| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using IwbZero.IwbBase;
- using IwbZero.ToolCommon.StringModel;
- using Newtonsoft.Json;
- using WeEngine.Packages;
- namespace WeEngine.ModelInfo
- {
- public class ModelBase
- {
- public ModelBase()
- {
- Children = new List<ModelBase>();
- GuideInfos = new List<GuideModel>();
- }
- protected NodeBase PackageNode { get; set; }
- [JsonProperty]
- public string Id { get; set; }
- [JsonProperty]
- public string No { get; set; }
- [JsonProperty]
- public string Name { get; set; }
- [JsonProperty]
- public string Path { get; set; }
- [JsonProperty]
- public string ParentPath { get; set; }
- [JsonIgnore]
- public string _guideNos;
- [JsonProperty]
- public string GuideNos
- {
- get
- {
- return _guideNos.IsEmpty()
- ? string.Join(",", GuideInfos?.Select(a => a.Id) ?? new string[0])
- : _guideNos;
- }
- set => _guideNos = value;
- }
- //public string GuideNames => string.Join(",", GuideInfos?.Select(a => a.Name) ?? new string[0]);
- private List<GuideModel> _guideInfos;
- [JsonIgnore]
- public List<GuideModel> GuideInfos
- {
- get
- {
- return _guideInfos?.Count > 0 ? _guideInfos : _guideInfos =
- PackageNode?.GuideInfos?.Select(a => new GuideModel().ModelFrom(a)).ToList() ??
- new List<GuideModel>();
- }
- set => _guideInfos = value;
- }
- [JsonProperty]
- public string SceneCategory { get; set; }
- [JsonProperty]
- public string SceneCategoryName { get; set; }
- [JsonProperty]
- public string PreComponent { get; set; }
- [JsonProperty]
- public string RunningComponent { get; set; }
- [JsonProperty]
- public string PostComponent { get; set; }
- [JsonProperty]
- public string VariableStr { get; set; }
- [JsonProperty]
- public decimal Weights { get; set; }
- public List<ModelBase> Children { get; set; }
- protected Hashtable GetVariable()
- {
- var table = new Hashtable();
- if (VariableStr.IsNotEmpty())
- {
- var varArr = VariableStr.StrToArray();
- foreach (var v in varArr)
- {
- var variable = IwbRtVariable.Str2Variable(v);
- table[variable.VarName] = variable;
- }
- }
- return table;
- }
- /// <summary>
- /// 转换Node
- /// </summary>
- /// <param name="node">空Node</param>
- /// <returns></returns>
- internal virtual NodeBase NodeFrom(NodeBase node)
- {
- node.Id = Id;
- node.InternalNo = No;
- node.Name = Name;
- node.EventComponentNode = new ComponentNode()
- {
- PreComponent = PreComponent,
- RunningComponent = RunningComponent,
- PostComponent = PostComponent
- };
- node.SceneCategory = SceneCategory;
- node.SceneCategoryName = SceneCategoryName;
- node.GuideInfos = new List<GuideNode>();
- if (GuideInfos?.Count > 0)
- {
- foreach (var guideInfo in GuideInfos)
- {
- var guide = guideInfo.NodeFrom();
- node.GuideInfos.Add(guide);
- }
- }
- node.Variables = GetVariable();
- //node.Children = new List<NodeBase>();
- return node;
- }
- /// <summary>
- /// 转换Model
- /// </summary>
- /// <param name="node"></param>
- /// <returns></returns>
- internal virtual void ModelFrom(NodeBase node)
- {
- Id = node.Id;
- No = node.InternalNo;
- Name = node.Name;
- Weights = node.Weights;
- Path = node.NodePath;
- ParentPath = node.Parent?.NodePath;
- SceneCategory = node.SceneCategory;
- SceneCategoryName = node.SceneCategoryName;
- VariableStr = Variable2Str(GetVariable());
- PreComponent = node.EventComponentNode?.PreComponent;
- RunningComponent = node.EventComponentNode?.RunningComponent;
- PostComponent = node.EventComponentNode?.PostComponent;
- //GuideInfos = node.GuideInfos?.Select(a => new GuideModel().ModelFrom(a)).ToList() ?? new List<GuideModel>();
- }
- /// <summary>
- /// 变量转字符串
- /// </summary>
- /// <param name="variables"></param>
- /// <returns></returns>
- private string Variable2Str(Hashtable variables)
- {
- string str = "";
- if (variables != null && variables.Count > 0)
- {
- string vStr = "";
- foreach (DictionaryEntry entry in variables)
- {
- var v = (IwbRtVariable)entry.Value;
- vStr += (vStr == "" ? "" : ",") + IwbRtVariable.Variable2Str(v);
- }
- }
- return str;
- }
- }
- }
|