Shun 2 lat temu
rodzic
commit
ce91755a61

+ 105 - 0
src/YSAI.DAQ/YSAI.Can/CanOperator.cs

@@ -5,6 +5,7 @@ using YSAI.Core.@interface;
 using YSAI.Core.subscription;
 using YSAI.Core.virtualAddress;
 using YSAI.Unility;
+using static YSAI.Unility.ReflexTool;
 
 namespace YSAI.Can
 {
@@ -456,5 +457,109 @@ namespace YSAI.Can
         {
             return Task.Run(() => GetStatus());
         }
+
+        public OperateResult GetParam()
+        {
+            string SN = Depart("GetParam");
+            try
+            {
+                //通过反射得到参数信息
+                List<LibInstanceParam>? libInstanceParams = ReflexTool.GetClassAllPropertyData<CanData.Basics>();
+                string message = TAG.Replace("Operate", string.Empty);
+                string nameSpace = "YSAI.Beckhoff.CanOperate";
+                CanData.Basics beckhoffData = new CanData.Basics();
+                LibParamStructure? libParamStructure = new LibParamStructure()
+                {
+                    Code = message,
+                    Name = message,
+                    Description = message,
+                    Subset = new List<LibParamStructure.subset>
+                        {
+                            new LibParamStructure.subset
+                            {
+                                Description = message,
+                                Name = message,
+                                Propertie = new List<LibParamStructure.subset.propertie>()
+                            }
+                        }
+                };
+                libParamStructure.Subset[0].Propertie.Add(new LibParamStructure.subset.propertie
+                {
+                    PropertyName = "ServiceName",
+                    Description = "实现类名",
+                    IsShow = false,
+                    IsMust = false,
+                    Value = nameSpace,
+                    DataCate = LibParamStructure.subset.propertie.dataCate.text
+                });
+                foreach (var lib in libInstanceParams)
+                {
+                    string param = ReflexTool.GetModelValue(lib.Name, beckhoffData);
+                    LibParamStructure.subset.propertie propertie = new LibParamStructure.subset.propertie
+                    {
+                        PropertyName = lib.Name,
+                        Description = lib.Describe,
+                        IsShow = true,
+                        Default = param,
+                        Value = param
+                    };
+
+                    switch (lib.ParamType)
+                    {
+                        case "Enum":
+                            propertie.DataCate = LibParamStructure.subset.propertie.dataCate.select;
+                            propertie.Options = new List<LibParamStructure.subset.propertie.options>();
+                            foreach (var val in lib.EnumArray as List<dynamic>)
+                            {
+                                string des = val.Describe;
+                                if (!string.IsNullOrEmpty(des))
+                                {
+                                    des = $"({val.Describe})";
+                                }
+                                propertie.Options.Add(new LibParamStructure.subset.propertie.options
+                                {
+                                    Key = val.Name + des,
+                                    Value = val.Value,
+                                });
+                            }
+                            break;
+
+                        case "Int32":
+                            propertie.DataCate = LibParamStructure.subset.propertie.dataCate.unmber;
+                            break;
+
+                        case "String":
+                            propertie.DataCate = LibParamStructure.subset.propertie.dataCate.text;
+                            break;
+
+                        case "Boolean":
+                            propertie.DataCate = LibParamStructure.subset.propertie.dataCate.radio;
+                            propertie.Options = new List<LibParamStructure.subset.propertie.options>();
+                            propertie.Options.Add(new LibParamStructure.subset.propertie.options
+                            {
+                                Key = "是",
+                                Value = true,
+                            });
+                            propertie.Options.Add(new LibParamStructure.subset.propertie.options
+                            {
+                                Key = "否",
+                                Value = false,
+                            });
+                            break;
+                    }
+                    libParamStructure.Subset[0].Propertie.Add(propertie);
+                }
+                return Break(SN, true, libParamStructure.ToJson().JsonFormatting(), libParamStructure, Core.@enum.ResultType.Object);
+            }
+            catch (Exception ex)
+            {
+                return Break(SN, false, ex.Message, Exception: ex);
+            }
+        }
+
+        public Task<OperateResult> GetParamAsync()
+        {
+            return Task.Run(() => GetParam());
+        }
     }
 }

+ 2 - 2
src/YSAI.DAQ/YSAI.Core/YSAI.Core.csproj

