using System.Collections; using System.Collections.Generic; using System.Linq; using IwbZero.IwbBase; using IwbZero.ToolCommon.StringModel; using Newtonsoft.Json; using WeEngine.Enum; using WeEngine.Packages; namespace WeEngine.CommonDto { public class RunningBase { public RunningBase() { } public RunningBase(NodeBase node) { Id = node.Id; No = node.InternalNo; Name = node.Name; CorrectionScore = node.CorrectionScore; SystemScore = node.ActualScore; FullScore = node.NodeFullScore; WaitPath = node.WaitPath; Variables = ""; if (node.Variables != null && node.Variables.Count > 0) { foreach (DictionaryEntry entry in node.Variables) { if (!DefaultVariable.VariableNames.Contains(entry.Key)) { var v = (IwbRtVariable)entry.Value; Variables += (Variables == "" ? "" : ",") + $"[{v.VarName}:{v.DataType.TypeString}:{v.GetStringValue()}]"; } } } IsStart = node.NodeState == NodeState.Running || node.NodeState == NodeState.RunEnd || node.NodeState == NodeState.Complete; IsEnd = node.NodeState == NodeState.RunEnd || node.NodeState == NodeState.Complete; } [JsonIgnore] public RunningBase Parent { get; set; } public string Id { get; set; } public string No { get; set; } public string Name { get; set; } [JsonIgnore] public string ParentPath => Parent?.Path ?? ""; public string Path => GetNodePath(); public string Variables{ get; set; } public decimal FullScore { get; set; } public decimal CorrectionScore { get; set; } public decimal SystemScore { get; set; } public bool IsStart { get; set; } public bool IsEnd { get; set; } public List WaitPath { get; set; } protected virtual string GetNodePath() { return Parent != null ? $"{ParentPath}_{No}" : No; } [JsonIgnore] public Hashtable VariableTable => GetVariableTable(); private Hashtable GetVariableTable() { var vTable= new Hashtable(); if (Variables.IsNotEmpty()) { var varArr = Variables.StrToArray(); foreach (var v in varArr) { var arr = v.StrToArray(":"); string id = ""; if (arr.Length > 0) { id = arr[0].UAndT(); } if (id.IsNotEmpty()) { vTable[id] = IwbRtVariable.Str2Variable(v); } } } return vTable; } public Hashtable GetVariables() { var variables = new Hashtable().MergeHashtable(VariableTable); if (Parent != null) { variables = Parent.GetVariables().MergeHashtable(variables); } return variables; } public List GetRunRoundInfo(List roundInfo) { return roundInfo?.Where(a => a.IsStart).ToList() ?? new List(); } public List GetRunBlockInfo(List roundInfo) { var list = new List(); foreach (var info in roundInfo) { var temp = info.BlockInfo?.Where(a => a.IsStart); if (temp != null) { list.AddRange(temp); } } return list; } public List GetRunFlowInfo(List blockInfo) { var list = new List(); foreach (var info in blockInfo) { var temp = info.FlowInfo?.Where(a => a.IsStart); if (temp != null) { list.AddRange(temp); } } return list; } public List GetRunNodeInfo(List flowInfo) { var list = new List(); foreach (var info in flowInfo) { var temp = info.NodeInfo?.FirstOrDefault(a => a.IsStart); if (temp != null) { list.Add(temp); list = GetRunChildNodeInfo(list, temp.NodeInfo); } } return list; } private List GetRunChildNodeInfo(List list, List childNodes) { var temp = childNodes?.FirstOrDefault(a => a.IsStart); if (temp != null) { list.Add(temp); if (temp.NodeInfo != null && temp.NodeInfo.Any()) { list = GetRunChildNodeInfo(list, temp.NodeInfo); } } return list; } public List GetRunSceneInfo(List nodeInfo) { var list = new List(); foreach (var info in nodeInfo) { var temp = info.SceneInfo?.Where(a => a.IsStart); if (temp != null) { list.AddRange(temp); } } return list; } public List GetRunBehaviorInfo(List sceneInfo) { var list = new List(); foreach (var info in sceneInfo) { var temp = info.BehaviorInfo?.Where(a => a.IsStart); if (temp != null) { list.AddRange(temp); } } return list; } } public class RunningInfo : RunningBase { public RunningInfo() { Parent = null; } public RunningInfo(NodeBase node) : base(node) { } public string PackageNo { get; set; } public int CurrentRoundIndex { get; set; } /// /// 考核角色 /// public List AssessRoles { get; set; } /// /// 未考核分数自动运行(满分) /// public bool AssessAuto { get; set; } /// /// 自动下一轮 /// public bool AutoNextRound { get; set; } /// /// 每轮总分 /// public decimal RoundScore { get; set; } [JsonIgnore] private List _infos; public List RoundInfo { get { if (_infos != null && _infos.Any()) { foreach (var info in _infos) { info.Parent = this; } } return _infos; } set => _infos = value; } #region Current-RUN [JsonIgnore] public List RunRoundInfo => GetRunRoundInfo(RoundInfo); [JsonIgnore] public List RunBlockInfo => GetRunBlockInfo(RunRoundInfo); [JsonIgnore] public List RunFlowInfo => GetRunFlowInfo(RunBlockInfo); [JsonIgnore] public List RunNodeInfo => GetRunNodeInfo(RunFlowInfo); [JsonIgnore] public List RunSceneInfo => GetRunSceneInfo(RunNodeInfo); [JsonIgnore] public List RunBehaviorInfo => GetRunBehaviorInfo(RunSceneInfo); #endregion } public class RoundRunningInfo: RunningBase { public RoundRunningInfo() { } public RoundRunningInfo(NodeBase node) : base(node) { RoundIndex = ((SceneRoundNode) node).RoundIndex; } public int RoundIndex { get; set; } [JsonIgnore] private List _infos; public List BlockInfo { get { if (_infos != null && _infos.Any()) { foreach (var info in _infos) { info.Parent = this; } } return _infos; } set => _infos = value; } [JsonIgnore] public List RunBlockInfos => BlockInfo.Where(a=>a.IsStart).ToList(); [JsonIgnore] public List RunFlowInfos => GetRunFlowInfo(RunBlockInfos); [JsonIgnore] public List RunNodeInfos => GetRunNodeInfo(RunFlowInfos); [JsonIgnore] public List RunSceneInfos => GetRunSceneInfo(RunNodeInfos); [JsonIgnore] public List RunBehaviorInfos => GetRunBehaviorInfo(RunSceneInfos); [JsonIgnore] public List FlowInfos => GetRunFlowInfo(BlockInfo); [JsonIgnore] public List NodeInfos => GetRunNodeInfo(FlowInfos); [JsonIgnore] public List SceneInfos => GetRunSceneInfo(NodeInfos); [JsonIgnore] public List BehaviorInfos => GetRunBehaviorInfo(SceneInfos); } public class BlockRunningInfo: RunningBase { public BlockRunningInfo() { } public BlockRunningInfo(NodeBase node) : base(node) { BlockType = ((SceneFlowBlockNode) node).BlockType; } public SceneFlowBlockType BlockType { get; set; } [JsonIgnore] private List _infos; public List FlowInfo { get { if (_infos != null && _infos.Any()) { foreach (var info in _infos) { info.Parent = this; } } return _infos; } set => _infos = value; } } public class FlowRunningInfo: RunningBase { public FlowRunningInfo() { } public FlowRunningInfo(NodeBase node) : base(node) { } [JsonIgnore] private List _infos; public List NodeInfo { get { if (_infos != null && _infos.Any()) { foreach (var info in _infos) { info.Parent = this; } } return _infos; } set => _infos = value; } } public class FlowNodeRunningInfo: RunningBase { public FlowNodeRunningInfo() { } public FlowNodeRunningInfo(NodeBase node) : base(node) { } [JsonIgnore] private List _sInfos; public List SceneInfo { get { if (_sInfos != null && _sInfos.Any()) { foreach (var info in _sInfos) { info.Parent = this; } } return _sInfos; } set => _sInfos = value; } [JsonIgnore] private List _infos; public List NodeInfo { get { if (_infos != null && _infos.Any()) { foreach (var info in _infos) { info.Parent = this; } } return _infos; } set => _infos = value; } } public class SceneRunningInfo: RunningBase { public SceneRunningInfo() { } public SceneRunningInfo(NodeBase node) : base(node) { //var variables = node.GetSelfVariables(); //if (variables != null && variables.Count > 0) //{ // foreach (DictionaryEntry entry in variables) // { // var v = (IwbRtVariable)entry.Value; // Variables += (Variables == "" ? "" : ",") + $"[{v.VarName}:{v.DataType.TypeString}:{v.GetStringValue()}]"; // } //} } [JsonIgnore] private List _infos; public List BehaviorInfo { get { if (_infos != null && _infos.Any()) { foreach (var info in _infos) { info.Parent = this; } } return _infos; } set => _infos = value; } } public class BehaviorRunningInfo: RunningBase { public BehaviorRunningInfo() { } public string KeyWords { get; set; } public BehaviorRunningInfo(NodeBase node) : base(node) { } } }