| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464 |
- using IwbZero.Expr;
- using IwbZero.IwbBase;
- using IwbZero.ToolCommon.StringModel;
- using Newtonsoft.Json;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- using WeEngine.CommonDto.WeInfo;
- using WeEngine.ComponentInfo;
- using WeEngine.Enum;
- using WeEngine.Packages;
- namespace WeEngine.ModelInfo
- {
- public class PackageModel : ModelBase
- {
- public PackageModel()
- {
- Children = new List<RoundModel>();
- }
- public int RoundCount { get; set; }
- public string EngineType { get; set; }
- /// <summary>
- /// 定性评估表达式
- /// </summary>
- public string EvalQualitativeExpression { get; set; }
- public string AssessRoles { get; set; }
- public string AssessRoleNos { get; set; }
- public bool AssessAuto { get; set; }
- public bool AutoNextRound { get; set; }
- public decimal RoundScore { get; set; }
- public List<EngineComponent> Components { get; set; }
- public List<RoundModel> _children;
- public new List<RoundModel> Children
- {
- get
- {
- if (PackageNode != null && PackageNode.HasChild && (_children == null || _children.Count == 0))
- {
- _children = new List<RoundModel>();
- foreach (var child in PackageNode.Children)
- {
- var modal = new RoundModel();
- modal.ModelFrom(child);
- _children.Add(modal);
- }
- }
- return _children;
- }
- set => _children = value;
- }
- private PackageNode _package;
- [JsonIgnore]
- public PackageNode Package { get => _package ?? PackageNodeFrom(); set => _package = value; }
- #region ALL MODEL INFO
- [JsonIgnore]
- public List<RoundModel> AllRoundModels => Children ?? new List<RoundModel>();
- [JsonIgnore]
- public List<BlockModel> AllBlockModels
- {
- get
- {
- var list = new List<BlockModel>();
- foreach (var model in AllRoundModels)
- {
- list.AddRange(model.AllBlockModels);
- }
- return list;
- }
- }
- [JsonIgnore]
- public List<SceneFlowModel> AllFlowModels
- {
- get
- {
- var list = new List<SceneFlowModel>();
- foreach (var model in AllRoundModels)
- {
- list.AddRange(model.AllFlowModels);
- }
- return list;
- }
- }
- [JsonIgnore]
- public List<FlowModel> AllFlowNodeModels
- {
- get
- {
- var list = new List<FlowModel>();
- foreach (var model in AllRoundModels)
- {
- list.AddRange(model.AllFlowNodeModels);
- }
- return list;
- }
- }
- [JsonIgnore]
- public List<SceneModel> AllSceneModels
- {
- get
- {
- var list = new List<SceneModel>();
- foreach (var model in AllRoundModels)
- {
- list.AddRange(model.AllSceneModels);
- }
- return list;
- }
- }
- [JsonIgnore]
- public List<BehaviorModel> AllBehaviorModels
- {
- get
- {
- var list = new List<BehaviorModel>();
- foreach (var model in AllRoundModels)
- {
- list.AddRange(model.AllBehaviorModels);
- }
- return list;
- }
- }
- [JsonIgnore]
- public List<GuideModel> AllGuideModels
- {
- get
- {
- var list = new List<GuideModel>();
- list.AddRange(GuideInfos ?? new List<GuideModel>());
- foreach (var model in AllRoundModels)
- {
- list.AddRange(model.AllGuideModels);
- }
- return list;
- }
- }
- [JsonIgnore]
- public List<EnvironResourceModel> AllEnvironResourceModels
- {
- get
- {
- var list = new List<EnvironResourceModel>();
- foreach (var model in AllRoundModels)
- {
- list.AddRange(model.AllEnvironResourceModels);
- }
- return list;
- }
- }
- #endregion ALL MODEL INFO
- public List<RoleModel> RoleInfos => Package?.AllRoleInfos
- .Select(a => new RoleModel(a.RoleNo, a.RoleName, a.RoleWeight, a.TotalWeight)).ToList();
- //public string AllRoleNames => RoleInfos?.Count > 0
- // ? string.Join(",", RoleInfos.Select(a => a.ToString()).ToArray())
- // : "";
- /// <summary>
- /// 构建方案包Node
- /// </summary>
- /// <param name="xmlInfo"></param>
- /// <returns></returns>
- public PackageNode BuildPackageNodeByXml(WePackageXmlDto xmlInfo)
- {
- var package = new PackageNode
- {
- AssessAuto = AssessAuto,
- AssessRoles = AssessRoles?.Split(',').ToList(),
- EngineType = EngineType,
- AutoNextRound = AutoNextRound,
- RoundScore = RoundScore,
- Parent = null,
- QueryFlowXmlFunc = id => PackageHelper.GetSceneFlowXmlFromXml(xmlInfo.FlowXml, id),
- QuerySceneXmlFunc = id => PackageHelper.GetSceneXmlFromXml(xmlInfo.SceneXml, id),
- QueryBehaviorXmlFunc = id => PackageHelper.GetBehaviorXmlFromXml(xmlInfo.BehaviorXml, id),
- QueryGuidesXmlFunc = ids => PackageHelper.GetGuidesXmlFromXml(xmlInfo.GuideXml, string.Join(",", ids)),
- QueryEnvironmentXmlFunc = id => PackageHelper.GetEnvironResourceXmlFromXml(xmlInfo.EnvironResourceXml, id),
- };
- var packageXmlNode = IwbXmlNode.ParseGenericXml(xmlInfo.PackageXml);
- package = (PackageNode)package.BuildNodeByXmlNode(packageXmlNode);
- Package = package;
- return package;
- }
- /// <summary>
- /// 构建方案包Model
- /// </summary>
- /// <param name="xmlInfo"></param>
- /// <returns></returns>
- public PackageModel BuildPackageModelByXml(WePackageXmlDto xmlInfo)
- {
- var packageNode = BuildPackageNodeByXml(xmlInfo);
- var packageModel = new PackageModel();
- packageModel.ModelFrom(packageNode);
- return packageModel;
- }
- /// <summary>
- /// Model转换为Node
- /// </summary>
- /// <returns></returns>
- public PackageNode PackageNodeFrom()
- {
- var package = new PackageNode
- {
- AssessAuto = AssessAuto,
- AssessRoles = AssessRoles?.Split(',').ToList(),
- EngineType = EngineType,
- AutoNextRound = AutoNextRound,
- RoundScore = RoundScore,
- EvalQualitativeExpression = EvalQualitativeExpression,
- Parent = null,
- };
- package = (PackageNode)NodeFrom(package);
- return package;
- }
- /// <summary>
- /// 方案包转换成 XML Dto
- /// </summary>
- /// <returns></returns>
- public WePackageXmlDto Package2Xml()
- {
- var packageNode = Package;
- var dto = new WePackageXmlDto
- {
- PackageXml = packageNode.ToXmlString(),
- FlowXml = packageNode.Flows2Xml(),
- SceneXml = packageNode.Scenes2Xml(),
- BehaviorXml = packageNode.Behaviors2Xml(),
- GuideXml = packageNode.Guide2Xml(),
- EnvironResourceXml = packageNode.EnvironmentRender2Xml(),
- ComponentXml = new EngineComponent().ConvertComponents2Xml(Components),
- AllRoles = RoleInfos?.Count > 0
- ? string.Join(",", RoleInfos.Select(a => a.ToString()).ToArray())
- : ""
- };
- return dto;
- }
- /// <summary>
- /// 转换Node
- /// </summary>
- /// <param name="node">空Node</param>
- /// <returns></returns>
- internal override NodeBase NodeFrom(NodeBase node)
- {
- var node2 = (PackageNode)base.NodeFrom(node);
- node2.Parent = null;
- var children = new List<SceneRoundNode>();
- if (Children?.Count > 0)
- {
- foreach (var child in Children)
- {
- var childNode = new SceneRoundNode(node2);
- children.Add((SceneRoundNode)child.NodeFrom(childNode));
- }
- }
- node2.Children = children;
- return node2;
- }
- /// <summary>
- /// 转换为Model
- /// </summary>
- /// <param name="node"></param>
- /// <returns></returns>
- internal override void ModelFrom(NodeBase node)
- {
- base.ModelFrom(node);
- var node2 = (PackageNode)node;
- AssessAuto = node2.AssessAuto;
- AssessRoles = string.Join(",", node2.AssessRoles);
- EngineType = node2.EngineType;
- AutoNextRound = node2.AutoNextRound;
- RoundScore = node2.RoundScore;
- EvalQualitativeExpression = node2.EvalQualitativeExpression;
- PackageNode = node2;
- //if (node.HasChild)
- //{
- // Children= new List<RoundModel>();
- // foreach (var child in node.Children)
- // {
- // var modal = new RoundModel() ;
- // modal.ModelFrom(child);
- // Children.Add(modal);
- // }
- //}
- }
- }
- public class RoundModel : ModelBase
- {
- public int RoundIndex { get; set; }
- public int BlockIndex { get; set; }
- public decimal RoundFullScore { get; set; }
- public int ControlRate { get; set; }
- public int SceneCount { get; set; }
- public List<BlockModel> _children;
- public new List<BlockModel> Children
- {
- get
- {
- if (PackageNode != null && PackageNode.HasChild && (_children == null || _children.Count == 0))
- {
- _children = new List<BlockModel>();
- foreach (var child in PackageNode.Children)
- {
- var modal = new BlockModel();
- modal.ModelFrom(child);
- _children.Add(modal);
- }
- }
- return _children;
- }
- set => _children = value;
- }
- #region ALL MODEL INFO
- [JsonIgnore]
- public List<BlockModel> AllBlockModels => Children ?? new List<BlockModel>();
- [JsonIgnore]
- public List<SceneFlowModel> AllFlowModels
- {
- get
- {
- var list = new List<SceneFlowModel>();
- foreach (var model in AllBlockModels)
- {
- list.AddRange(model.AllFlowModels);
- }
- return list;
- }
- }
- [JsonIgnore]
- public List<FlowModel> AllFlowNodeModels
- {
- get
- {
- var list = new List<FlowModel>();
- foreach (var model in AllBlockModels)
- {
- list.AddRange(model.AllFlowNodeModels);
- }
- return list;
- }
- }
- [JsonIgnore]
- public List<SceneModel> AllSceneModels
- {
- get
- {
- var list = new List<SceneModel>();
- foreach (var model in AllBlockModels)
- {
- list.AddRange(model.AllSceneModels);
- }
- return list;
- }
- }
- [JsonIgnore]
- public List<BehaviorModel> AllBehaviorModels
- {
- get
- {
- var list = new List<BehaviorModel>();
- foreach (var model in AllBlockModels)
- {
- list.AddRange(model.AllBehaviorModels);
- }
- return list;
- }
- }
- [JsonIgnore]
- public List<GuideModel> AllGuideModels
- {
- get
- {
- var list = new List<GuideModel>();
- list.AddRange(GuideInfos ?? new List<GuideModel>());
- foreach (var model in AllBlockModels)
- {
- list.AddRange(model.AllGuideModels);
- }
- return list;
- }
- }
- [JsonIgnore]
- public List<EnvironResourceModel> AllEnvironResourceModels
- {
- get
- {
- var list = new List<EnvironResourceModel>();
- foreach (var model in AllBlockModels)
- {
- list.AddRange(model.AllEnvironResourceModels);
- }
- return list;
- }
- }
- #endregion ALL MODEL INFO
- /// <summary>
- /// 转换Node
- /// </summary>
- /// <param name="node">空Node</param>
- /// <returns></returns>
- internal override NodeBase NodeFrom(NodeBase node)
- {
- var newNode = (SceneRoundNode)base.NodeFrom(node);
- newNode.RoundIndex = RoundIndex;
- newNode.RoundFullScore = RoundFullScore;
- newNode.ControlRate = ControlRate;
- newNode.SceneCount = SceneCount;
- if (Children?.Count > 0)
- {
- var list = new List<SceneFlowBlockNode>();
- foreach (var child in Children)
- {
- var childNode = new SceneFlowBlockNode(newNode);
- list.Add((SceneFlowBlockNode)child.NodeFrom(childNode));
- }
- newNode.Children = list;
- }
- return newNode;
- }
- /// <summary>
- /// 转换Model
- /// </summary>
- /// <param name="node"></param>
- /// <returns></returns>
- internal override void ModelFrom(NodeBase node)
- {
- base.ModelFrom(node);
- var node2 = (SceneRoundNode)node;
- RoundIndex = node2.RoundIndex;
- RoundFullScore = node2.RoundFullScore;
- ControlRate = node2.ControlRate;
- SceneCount = node2.SceneCount;
- PackageNode = node2;
- //if (node.HasChild)
- //{
- // Children = new List<BlockModel>();
- // foreach (var child in node.Children)
- // {
- // var modal = new BlockModel();
- // modal.ModelFrom(child);
- // Children.Add(modal);
- // }
- //}
- }
- }
- public class BlockModel : ModelBase
- {
- public int BlockType { get; set; }
- public string FlowNos { get; set; }
- public string FlowNames { get; set; }
- public List<SceneFlowModel> _children;
- public new List<SceneFlowModel> Children
- {
- get
- {
- if (PackageNode != null && PackageNode.HasChild && (_children == null || _children.Count == 0))
- {
- _children = new List<SceneFlowModel>();
- foreach (var child in PackageNode.Children)
- {
- var modal = new SceneFlowModel();
- modal.ModelFrom(child);
- _children.Add(modal);
- }
- }
- return _children;
- }
- set => _children = value;
- }
- #region ALL MODEL INFO
- [JsonIgnore]
- public List<SceneFlowModel> AllFlowModels => Children ?? new List<SceneFlowModel>();
- [JsonIgnore]
- public List<FlowModel> AllFlowNodeModels
- {
- get
- {
- var list = new List<FlowModel>();
- foreach (var model in AllFlowModels)
- {
- list.AddRange(model.AllFlowNodeModels);
- }
- return list;
- }
- }
- [JsonIgnore]
- public List<SceneModel> AllSceneModels
- {
- get
- {
- var list = new List<SceneModel>();
- foreach (var model in AllFlowModels)
- {
- list.AddRange(model.AllSceneModels);
- }
- return list;
- }
- }
- [JsonIgnore]
- public List<BehaviorModel> AllBehaviorModels
- {
- get
- {
- var list = new List<BehaviorModel>();
- foreach (var model in AllFlowModels)
- {
- list.AddRange(model.AllBehaviorModels);
- }
- return list;
- }
- }
- [JsonIgnore]
- public List<GuideModel> AllGuideModels
- {
- get
- {
- var list = new List<GuideModel>();
- list.AddRange(GuideInfos ?? new List<GuideModel>());
- foreach (var model in AllFlowModels)
- {
- list.AddRange(model.AllGuideModels);
- }
- return list;
- }
- }
- [JsonIgnore]
- public List<EnvironResourceModel> AllEnvironResourceModels
- {
- get
- {
- var list = new List<EnvironResourceModel>();
- foreach (var model in AllFlowModels)
- {
- list.AddRange(model.AllEnvironResourceModels);
- }
- return list;
- }
- }
- #endregion ALL MODEL INFO
- /// <summary>
- /// 转换Node
- /// </summary>
- /// <param name="node">空Node</param>
- /// <returns></returns>
- internal override NodeBase NodeFrom(NodeBase node)
- {
- var newNode = (SceneFlowBlockNode)base.NodeFrom(node);
- newNode.BlockType = (SceneFlowBlockType)BlockType;
- if (Children?.Count > 0)
- {
- var list = new List<SceneFlowNode>();
- foreach (var child in Children)
- {
- var childNode = new SceneFlowNode(newNode);
- list.Add((SceneFlowNode)child.NodeFrom(childNode));
- }
- newNode.Children = list;
- }
- return newNode;
- }
- /// <summary>
- /// 转换为Model
- /// </summary>
- /// <param name="node"></param>
- /// <returns></returns>
- internal override void ModelFrom(NodeBase node)
- {
- base.ModelFrom(node);
- var node2 = (SceneFlowBlockNode)node;
- BlockType = (int)node2.BlockType;
- PackageNode = node2;
- //if (node.HasChild)
- //{
- // Children = new List<SceneFlowModel>();
- // foreach (var child in node.Children)
- // {
- // var modal = new SceneFlowModel();
- // modal.ModelFrom(child);
- // Children.Add(modal);
- // }
- //}
- }
- }
- public class SceneFlowModel : ModelBase
- {
- public FlowModel ContentInfo { get; set; }
- public List<FlowModel> _children;
- public new List<FlowModel> Children
- {
- get
- {
- if (PackageNode != null && PackageNode.HasChild && (_children == null || _children.Count == 0))
- {
- _children = new List<FlowModel>();
- foreach (var child in PackageNode.Children)
- {
- var modal = new FlowModel();
- modal.ModelFrom(child);
- _children.Add(modal);
- }
- }
- return _children;
- }
- set => _children = value;
- }
- #region ALL MODEL INFO
- [JsonIgnore]
- public List<FlowModel> AllFlowNodeModels
- {
- get
- {
- var list = new List<FlowModel>();
- foreach (var child in Children)
- {
- list.AddRange(GetFlowModels(child));
- }
- return list;
- }
- }
- [JsonIgnore]
- public List<SceneModel> AllSceneModels
- {
- get
- {
- var list = new List<SceneModel>();
- foreach (var model in AllFlowNodeModels)
- {
- list.AddRange(model.AllSceneModels);
- }
- return list;
- }
- }
- [JsonIgnore]
- public List<BehaviorModel> AllBehaviorModels
- {
- get
- {
- var list = new List<BehaviorModel>();
- foreach (var model in AllFlowNodeModels)
- {
- list.AddRange(model.AllBehaviorModels);
- }
- return list;
- }
- }
- [JsonIgnore]
- public List<GuideModel> AllGuideModels
- {
- get
- {
- var list = new List<GuideModel>();
- list.AddRange(GuideInfos ?? new List<GuideModel>());
- foreach (var model in AllFlowNodeModels)
- {
- list.AddRange(model.AllGuideModels);
- }
- return list;
- }
- }
- [JsonIgnore]
- public List<EnvironResourceModel> AllEnvironResourceModels
- {
- get
- {
- var list = new List<EnvironResourceModel>();
- foreach (var model in AllFlowNodeModels)
- {
- list.AddRange(model.AllEnvironResourceModels);
- }
- return list;
- }
- }
- #endregion ALL MODEL INFO
- /// <summary>
- /// 转换Node
- /// </summary>
- /// <param name="node">空Node</param>
- /// <returns></returns>
- internal override NodeBase NodeFrom(NodeBase node)
- {
- var newNode = (SceneFlowNode)base.NodeFrom(node);
- if (Children?.Count > 0)
- {
- var list = new List<FlowNode>();
- foreach (var child in Children)
- {
- var childNode = new FlowNode(newNode);
- list.Add((FlowNode)child.NodeFrom(childNode));
- }
- newNode.Children = list;
- }
- return newNode;
- }
- /// <summary>
- /// 转换为Model
- /// </summary>
- /// <param name="node"></param>
- /// <returns></returns>
- internal override void ModelFrom(NodeBase node)
- {
- base.ModelFrom(node);
- var node2 = (SceneFlowNode)node;
- PackageNode = node2;
- //if (node.HasChild)
- //{
- // Children = new List<FlowModel>();
- // foreach (var child in node.Children)
- // {
- // var modal = new FlowModel();
- // modal.ModelFrom(child);
- // Children.Add(modal);
- // }
- //}
- }
- private List<FlowModel> GetFlowModels(FlowModel model)
- {
- var list = new List<FlowModel>();
- if (model == null)
- {
- return list;
- }
- list.Add(model);
- if (model.Children?.Count > 0)
- {
- foreach (var child in model.Children)
- {
- var children = GetFlowModels(child);
- list.AddRange(children);
- }
- }
- return list;
- }
- }
- public class FlowModel : ModelBase
- {
- public int Index { get; set; }
- public int FlowDepth { get; set; }
- [JsonIgnore]
- public string _sceneNos;
- public string SceneNos
- {
- get
- {
- return _sceneNos ??
- string.Join(",", Children?.Select(a => a.Id).ToArray() ?? Array.Empty<string>());
- }
- set => _sceneNos = value;
- }
- public string SceneNames => string.Join(",", SceneInfos?.Select(a => a.Name) ?? Array.Empty<string>());
- public List<FlowModel> _children;
- public new List<FlowModel> Children
- {
- get
- {
- if (PackageNode != null && PackageNode.HasChild && (_children == null || _children.Count == 0))
- {
- _children = new List<FlowModel>();
- foreach (var child in PackageNode.Children)
- {
- var modal = new FlowModel();
- modal.ModelFrom(child);
- _children.Add(modal);
- }
- }
- return _children;
- }
- set => _children = value;
- }
- public List<SceneModel> _sceneInfos;
- public List<SceneModel> SceneInfos
- {
- get
- {
- if (PackageNode != null && (_sceneInfos == null || _sceneInfos.Count == 0))
- {
- _sceneInfos = new List<SceneModel>();
- if (PackageNode != null)
- {
- var node = (FlowNode)PackageNode;
- foreach (var child in node.SceneInfos)
- {
- var modal = new SceneModel();
- modal.ModelFrom(child);
- _sceneInfos.Add(modal);
- }
- }
- }
- return _sceneInfos;
- }
- set => _sceneInfos = value;
- }
- #region ALL MODEL INFO
- [JsonIgnore]
- public List<SceneModel> AllSceneModels => SceneInfos ?? new List<SceneModel>();
- [JsonIgnore]
- public List<BehaviorModel> AllBehaviorModels
- {
- get
- {
- var list = new List<BehaviorModel>();
- foreach (var model in AllSceneModels)
- {
- list.AddRange(model.AllBehaviorModels);
- }
- return list;
- }
- }
- [JsonIgnore]
- public List<GuideModel> AllGuideModels
- {
- get
- {
- var list = new List<GuideModel>();
- list.AddRange(GuideInfos ?? new List<GuideModel>());
- foreach (var model in AllSceneModels)
- {
- list.AddRange(model.AllGuideModels);
- }
- return list;
- }
- }
- [JsonIgnore]
- public List<EnvironResourceModel> AllEnvironResourceModels
- {
- get
- {
- var list = new List<EnvironResourceModel>();
- foreach (var model in AllSceneModels)
- {
- list.AddRange(model.AllEnvironResourceModels);
- }
- return list;
- }
- }
- #endregion ALL MODEL INFO
- /// <summary>
- /// 转换Node
- /// </summary>
- /// <param name="node">空Node</param>
- /// <returns></returns>
- internal override NodeBase NodeFrom(NodeBase node)
- {
- var newNode = (FlowNode)base.NodeFrom(node);
- if (Children?.Count > 0)
- {
- var list = new List<FlowNode>();
- foreach (var child in Children)
- {
- var childNode = new FlowNode(newNode);
- list.Add((FlowNode)child.NodeFrom(childNode));
- }
- newNode.Children = list;
- }
- if (SceneInfos?.Count > 0)
- {
- var list = new List<SceneNode>();
- foreach (var child in SceneInfos)
- {
- var childNode = new SceneNode(newNode);
- list.Add((SceneNode)child.NodeFrom(childNode));
- }
- newNode.SceneInfos = list;
- }
- return newNode;
- }
- /// <summary>
- /// 转换Model
- /// </summary>
- /// <param name="node"></param>
- /// <returns></returns>
- internal override void ModelFrom(NodeBase node)
- {
- base.ModelFrom(node);
- var node2 = (FlowNode)node;
- PackageNode = node2;
- //if (node.HasChild)
- //{
- // Children = new List<FlowModel>();
- // foreach (var child in node.Children)
- // {
- // var modal = new FlowModel();
- // modal.ModelFrom(child);
- // Children.Add(modal);
- // }
- //}
- //if (node2.SceneInfos?.Count > 0)
- //{
- // SceneInfos = new List<SceneModel>();
- // foreach (var child in node2.SceneInfos)
- // {
- // var modal = new SceneModel();
- // modal.ModelFrom(child);
- // SceneInfos.Add(modal);
- // }
- //}
- }
- }
- public class SceneModel : ModelBase
- {
- public SceneModel()
- {
- Children = new List<BehaviorModel>();
- EnvironResources = new List<EnvironResourceModel>();
- }
- public int SceneType { get; set; }
- public string SceneTag { get; set; }
- public string _description { get; set; }
- public string Description
- {
- get
- {
- var desc = _description ?? "";
- if (Variables != null && _description.IsNotEmpty())
- {
- if (desc.IndexOf(IwbVariableType.Local, StringComparison.Ordinal) >= 0)
- {
- var reg = new Regex("@[0-9,a-z,A-Z]*");
- desc = reg.Replace(desc, match => match.ToString().ToUpper());
- desc = EvalExpr.TransVariable(desc, Variables);
- }
- //foreach (DictionaryEntry entry in Variables)
- //{
- // var variable = (IwbRtVariable)entry.Value;
- // desc = desc.Replace(variable.VarName.ToUpper(), variable.GetStringValue());
- //}
- return desc;
- }
- return desc;
- }
- }
- [JsonIgnore]
- public string _behaviorNos;
- public string BehaviorNos
- {
- get
- {
- return _behaviorNos ??
- string.Join(",", Children?.Select(a => a.Id).ToArray() ?? Array.Empty<string>());
- }
- set => _behaviorNos = value;
- }
- [JsonIgnore]
- private string _environResourceNos;
- public string EnvironResourceNos
- {
- get
- {
- return _environResourceNos ??
- string.Join(",", EnvironResources?.Select(a => a.Id).ToArray() ?? Array.Empty<string>());
- }
- set => _environResourceNos = value;
- }
- private List<EnvironResourceModel> _environResources;
- [JsonIgnore]
- public List<EnvironResourceModel> EnvironResources
- {
- get
- {
- if (_environResources == null)
- {
- var node = (SceneNode)PackageNode;
- _environResources = node?.EnvironResources?.Select(a => new EnvironResourceModel().ModelFrom(a)).ToList() ??
- new List<EnvironResourceModel>();
- }
- return _environResources;
- }
- set => _environResources = value;
- }
- [JsonIgnore]
- public Hashtable _variables;
- [JsonIgnore]
- public Hashtable Variables
- {
- get => _variables != null && _variables.Count > 0 ? _variables : GetVariable();
- set => _variables = value;
- }
- [JsonIgnore]
- public List<BehaviorModel> _children;
- public new List<BehaviorModel> Children
- {
- get
- {
- if (PackageNode != null && PackageNode.HasChild && (_children == null || _children.Count == 0))
- {
- _children = new List<BehaviorModel>();
- foreach (var child in PackageNode.Children)
- {
- var modal = new BehaviorModel();
- modal.ModelFrom(child);
- _children.Add(modal);
- }
- }
- return _children;
- }
- set => _children = value;
- }
- #region ALL MODEL INFO
- [JsonIgnore]
- public List<BehaviorModel> AllBehaviorModels => Children;
- [JsonIgnore]
- public List<GuideModel> AllGuideModels
- {
- get
- {
- var list = new List<GuideModel>();
- list.AddRange(GuideInfos ?? new List<GuideModel>());
- foreach (var model in AllBehaviorModels)
- {
- list.AddRange(model.AllGuideModels);
- }
- return list;
- }
- }
- [JsonIgnore]
- public List<EnvironResourceModel> AllEnvironResourceModels
- {
- get
- {
- var list = new List<EnvironResourceModel>();
- list.AddRange(EnvironResources ?? new List<EnvironResourceModel>());
- foreach (var model in AllBehaviorModels)
- {
- list.AddRange(model.AllEnvironResourceModels);
- }
- return list;
- }
- }
- #endregion ALL MODEL INFO
- /// <summary>
- /// 转换Node
- /// </summary>
- /// <param name="node">空Node</param>
- /// <returns></returns>
- internal override NodeBase NodeFrom(NodeBase node)
- {
- var newNode = (SceneNode)base.NodeFrom(node);
- newNode.SceneTag = SceneTag;
- newNode.Description = _description;
- newNode.SceneType = (SceneType)SceneType;
- newNode.EnvironResources = EnvironResources?.Select(a => a.NodeFrom()).ToList() ?? new List<EnvironResourceNode>();
- if (Children?.Count > 0)
- {
- var list = new List<BehaviorNode>();
- foreach (var child in Children)
- {
- var childNode = new BehaviorNode(newNode);
- list.Add((BehaviorNode)child.NodeFrom(childNode));
- }
- newNode.Children = list;
- }
- return newNode;
- }
- /// <summary>
- /// 转换为Model
- /// </summary>
- /// <param name="node"></param>
- /// <returns></returns>
- internal override void ModelFrom(NodeBase node)
- {
- base.ModelFrom(node);
- var node2 = (SceneNode)node;
- PackageNode = node2;
- SceneTag = node2.SceneTag;
- SceneType = (int)node2.SceneType;
- _description = node2.Description;
- //EnvironResources = node2.EnvironResources?.Select(a => new EnvironResourceModel().ModelFrom(a)).ToList() ?? new List<EnvironResourceModel>();
- //if (node.HasChild)
- //{
- // foreach (var child in node.Children)
- // {
- // var modal = new BehaviorModel();
- // modal.ModelFrom(child);
- // Children.Add(modal);
- // }
- //}
- }
- }
- public class BehaviorModel : ModelBase
- {
- public BehaviorModel()
- {
- EnvironResources = new List<EnvironResourceModel>();
- }
- public string BehaviorTag { get; set; }
- public string Description { get; set; }
- public int BehaviorScoreType { get; set; }
- public int RoleLogicType { get; set; }
- private List<RoleModel> _behaviorRoles { get; set; }
- public List<RoleModel> BehaviorRoles
- {
- get
- {
- if (_behaviorRoles == null)
- {
- var node = (BehaviorNode)PackageNode;
- _behaviorRoles = node?.BehaviorRoles?.Count > 0
- ? node.BehaviorRoles.Select(a => new RoleModel(a.RoleNo, a.RoleName, a.RoleWeight, a.TotalWeight)).ToList()
- : new List<RoleModel>();
- }
- return _behaviorRoles;
- }
- set => _behaviorRoles = value;
- }
- public string RoleNames => string.Join(",", BehaviorRoles?.Select(a => a.RoleName).ToList() ?? new List<string>());
- public string RuleKeyword { get; set; }
- public string KnowledgeNos { get; set; }
- [JsonIgnore]
- private string _environResourceNos;
- public string EnvironResourceNos
- {
- get
- {
- return _environResourceNos ??
- string.Join(",", EnvironResources?.Select(a => a.Id).ToArray() ?? new string[0]);
- }
- set => _environResourceNos = value;
- }
- private List<EnvironResourceModel> _environResources;
- [JsonIgnore]
- public List<EnvironResourceModel> EnvironResources
- {
- get
- {
- if (_environResources == null)
- {
- var node = (BehaviorNode)PackageNode;
- _environResources = node?.EnvironResources?.Select(a => new EnvironResourceModel().ModelFrom(a)).ToList() ??
- new List<EnvironResourceModel>();
- }
- return _environResources;
- }
- set => _environResources = value;
- }
- #region ALL MODEL INFO
- [JsonIgnore]
- public List<GuideModel> AllGuideModels => GuideInfos ?? new List<GuideModel>();
- [JsonIgnore]
- public List<EnvironResourceModel> AllEnvironResourceModels =>
- EnvironResources ?? new List<EnvironResourceModel>();
- #endregion ALL MODEL INFO
- /// <summary>
- /// 转换Node
- /// </summary>
- /// <param name="node">空Node</param>
- /// <returns></returns>
- internal override NodeBase NodeFrom(NodeBase node)
- {
- var newNode = (BehaviorNode)base.NodeFrom(node);
- newNode.BehaviorTag = BehaviorTag;
- newNode.BehaviorRoleLogic = (BehaviorRoleLogicType)RoleLogicType;
- newNode.BehaviorScoreType = (BehaviorScoreType)BehaviorScoreType;
- newNode.BehaviorRoles = BehaviorRoles?.Count > 0
- ? BehaviorRoles.Select(a => new RoleNode(a.RoleNo, a.RoleName)).ToList()
- : new List<RoleNode>();
- newNode.EnvironResources = new List<EnvironResourceNode>();
- newNode.Description = Description;
- newNode.BuildKeywordNodes(RuleKeyword);
- newNode.EnvironResources = EnvironResources?.Select(a => a.NodeFrom()).ToList() ?? new List<EnvironResourceNode>();
- return newNode;
- }
- /// <summary>
- /// 转换为Model
- /// </summary>
- /// <param name="node"></param>
- /// <returns></returns>
- internal override void ModelFrom(NodeBase node)
- {
- base.ModelFrom(node);
- var node2 = (BehaviorNode)node;
- BehaviorTag = node2.BehaviorTag;
- RoleLogicType = (int)node2.BehaviorRoleLogic;
- BehaviorScoreType = (int)node2.BehaviorScoreType;
- //BehaviorRoles = node2.BehaviorRoles?.Count > 0
- // ? node2.BehaviorRoles.Select(a => new RoleModel(a.RoleNo, a.RoleName, a.RoleWeight, a.TotalWeight)).ToList()
- // : new List<RoleModel>();
- Description = node2.Description;
- RuleKeyword = node2.Keywords;
- //EnvironResources = node2.EnvironResources?.Select(a => new EnvironResourceModel().ModelFrom(a)).ToList() ?? new List<EnvironResourceModel>();
- //if (node.HasChild)
- //{
- // foreach (var child in node.Children)
- // {
- // var modal = new BehaviorModel() ;
- // modal.ModelFrom(child);
- // Children.Add(modal);
- // }
- //}
- }
- }
- public class GuideModel
- {
- public string Id { get; set; }
- /// <summary>
- /// 提示名称
- /// </summary>
- public string Name { get; set; }
- /// <summary>
- /// 提示详情
- /// </summary>
- public string Description { get; set; }
- /// <summary>
- /// 提示类型
- /// </summary>
- public int GuideType { get; set; }
- public GuideNode NodeFrom()
- {
- var node = new GuideNode
- {
- Id = Id,
- Name = Name,
- GuideType = GuideType,
- Description = Description,
- };
- return node;
- }
- public GuideModel ModelFrom(GuideNode node)
- {
- if (node == null)
- {
- return null;
- }
- Id = node.Id;
- Name = node.Name;
- GuideType = node.GuideType;
- Description = node.Description;
- return this;
- }
- }
- public class EnvironResourceModel
- {
- public string Id { get; set; }
- /// <summary>
- /// 资源名称
- /// </summary>
- public string ResourceName { get; set; }
- /// <summary>
- /// 资源类型
- /// </summary>
- public int ResourceType { get; set; }
- /// <summary>
- /// 资源路径
- /// </summary>
- public string ResourcePath { get; set; }
- /// <summary>
- /// 资源描述
- /// </summary>
- public string Description { get; set; }
- public string MessageCode { get; set; }
- public EnvironResourceNode NodeFrom()
- {
- var node = new EnvironResourceNode
- {
- Id = Id,
- ResourceName = ResourceName,
- ResourceType = ResourceType,
- ResourcePath = ResourcePath,
- Description = Description,
- MessageCode = MessageCode
- };
- return node;
- }
- public EnvironResourceModel ModelFrom(EnvironResourceNode node)
- {
- if (node == null)
- {
- return null;
- }
- Id = node.Id;
- ResourceName = node.ResourceName;
- ResourceType = node.ResourceType;
- ResourcePath = node.ResourcePath;
- MessageCode = node.MessageCode;
- Description = node.Description;
- return this;
- }
- }
- public class RoleModel
- {
- public RoleModel()
- {
- }
- public RoleModel(string roleNo, string roleName)
- {
- RoleNo = roleNo;
- RoleName = roleName;
- RoleWeight = 1;
- TotalWeight = 1;
- }
- public RoleModel(string roleNo, string roleName, decimal roleWeight, decimal totalWeight)
- {
- RoleNo = roleNo;
- RoleName = roleName;
- RoleWeight = roleWeight;
- TotalWeight = totalWeight;
- }
- public string RoleNo { get; set; }
- public string RoleName { get; set; }
- public decimal RoleWeight { get; }
- public decimal TotalWeight { get; }
- public decimal RolePer => Math.Round(TotalWeight == 0 ? 0 : RoleWeight * 100 / TotalWeight, 2);
- public static RoleModel ModelFrom(string roles)
- {
- var node = new RoleNode();
- var arr = roles.Split(':');
- node.RoleNo = arr[0];
- if (arr.Length > 1)
- {
- node.RoleName = arr[1];
- }
- if (arr.Length > 2)
- {
- node.SetWeight(int.TryParse(arr[2], out var w) ? w : 0);
- }
- if (arr.Length > 3)
- {
- node.SetTotalWeight(int.TryParse(arr[3], out var w) ? w : 0);
- }
- return new RoleModel(node.RoleNo, node.RoleName, node.RoleWeight, node.TotalWeight);
- }
- public override string ToString()
- {
- return new RoleNode(RoleNo, RoleName, RoleWeight, TotalWeight).ToString();
- }
- }
- }
|