@@ -5,7 +5,7 @@
     <ImplicitUsings>enable</ImplicitUsings>
     <Nullable>enable</Nullable>
     <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
-    <Version>1.0.0.72</Version>
+    <Version>1.0.0.73</Version>
     <Authors>Shun</Authors>
     <Company>YSAI</Company>
     <Product>SCADA</Product>
@@ -17,7 +17,7 @@
 		<PackageReference Include="Microsoft.ClearScript" Version="7.4.4" />
 		<PackageReference Include="System.IO.Ports" Version="7.0.0" />
 		<PackageReference Include="YSAI.Log" Version="1.0.0.11" />
-		<PackageReference Include="YSAI.Unility" Version="1.0.0.26" />
+		<PackageReference Include="YSAI.Unility" Version="1.0.0.27" />
 	</ItemGroup>
 
 </Project>

+ 26 - 0
src/YSAI.DAQ/YSAI.Core/attribute/UnitAttribute.cs

@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace YSAI.Core.attribute
+{
+    /// <summary>
+    /// 单位特性
+    /// </summary>
+    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property)]
+    public class UnitAttribute : Attribute
+    {
+        /// <summary>
+        /// 构造函数
+        /// </summary>
+        /// <param name="Unit">单位</param>
+        public UnitAttribute(string Unit)
+        {
+            this.Unit = Unit;
+        }
+
+        public string Unit { get; set; }
+    }
+}

+ 36 - 0
src/YSAI.DAQ/YSAI.Core/attribute/VerifyAttribute.cs

@@ -0,0 +1,36 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace YSAI.Core.attribute
+{
+    /// <summary>
+    /// 验证特性
+    /// </summary>
+    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property)]
+    public class VerifyAttribute : Attribute
+    {
+        /// <summary>
+        /// 验证
+        /// </summary>
+        /// <param name="Regex">正则表达式</param>
+        /// <param name="FailTips">验证失败提示</param>
+        public VerifyAttribute(string Regex, string FailTips)
+        {
+            this.Regex = Regex;
+            this.FailTips = FailTips;
+        }
+
+        /// <summary>
+        /// 正则表达式
+        /// </summary>
+        public string Regex { get; set; }
+
+        /// <summary>
+        /// 验证失败提示
+        /// </summary>
+        public string FailTips { get; set; }
+    }
+}

+ 1 - 1
src/YSAI.DAQ/YSAI.Core/data/LibParamStructure.cs

@@ -123,7 +123,7 @@ namespace YSAI.Core.data
                 /// <summary>
                 /// 输入错误提示
                 /// </summary>
-                public string InputErrorTips { get; set; }
+                public string FailTips { get; set; }
 
                 /// <summary>
                 /// 非必填项集合

+ 24 - 0
src/YSAI.DAQ/YSAI.Unility/ReflexTool.cs

@@ -7,6 +7,30 @@ namespace YSAI.Unility
     /// </summary>
     public class ReflexTool
     {
+        /// <summary>
+        /// 为指定对象分配参数
+        /// </summary>
+        /// <typeparam name="T">对象类型</typeparam>
+        /// <param name="dic">字段/值</param>
+        /// <returns></returns>
+        public T Assign<T>(Dictionary<string, object> dic) where T : new()
+        {
+            Type myType = typeof(T);
+            T entity = new T();
+            var fields = myType.GetProperties();
+            object val;
+            object obj;
+            foreach (var field in fields)
+            {
+                if (!dic.Keys.Contains(field.Name))
+                    continue;
+                val = dic[field.Name.ToString()];
+                obj = Convert.ChangeType(val, field.PropertyType);
+                field.SetValue(entity, obj, null);
+            }
+            return entity;
+        }
+
         /// <summary>
         /// 取对象属性值
         /// </summary>

+ 1 - 1
src/YSAI.DAQ/YSAI.Unility/YSAI.Unility.csproj

@@ -5,7 +5,7 @@
 		<ImplicitUsings>enable</ImplicitUsings>
 		<Nullable>enable</Nullable>
 		<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
-		<Version>1.0.0.26</Version>
+		<Version>1.0.0.27</Version>
 		<Authors>Shun</Authors>
 		<Company>YSAI</Company>
 		<Product>SCADA</Product>