ModelBase.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using IwbZero.IwbBase;
  5. using IwbZero.ToolCommon.StringModel;
  6. using Newtonsoft.Json;
  7. using WeEngine.Packages;
  8. namespace WeEngine.ModelInfo
  9. {
  10. public class ModelBase
  11. {
  12. public ModelBase()
  13. {
  14. Children = new List<ModelBase>();
  15. GuideInfos = new List<GuideModel>();
  16. }
  17. protected NodeBase PackageNode { get; set; }
  18. [JsonProperty]
  19. public string Id { get; set; }
  20. [JsonProperty]
  21. public string No { get; set; }
  22. [JsonProperty]
  23. public string Name { get; set; }
  24. [JsonProperty]
  25. public string Path { get; set; }
  26. [JsonProperty]
  27. public string ParentPath { get; set; }
  28. [JsonIgnore]
  29. public string _guideNos;
  30. [JsonProperty]
  31. public string GuideNos
  32. {
  33. get
  34. {
  35. return _guideNos.IsEmpty()
  36. ? string.Join(",", GuideInfos?.Select(a => a.Id) ?? new string[0])
  37. : _guideNos;
  38. }
  39. set => _guideNos = value;
  40. }
  41. //public string GuideNames => string.Join(",", GuideInfos?.Select(a => a.Name) ?? new string[0]);
  42. private List<GuideModel> _guideInfos;
  43. [JsonIgnore]
  44. public List<GuideModel> GuideInfos
  45. {
  46. get
  47. {
  48. return _guideInfos?.Count > 0 ? _guideInfos : _guideInfos =
  49. PackageNode?.GuideInfos?.Select(a => new GuideModel().ModelFrom(a)).ToList() ??
  50. new List<GuideModel>();
  51. }
  52. set => _guideInfos = value;
  53. }
  54. [JsonProperty]
  55. public string SceneCategory { get; set; }
  56. [JsonProperty]
  57. public string SceneCategoryName { get; set; }
  58. [JsonProperty]
  59. public string PreComponent { get; set; }
  60. [JsonProperty]
  61. public string RunningComponent { get; set; }
  62. [JsonProperty]
  63. public string PostComponent { get; set; }
  64. [JsonProperty]
  65. public string VariableStr { get; set; }
  66. [JsonProperty]
  67. public decimal Weights { get; set; }
  68. public List<ModelBase> Children { get; set; }
  69. protected Hashtable GetVariable()
  70. {
  71. var table = new Hashtable();
  72. if (VariableStr.IsNotEmpty())
  73. {
  74. var varArr = VariableStr.StrToArray();
  75. foreach (var v in varArr)
  76. {
  77. var variable = IwbRtVariable.Str2Variable(v);
  78. table[variable.VarName] = variable;
  79. }
  80. }
  81. return table;
  82. }
  83. /// <summary>
  84. /// 转换Node
  85. /// </summary>
  86. /// <param name="node">空Node</param>
  87. /// <returns></returns>
  88. internal virtual NodeBase NodeFrom(NodeBase node)
  89. {
  90. node.Id = Id;
  91. node.InternalNo = No;
  92. node.Name = Name;
  93. node.EventComponentNode = new ComponentNode()
  94. {
  95. PreComponent = PreComponent,
  96. RunningComponent = RunningComponent,
  97. PostComponent = PostComponent
  98. };
  99. node.SceneCategory = SceneCategory;
  100. node.SceneCategoryName = SceneCategoryName;
  101. node.GuideInfos = new List<GuideNode>();
  102. if (GuideInfos?.Count > 0)
  103. {
  104. foreach (var guideInfo in GuideInfos)
  105. {
  106. var guide = guideInfo.NodeFrom();
  107. node.GuideInfos.Add(guide);
  108. }
  109. }
  110. node.Variables = GetVariable();
  111. //node.Children = new List<NodeBase>();
  112. return node;
  113. }
  114. /// <summary>
  115. /// 转换Model
  116. /// </summary>
  117. /// <param name="node"></param>
  118. /// <returns></returns>
  119. internal virtual void ModelFrom(NodeBase node)
  120. {
  121. Id = node.Id;
  122. No = node.InternalNo;
  123. Name = node.Name;
  124. Weights = node.Weights;
  125. Path = node.NodePath;
  126. ParentPath = node.Parent?.NodePath;
  127. SceneCategory = node.SceneCategory;
  128. SceneCategoryName = node.SceneCategoryName;
  129. VariableStr = Variable2Str(GetVariable());
  130. PreComponent = node.EventComponentNode?.PreComponent;
  131. RunningComponent = node.EventComponentNode?.RunningComponent;
  132. PostComponent = node.EventComponentNode?.PostComponent;
  133. //GuideInfos = node.GuideInfos?.Select(a => new GuideModel().ModelFrom(a)).ToList() ?? new List<GuideModel>();
  134. }
  135. /// <summary>
  136. /// 变量转字符串
  137. /// </summary>
  138. /// <param name="variables"></param>
  139. /// <returns></returns>
  140. private string Variable2Str(Hashtable variables)
  141. {
  142. string str = "";
  143. if (variables != null && variables.Count > 0)
  144. {
  145. string vStr = "";
  146. foreach (DictionaryEntry entry in variables)
  147. {
  148. var v = (IwbRtVariable)entry.Value;
  149. vStr += (vStr == "" ? "" : ",") + IwbRtVariable.Variable2Str(v);
  150. }
  151. }
  152. return str;
  153. }
  154. }
  155. }