DefaultVariable.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using IwbZero.IwbBase;
  5. using IwbZero.ToolCommon.StringModel;
  6. namespace WeEngine
  7. {
  8. public class DefaultVariable
  9. {
  10. /// <summary>
  11. /// 运行编号
  12. /// </summary>
  13. private static readonly string _runningId = $"{IwbVariableType.Local}RunningId";
  14. [Description("运行编号")]
  15. public static string RunningId => _runningId.UAndT();
  16. private static readonly string _id = $"{IwbVariableType.Local}Id";
  17. [Description("编号")]
  18. public static string Id => _id.UAndT();
  19. /// <summary>
  20. /// 节点路径
  21. /// </summary>
  22. [Description("节点路径")]
  23. public static string Path => _path.UAndT();
  24. private static readonly string _path = $"{IwbVariableType.Local}Path";
  25. /// <summary>
  26. /// 轮次总分
  27. /// </summary>
  28. [Description("轮次总分")]
  29. public static string FullRoundScore => _fullRoundScore.UAndT();
  30. private static readonly string _fullRoundScore = $"{IwbVariableType.Local}FullRoundScore";
  31. /// <summary>
  32. /// 节点总分
  33. /// </summary>
  34. [Description("节点总分")]
  35. public static string FullNodeScore => _fullNodeScore.UAndT();
  36. private static readonly string _fullNodeScore = $"{IwbVariableType.Local}FullNodeScore";
  37. /// <summary>
  38. /// 前一节点评分
  39. /// </summary>
  40. [Description("前一节点评分")]
  41. public static string PrevNodeScore => _prevNodeScore.UAndT();
  42. private static readonly string _prevNodeScore = $"{IwbVariableType.Local}PrevNodeScore";
  43. //public static string PrevRoundScore = $"{IwbVariableType.Local}PrevRoundScore";
  44. /// <summary>
  45. /// 轮次评分
  46. /// </summary>
  47. [Description("轮次评分")]
  48. public static string RoundScore => _roundScore.UAndT();
  49. private static readonly string _roundScore = $"{IwbVariableType.Local}RoundScore";
  50. /// <summary>
  51. /// 情景流总分
  52. /// </summary>
  53. [Description("情景流总分")]
  54. public static string FullFlowScore => _fullFlowScore.UAndT();
  55. private static readonly string _fullFlowScore = $"{IwbVariableType.Local}FullFlowScore";
  56. /// <summary>
  57. /// 情景流评分
  58. /// </summary>
  59. [Description("情景流评分")]
  60. public static string FlowScore => _flowScore;
  61. private static readonly string _flowScore = $"{IwbVariableType.Local}FlowScore";
  62. /// <summary>
  63. /// 情景流节点评分
  64. /// </summary>
  65. [Description("情景流节点评分")]
  66. public static string FlowNodeScore => _flowNodeScore.UAndT();
  67. private static readonly string _flowNodeScore = $"{IwbVariableType.Local}FlowNodeScore";
  68. /// <summary>
  69. /// 情景评分
  70. /// </summary>
  71. [Description("情景评分")]
  72. public static string SceneScore => _sceneScore.UAndT();
  73. private static readonly string _sceneScore = $"{IwbVariableType.Local}SceneScore";
  74. /// <summary>
  75. /// 事务节点验证条件结果
  76. /// </summary>
  77. [Description("事务节点验证条件结果")]
  78. public static string RunValidate => _runValidate.UAndT();
  79. private static readonly string _runValidate = $"{IwbVariableType.Local}RunValidate";
  80. /// <summary>
  81. /// 默认变量
  82. /// </summary>
  83. public static Hashtable Variables => GetVariables();
  84. public static List<string> VariableNames => GetVariableNames();
  85. private static Hashtable GetVariables(bool u = true)
  86. {
  87. var variables = new Hashtable
  88. {
  89. {u ? Path : _path, new IwbRtVariable(Path)},
  90. {u ? FullRoundScore : _fullRoundScore, new IwbRtVariable(FullFlowScore, "Numeric")},
  91. {u ? FullNodeScore : _fullNodeScore, new IwbRtVariable(FullNodeScore, "Numeric")},
  92. {u ? PrevNodeScore : _prevNodeScore, new IwbRtVariable(PrevNodeScore, "Numeric")},
  93. {u ? RoundScore : _roundScore, new IwbRtVariable(RoundScore, "Numeric")},
  94. {u ? FullFlowScore : _fullFlowScore, new IwbRtVariable(FullFlowScore, "Numeric")},
  95. {u ? FlowScore : _flowScore, new IwbRtVariable(FlowScore, "Numeric")},
  96. {u ? FlowNodeScore : _flowNodeScore, new IwbRtVariable(FlowNodeScore, "Numeric")},
  97. {u ? SceneScore : _sceneScore, new IwbRtVariable(SceneScore, "Numeric")},
  98. {u ? RunValidate : _runValidate, new IwbRtVariable(RunValidate)}
  99. };
  100. return variables;
  101. }
  102. public static List<string> GetVariableNames()
  103. {
  104. var list = new List<string> { _runningId };
  105. foreach (DictionaryEntry dic in Variables)
  106. {
  107. list.Add(dic.Key.ToString());
  108. }
  109. return list;
  110. }
  111. public static List<VariableName> GetVariableNameList()
  112. {
  113. var list = new List<VariableName>();
  114. var variables = GetVariables(false);
  115. foreach (DictionaryEntry dic in variables)
  116. {
  117. var key = dic.Key.ToString();
  118. var name = GetName(key);
  119. list.Add(new VariableName($"{name}({key})", key));
  120. }
  121. return list;
  122. }
  123. public static string GetVariableSelects()
  124. {
  125. string str = "";
  126. str += $"<option value=\"{FullRoundScore.Substring(1)}\">{GetName(FullRoundScore)}</option>";
  127. str += $"<option value=\"{FullFlowScore.Substring(1)}\">{GetName(FullFlowScore)}</option>";
  128. str += $"<option value=\"{FullNodeScore.Substring(1)}\">{GetName(FullNodeScore)}</option>";
  129. str += $"<option value=\"{PrevNodeScore.Substring(1)}\">{GetName(PrevNodeScore)}</option>";
  130. str += $"<option value=\"{RoundScore.Substring(1)}\">{GetName(RoundScore)}</option>";
  131. str += $"<option value=\"{FlowScore.Substring(1)}\">{GetName(FlowScore)}</option>";
  132. str += $"<option value=\"{FlowNodeScore.Substring(1)}\">{GetName(FlowNodeScore)}</option>";
  133. str += $"<option value=\"{SceneScore.Substring(1)}\">{GetName(SceneScore)}</option>";
  134. str += $"<option value=\"{Path.Substring(1)}\">{GetName(Path)}</option>";
  135. str += $"<option value=\"{RunValidate.Substring(1)}\">{GetName(RunValidate)}</option>";
  136. return str;
  137. }
  138. private static string GetName(string key)
  139. {
  140. key = key.StartsWith("@") ? key.Substring(1) : key;
  141. var p = typeof(DefaultVariable).GetProperty(key);
  142. var obj = p?.GetCustomAttributes(typeof(DescriptionAttribute), true)[0];
  143. var str = obj != null ? ((DescriptionAttribute)obj).Description : "";
  144. return str;
  145. }
  146. public class VariableName
  147. {
  148. public VariableName()
  149. {
  150. }
  151. public VariableName(string name, string value)
  152. {
  153. Name = name;
  154. Value = value;
  155. }
  156. public string Name { get; set; }
  157. public string Value { get; set; }
  158. }
  159. }
  160. }