|
|
@@ -0,0 +1,343 @@
|
|
|
+using Google.Protobuf.WellKnownTypes;
|
|
|
+using Microsoft.AspNetCore.DataProtection.KeyManagement;
|
|
|
+using Microsoft.Win32.SafeHandles;
|
|
|
+using Newtonsoft.Json;
|
|
|
+using Newtonsoft.Json.Converters;
|
|
|
+using OpcDaNetApi;
|
|
|
+using System.Collections.Generic;
|
|
|
+using YSAI.Can;
|
|
|
+using YSAI.DB;
|
|
|
+using YSAI.Kafka;
|
|
|
+using YSAI.Modbus.client;
|
|
|
+using YSAI.Mqtt.client;
|
|
|
+using YSAI.Opc.da.client;
|
|
|
+using YSAI.Opc.da.http;
|
|
|
+using YSAI.Opc.ua.client;
|
|
|
+using YSAI.RabbitMQ;
|
|
|
+using YSAI.S7.client;
|
|
|
+using YSAI.Unility;
|
|
|
+using static YSAI.Pack.Param.Program;
|
|
|
+using static YSAI.Pack.Param.Program.BodyParam.subset;
|
|
|
+using static YSAI.Unility.ReflexTool;
|
|
|
+
|
|
|
+namespace YSAI.Pack.Param
|
|
|
+{
|
|
|
+ internal class Program
|
|
|
+ {
|
|
|
+ static void Main(string[] args)
|
|
|
+ {
|
|
|
+ string FileDirectory = string.Empty;
|
|
|
+ string[] paths = AppDomain.CurrentDomain.BaseDirectory.Split('\\');
|
|
|
+ for (int i = 0; i < paths.Length - 5; i++)
|
|
|
+ {
|
|
|
+ FileDirectory += $"{paths[i]}//";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ BodyHandler body1 = new BodyHandler { Body = new CanData.Basics(), FileName = "Can.json",Namespace= "YSAI.Can.CanOperator" };
|
|
|
+ BodyHandler body2 = new BodyHandler { Body = new DBData.Basics(), FileName = "DB.json", Namespace = "YSAI.DB.DBOperate" };
|
|
|
+ BodyHandler body3 = new BodyHandler { Body = new KafkaData.Basics(), FileName = "Kafka.json", Namespace = "YSAI.Kafka.KafkaOperate" };
|
|
|
+ BodyHandler body4 = new BodyHandler { Body = new ModbusClientData.Basics(), FileName = "Modbus.json", Namespace = "YSAI.Modbus.client.ModbusClientOperate" };
|
|
|
+ BodyHandler body5 = new BodyHandler { Body = new MqttClientData.Basics(), FileName = "Mqtt.json", Namespace = "YSAI.Mqtt.client.MqttClientOperate" };
|
|
|
+ BodyHandler body6 = new BodyHandler { Body = new OpcDaClientData.Basics(), FileName = "OpcDa.json", Namespace = "YSAI.Opc.da.client.OpcDaClientOperate" };
|
|
|
+ BodyHandler body7 = new BodyHandler { Body = new OpcDaHttpData.Basics(), FileName = "OpcDaHttp.json", Namespace = "YSAI.Opc.da.http.OpcDaHttpOperate" };
|
|
|
+ BodyHandler body8 = new BodyHandler { Body = new OpcUaClientData.Basics(), FileName = "OpcUa.json", Namespace = "YSAI.Opc.ua.client.OpcUaClientOperate" };
|
|
|
+ BodyHandler body9 = new BodyHandler { Body = new RabbitMQData.Basics(), FileName = "RabbitMQ.json", Namespace = "YSAI.RabbitMQ.RabbitMQOperate" };
|
|
|
+ BodyHandler body10 = new BodyHandler { Body = new S7ClientData.Basics(), FileName = "S7.json", Namespace = "YSAI.S7.client.S7ClientOperate" };
|
|
|
+
|
|
|
+ List<BodyHandler> bodys = new List<BodyHandler> { body1, body2, body3, body4, body5, body6, body7, body8, body9, body10 };
|
|
|
+
|
|
|
+ foreach (var item in bodys)
|
|
|
+ {
|
|
|
+ int index = item.Body.GetType().FullName.Replace("+", ".").Split('.').Length;
|
|
|
+ string name = $"{item.Body.GetType().FullName.Replace("+", ".").Split('.')[index - 2]}.{item.Body.GetType().FullName.Replace("+", ".").Split('.')[index - 1]}";
|
|
|
+ string message = item.FileName.Split('.')[0];
|
|
|
+ List<LibInstanceParam>? libInstanceParams = null;
|
|
|
+ BodyParam? bodyParam = null;
|
|
|
+ switch (name)
|
|
|
+ {
|
|
|
+ case "CanData.Basics":
|
|
|
+ libInstanceParams = ReflexTool.GetClassAllPropertyData<CanData.Basics>();
|
|
|
+ break;
|
|
|
+ case "DBData.Basics":
|
|
|
+ libInstanceParams = ReflexTool.GetClassAllPropertyData<DBData.Basics>();
|
|
|
+ break;
|
|
|
+ case "KafkaData.Basics":
|
|
|
+ libInstanceParams = ReflexTool.GetClassAllPropertyData<KafkaData.Basics>();
|
|
|
+ break;
|
|
|
+ case "ModbusClientData.Basics":
|
|
|
+ libInstanceParams = ReflexTool.GetClassAllPropertyData<ModbusClientData.Basics>();
|
|
|
+ break;
|
|
|
+ case "MqttClientData.Basics":
|
|
|
+ libInstanceParams = ReflexTool.GetClassAllPropertyData<MqttClientData.Basics>();
|
|
|
+ break;
|
|
|
+ case "OpcDaClientData.Basics":
|
|
|
+ libInstanceParams = ReflexTool.GetClassAllPropertyData<OpcDaClientData.Basics>();
|
|
|
+ break;
|
|
|
+ case "OpcDaHttpData.Basics":
|
|
|
+ libInstanceParams = ReflexTool.GetClassAllPropertyData<OpcDaHttpData.Basics>();
|
|
|
+ break;
|
|
|
+ case "OpcUaClientData.Basics":
|
|
|
+ libInstanceParams = ReflexTool.GetClassAllPropertyData<OpcUaClientData.Basics>();
|
|
|
+ break;
|
|
|
+ case "RabbitMQData.Basics":
|
|
|
+ libInstanceParams = ReflexTool.GetClassAllPropertyData<RabbitMQData.Basics>();
|
|
|
+ break;
|
|
|
+ case "S7ClientData.Basics":
|
|
|
+ libInstanceParams = ReflexTool.GetClassAllPropertyData<S7ClientData.Basics>();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (message.Equals("Modbus"))
|
|
|
+ {
|
|
|
+ string[] strings = new string[] { "Modbus-Tcp", "Modbus-Udp", "Modbus-Rtu", "Modbus-Ascii" };
|
|
|
+ bodyParam = new BodyParam()
|
|
|
+ {
|
|
|
+ Code = message,
|
|
|
+ Name = message,
|
|
|
+ Description = message,
|
|
|
+ Subset = new List<BodyParam.subset>()
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+ for (int i = 0; i < strings.Length; i++)
|
|
|
+ {
|
|
|
+ bodyParam.Subset.Add(new BodyParam.subset
|
|
|
+ {
|
|
|
+ Description = strings[i],
|
|
|
+ Name = strings[i],
|
|
|
+ Propertie = new List<BodyParam.subset.propertie>()
|
|
|
+ });
|
|
|
+
|
|
|
+ foreach (var lib in libInstanceParams)
|
|
|
+ {
|
|
|
+ BodyParam.subset.propertie propertie = new BodyParam.subset.propertie
|
|
|
+ {
|
|
|
+ PropertyName = lib.Name,
|
|
|
+ Description = lib.Describe,
|
|
|
+ IsShow = true,
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ if (lib.ParamType.Equals("Enum"))
|
|
|
+ {
|
|
|
+ propertie.DataCate = BodyParam.subset.propertie.dataCate.select;
|
|
|
+ propertie.Options = new List<BodyParam.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 BodyParam.subset.propertie.options
|
|
|
+ {
|
|
|
+ Key = val.Name + des,
|
|
|
+ Value = val.Value,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (lib.ParamType.Equals("String"))
|
|
|
+ {
|
|
|
+ propertie.DataCate = BodyParam.subset.propertie.dataCate.text;
|
|
|
+ }
|
|
|
+ if (lib.ParamType.Equals("Boolean"))
|
|
|
+ {
|
|
|
+ propertie.DataCate = BodyParam.subset.propertie.dataCate.radio;
|
|
|
+ propertie.Options = new List<BodyParam.subset.propertie.options>();
|
|
|
+ propertie.Options.Add(new BodyParam.subset.propertie.options
|
|
|
+ {
|
|
|
+ Key = "是",
|
|
|
+ Value = true,
|
|
|
+ });
|
|
|
+ propertie.Options.Add(new BodyParam.subset.propertie.options
|
|
|
+ {
|
|
|
+ Key = "否",
|
|
|
+ Value = false,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ bodyParam.Subset[i].Propertie.Add(propertie);
|
|
|
+ }
|
|
|
+ bodyParam.Subset[i].Propertie.RemoveRange(2, 1);
|
|
|
+ switch (strings[i])
|
|
|
+ {
|
|
|
+ case "Modbus-Tcp":
|
|
|
+ case "Modbus-Udp":
|
|
|
+ bodyParam.Subset[i].Propertie.RemoveRange(10, 5);
|
|
|
+ break;
|
|
|
+ case "Modbus-Rtu":
|
|
|
+ case "Modbus-Ascii":
|
|
|
+ bodyParam.Subset[i].Propertie.RemoveRange(7, 3);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ bodyParam.Subset[i].Propertie.Add(new propertie
|
|
|
+ {
|
|
|
+ PropertyName = "ServiceName",
|
|
|
+ Description = "实现类名",
|
|
|
+ IsShow = false,
|
|
|
+ IsMust = false,
|
|
|
+ Value = item.Namespace,
|
|
|
+ DataCate = propertie.dataCate.text
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ bodyParam = new BodyParam()
|
|
|
+ {
|
|
|
+ Code = message,
|
|
|
+ Name = message,
|
|
|
+ Description = message,
|
|
|
+ Subset = new List<BodyParam.subset>
|
|
|
+ {
|
|
|
+ new BodyParam.subset
|
|
|
+ {
|
|
|
+ Description = message,
|
|
|
+ Name = message,
|
|
|
+ Propertie = new List<BodyParam.subset.propertie>()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+ foreach (var lib in libInstanceParams)
|
|
|
+ {
|
|
|
+
|
|
|
+ BodyParam.subset.propertie propertie = new BodyParam.subset.propertie
|
|
|
+ {
|
|
|
+ PropertyName = lib.Name,
|
|
|
+ Description = lib.Describe,
|
|
|
+ IsShow = true,
|
|
|
+ };
|
|
|
+
|
|
|
+ if (lib.ParamType.Equals("Enum"))
|
|
|
+ {
|
|
|
+ propertie.DataCate = BodyParam.subset.propertie.dataCate.select;
|
|
|
+ propertie.Options = new List<BodyParam.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 BodyParam.subset.propertie.options
|
|
|
+ {
|
|
|
+ Key = val.Name + des,
|
|
|
+ Value = val.Value,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (lib.ParamType.Equals("String"))
|
|
|
+ {
|
|
|
+ propertie.DataCate = BodyParam.subset.propertie.dataCate.text;
|
|
|
+ }
|
|
|
+ if (lib.ParamType.Equals("Boolean"))
|
|
|
+ {
|
|
|
+ propertie.DataCate = BodyParam.subset.propertie.dataCate.radio;
|
|
|
+ propertie.Options = new List<BodyParam.subset.propertie.options>();
|
|
|
+ propertie.Options.Add(new BodyParam.subset.propertie.options
|
|
|
+ {
|
|
|
+ Key = "是",
|
|
|
+ Value = true,
|
|
|
+ });
|
|
|
+ propertie.Options.Add(new BodyParam.subset.propertie.options
|
|
|
+ {
|
|
|
+ Key = "否",
|
|
|
+ Value = false,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ bodyParam.Subset[0].Propertie.Add(propertie);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (message.Equals("RabbitMQ") || message.Equals("Mqtt") || message.Equals("Kafka"))
|
|
|
+ {
|
|
|
+ bodyParam.Subset[0].Propertie.Add(new propertie
|
|
|
+ {
|
|
|
+ PropertyName = "Topic",
|
|
|
+ Description = "主题",
|
|
|
+ IsShow = true,
|
|
|
+ IsMust=true,
|
|
|
+ DataCate=propertie.dataCate.text
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ bodyParam.Subset[0].Propertie.Add(new propertie
|
|
|
+ {
|
|
|
+ PropertyName = "ServiceName",
|
|
|
+ Description = "实现类名",
|
|
|
+ IsShow = false,
|
|
|
+ IsMust = false,
|
|
|
+ Value= item.Namespace,
|
|
|
+ DataCate = propertie.dataCate.text
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ string path = Path.Combine(FileDirectory, "YSAI.Pack", item.FileName);
|
|
|
+
|
|
|
+ FileTool.StringToFile(path, bodyParam.ToJson().JsonFormatting());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 处理的结构
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="T">泛型对象</typeparam>
|
|
|
+ public class BodyHandler
|
|
|
+ {
|
|
|
+ public object Body { get; set; }
|
|
|
+ public string FileName { get; set; }
|
|
|
+ public string Namespace { get; set; }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 结构体参数
|
|
|
+ /// </summary>
|
|
|
+ public class BodyParam
|
|
|
+ {
|
|
|
+ public string Code { get; set; }
|
|
|
+ public string Name { get; set; }
|
|
|
+ public string Description { get; set; }
|
|
|
+ public List<subset> Subset { get; set; }
|
|
|
+ public class subset
|
|
|
+ {
|
|
|
+ public string Name { get; set; }
|
|
|
+ public string Description { get; set; }
|
|
|
+ public List<propertie> Propertie { get; set; }
|
|
|
+ public class propertie
|
|
|
+ {
|
|
|
+ [JsonConverter(typeof(StringEnumConverter))]
|
|
|
+ public dataCate DataCate { get; set; }
|
|
|
+ public enum dataCate
|
|
|
+ {
|
|
|
+ text,
|
|
|
+ select,
|
|
|
+ radio
|
|
|
+ }
|
|
|
+ public string Default { get; set; }
|
|
|
+ public string Description { get; set; }
|
|
|
+ public string PropertyName { get; set; }
|
|
|
+ public object? Value { get; set; }
|
|
|
+ public bool IsShow { get; set; }
|
|
|
+ public bool IsMust { get; set; }
|
|
|
+ public List<options>? Options { get; set; } = null;
|
|
|
+ public class options
|
|
|
+ {
|
|
|
+ public string Key { get; set; }
|
|
|
+ public object Value { get; set; }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|