| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- using System.Collections.Generic;
- using IwbZero.IwbBase;
- using IwbZero.ToolCommon.StringModel;
- namespace WeEngine.ComponentInfo
- {
- public class EngineComponent:IIwbId
- {
- public EngineComponent()
- {
- Data=new List<ComponentScript>();
- }
- /// <summary>
- /// 编号
- /// </summary>
- public string Id { get; set; }
- /// <summary>
- /// 编号
- /// </summary>
- public string No
- {
- get => Id;
- set => Id = value;
- }
- /// <summary>
- /// 名称
- /// </summary>
- public string Name { get; set; }
- /// <summary>
- /// 参数映射
- /// </summary>
- public string Parameters { get; set; }
- /// <summary>
- /// 事务描述
- /// </summary>
- public string Description { get; set; }
- /// <summary>
- /// 事务类型
- /// </summary>
- public string ComponentType { get; set; }
- /// <summary>
- /// 事务逻辑
- /// </summary>
- public string ComponentScript
- {
- get
- {
- string str = "";
- foreach (var componentScript in Data)
- {
- str += componentScript.ToXmlString()+"\r\n";
- }
- if (str.IsNotEmpty())
- {
- str = $"<ComponentScript>{str}</ComponentScript>";
- }
- return str;
- }
- }
- /// <summary>
- /// 类全名
- /// </summary>
- public string ComponentClass { get; set; }
- /// <summary>
- /// 程序集
- /// </summary>
- public string ComponentLib { get; set; }
- /// <summary>
- /// 注册Key(IOC注入)
- /// </summary>
- public string RegisterKey { get; set; }
- public List<ComponentScript> Data { get; set; }
- public EngineComponent ModelFrom(IwbXmlNode xmlNode)
- {
- if (xmlNode == null)
- {
- return null;
- }
- Data = new List<ComponentScript>();
- Id = xmlNode.GetChildValue("Id");
- No = xmlNode.GetChildValue("No");
- Name = xmlNode.GetChildValue("Name");
- Parameters = xmlNode.GetChildValue("Parameters");
- Description = xmlNode.GetChildValue("Description");
- RegisterKey = xmlNode.GetChildValue("RegisterKey");
- ComponentClass = xmlNode.GetChildValue("ComponentClass");
- ComponentLib = xmlNode.GetChildValue("ComponentLib");
- ComponentType = xmlNode.GetChildValue("ComponentType");
- var scriptStr = xmlNode.GetChildValue("ComponentScript")?.DecodeBase64();
- Data = new ComponentScript().ModelFrom(scriptStr);
- return this;
- }
- public string ConvertComponents2Xml(List<EngineComponent> engineComponents)
- {
- string str = "";
- foreach (var component in engineComponents)
- {
- str += component.ToXmlString() + "\r\n";
- }
- if (str.IsNotEmpty())
- {
- str = $"<ComponentInfos>{str}</ComponentInfos>";
- }
- return str;
- }
- public string ToXmlString()
- {
- string str = "";
- str += $"<ComponentInfo id=\"{Id}\">\r\n";
- str += $"<Id>{Id}</Id>\r\n";
- str += $"<Name>{Name}</Name>\r\n";
- str += $"<Parameters>{Parameters}</Parameters>\r\n";
- str += $"<Description>{Description}</Description>\r\n";
- str += $"<RegisterKey>{RegisterKey}</RegisterKey>\r\n";
- str += $"<ComponentScript>{ComponentScript.EncodeBase64()}</ComponentScript>\r\n";
- str += $"<ComponentClass>{ComponentClass}</ComponentClass>\r\n";
- str += $"<ComponentLib>{ComponentLib}</ComponentLib>\r\n";
- str += $"<ComponentType>{ComponentType}</ComponentType>\r\n";
- str += "</ComponentInfo>";
- return str;
- }
-
- public List<EngineComponent> BuildByXml(string xml)
- {
- var node = IwbXmlNode.ParseGenericXml(xml);
- return BuildByXml(node);
- }
- public List<EngineComponent> BuildByXml(IwbXmlNode xmlNode)
- {
- var models = new List<EngineComponent>();
- var nodes = xmlNode?.Nodes;
- if (nodes?.Count > 0)
- {
- foreach (IwbXmlNode node in nodes)
- {
- var model = new EngineComponent().ModelFrom(node);
- if (model != null) models.Add(model);
- }
- }
- return models;
- }
- }
- public class ComponentScript
- {
- public string Id { get; set; }
- public string No { get; set; }
- public string Name { get; set; }
- public string Path { get; set; }
- public string ParentPath { get; set; }
- public string CompType { get; set; }
- public ComponentVariable Variable { get; set; }
- public string Condition { get; set; }
- public List<ComponentScript> Yes { get; set; }
- public List<ComponentScript> Not { get; set; }
- public string WaitNodes { get; set; }
- public string Message { get; set; }
- public string ToXmlString()
- {
- string str = "", str1 = "";
- str += $"<{CompType} id=\"{Id}\">";
- if (Variable != null)
- {
- str1 += Variable.ToXmlString();
- str += str1.IsEmpty() ? "" : $"<Variable>{str1}</Variable>\r\n";
- }
- str += CompType.IsEmpty() ? "" : $"<CompType>{CompType}</CompType>\r\n";
- str += Name.IsEmpty() ? "" : $"<Name>{Name}</Name>\r\n";
- str += Path.IsEmpty() ? "" : $"<Name>{Path}</Name>\r\n";
- str += ParentPath.IsEmpty() ? "" : $"<Name>{ParentPath}</Name>\r\n";
- str += Condition.IsEmpty() ? "" : $"<Condition>{Condition.FormatCode2Xml()}</Condition>\r\n";
- str += WaitNodes.IsEmpty() ? "" : $"<WaitNodes>{WaitNodes}</WaitNodes>\r\n";
- str += Message.IsEmpty() ? "" : $"<Message>{Message}</Message>\r\n";
- str1 = "";
- if (Yes != null)
- {
- foreach (var cd in Yes)
- {
- str1 += cd.ToXmlString();
- }
- }
- str += str1.IsEmpty() ? "" : $"<Yes>{str1}</Yes>\r\n";
- str1 = "";
- if (Not != null)
- {
- foreach (var cd in Not)
- {
- str1 += cd.ToXmlString();
- }
- }
- str += str1.IsEmpty() ? "" : $"<No>{str1}</No>\r\n";
- str += $"</{CompType}>";
- return str;
- }
- public List<ComponentScript> ModelFrom(string str)
- {
- var scripts= new List<ComponentScript>();
- if (str.IsEmpty())
- {
- return scripts;
- }
- var xmlStr = str.StartsWith("<ComponentScript>") ? str : $"<ComponentScript>{str}</ComponentScript>";
- var xmlNode = IwbXmlNode.ParseGenericXml(xmlStr);
- var scriptNodes = xmlNode.Nodes;
- if (scriptNodes?.Count > 0)
- {
- foreach (IwbXmlNode scriptNode in scriptNodes)
- {
- var data = new ComponentScript().ModelFrom(scriptNode);
- scripts.Add(data);
- }
- }
- return scripts;
- }
- public ComponentScript ModelFrom(IwbXmlNode xmlNode)
- {
- if (xmlNode == null)
- return null;
- Id = xmlNode.GetChildValue("Id");
- No = xmlNode.GetChildValue("No");
- Name = xmlNode.GetChildValue("Name");
- CompType = xmlNode.GetChildValue("CompType");
- Path = xmlNode.GetChildValue("Path");
- ParentPath = xmlNode.GetChildValue("ParentPath");
- Condition = xmlNode.GetChildValue("Condition");
- WaitNodes = xmlNode.GetChildValue("WaitNodes");
- Message = xmlNode.GetChildValue("Message");
- var variableNode = xmlNode.GetChildNode("Variable");
- Variable = new ComponentVariable().ModelFrom(variableNode);
- Yes = new List<ComponentScript>();
- Not = new List<ComponentScript>();
- var yesNodes = xmlNode.GetChildNode("Yes")?.Nodes;
- if (yesNodes?.Count > 0)
- {
- foreach (IwbXmlNode y in yesNodes)
- {
- var yes = new ComponentScript().ModelFrom(y);
- if (yes != null) Yes.Add(yes);
- }
- }
- var noNodes = xmlNode.GetChildNode("Not")?.Nodes;
- if (noNodes?.Count > 0)
- {
- foreach (IwbXmlNode n in noNodes)
- {
- var not = new ComponentScript().ModelFrom(n);
- if (not != null) Not.Add(not);
- }
- }
- return this;
- }
- }
- public class ComponentVariable
- {
- public ComponentVariable(string str)
- {
- var arr = str.StrToArray(":");
- Name = "";
- Type = "STRING";
- Value = "";
- if (arr.Length > 0)
- {
- Name = arr[0].Substring(2);
- }
- if (arr.Length > 1)
- {
- TargetPath = arr[1];
- }
- if (arr.Length > 2)
- {
- Value = arr[2];
- }
- }
- public ComponentVariable()
- {
- }
- public string Name { get; set; }
- public string Type { get; set; }
- public string Value { get; set; }
- public string TargetPath { get; set; }
- public string TargetName { get; set; }
- public string ToXmlString()
- {
- string str = "";
- str += Name.IsEmpty() ? "" : $"<Name>{Name}</Name>\r\n";
- str += Type.IsEmpty() ? "" : $"<Type>{Type}</Type>\r\n";
- str += Value.IsEmpty() ? "" : $"<Value>{Value}</Value>\r\n";
- str += TargetPath.IsEmpty() ? "" : $"<TargetPath>{TargetPath}</TargetPath>\r\n";
- str += TargetName.IsEmpty() ? "" : $"<TargetName>{TargetName}</TargetName>\r\n";
- return str;
- }
- public ComponentVariable ModelFrom(IwbXmlNode xmlNode)
- {
- if (xmlNode == null)
- {
- return null;
- }
- Name = xmlNode.GetChildValue("Name");
- Type = xmlNode.GetChildValue("Type");
- Value = xmlNode.GetChildValue("Value");
- TargetPath = xmlNode.GetChildValue("TargetPath");
- TargetName = xmlNode.GetChildValue("TargetName");
- return this;
- }
- }
- }
|