using Glorysoft.SECS.EQP.Commands; using Glorysoft.SECS.EQP.Message; using Glorysoft.SECS.EQP.Utilities; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Xml.Serialization; namespace Glorysoft.SECS.EQP { public static class ScenarioExtension { public static void ExecuteNextStep(this Scenario scenario) { if (scenario.CurrentStep > 1) { var prevWF = scenario.WorkFlows.FirstOrDefault(item => item.Step == scenario.CurrentStep); SimulatorInfo.Instance.ShowInfo = $"ScenarioName: {scenario.Name}, StepCount: {scenario.WorkFlows.Count}, CurrentStep: {scenario.CurrentStep}, Message: {prevWF.MessageName}."; } scenario.CurrentStep++; if (scenario.CurrentStep >= scenario.WorkFlows.Count) { return; } var nextWF = scenario.WorkFlows.FirstOrDefault(item => item.Step == scenario.CurrentStep); SimulatorInfo.Instance.ShowInfo = $"ScenarioName: {scenario.Name}, StepCount: {scenario.WorkFlows.Count}, CurrentStep: {scenario.CurrentStep}, Message: {nextWF.MessageName}."; switch (nextWF.MessageName) { case "S1F1": scenario.CurrentStep++; Command.S1F1Command(scenario); break; case "S1F13": scenario.CurrentStep++; Command.S1F13Command(scenario); break; case "S1F17": scenario.CurrentStep++; Command.S1F17Command(scenario); break; case "S1F15": scenario.CurrentStep++; Command.S1F15Command(scenario); break; case "S6F23": scenario.CurrentStep++; Command.S6F23Command(scenario); break; case "S5F5": scenario.CurrentStep++; Command.S5F5Command(scenario); break; case "S7F19": scenario.CurrentStep++; Command.S7F19Command(scenario); break; case "S2F13": scenario.CurrentStep++; Command.S2F13Command(scenario); break; case "S2F43": scenario.CurrentStep++; Command.S2F43Command(nextWF.MessageContent.FromJson(), scenario); break; case "S2F23": scenario.CurrentStep++; Command.S2F23Command(nextWF.MessageContent.FromJson(), scenario); break; case "S1F3": scenario.CurrentStep++; Command.S1F3Command(scenario); break; case "S2F15": scenario.CurrentStep++; Command.S2F15Command(nextWF.MessageContent.FromJson(), scenario); break; case "S2F15Rcp": scenario.CurrentStep++; Command.S2F15CommandRcp(nextWF.MessageContent.FromJson(), scenario); break; case "S2F31": scenario.CurrentStep++; Command.S2F31Command(nextWF.MessageContent.FromJson(), scenario); break; case "S2F33": scenario.CurrentStep++; Command.S2F33Command(nextWF.MessageContent.FromJson(), scenario); break; case "S2F35": scenario.CurrentStep++; Command.S2F35Command(nextWF.MessageContent.FromJson(), scenario); break; case "S2F37": scenario.CurrentStep++; Command.S2F37Command(nextWF.MessageContent.FromJson(), scenario); break; case "S2F41": scenario.CurrentStep++; Command.S2F41Command(nextWF.MessageContent.FromJson(), scenario); break; case "S5F3": scenario.CurrentStep++; Command.S5F3Command(nextWF.MessageContent.FromJson(), scenario); break; case "S7F1": scenario.CurrentStep++; Command.S7F1Command(nextWF.MessageContent.FromJson(), scenario); break; case "S7F3": scenario.CurrentStep++; Command.S7F3Command(nextWF.MessageContent.FromJson(), scenario); break; case "S7F5": scenario.CurrentStep++; Command.S7F5Command(nextWF.MessageContent.FromJson(), scenario); break; case "S7F17": scenario.CurrentStep++; Command.S7F17Command(nextWF.MessageContent.FromJson(), scenario); break; } } } [Serializable] public class ScenarioCollection { public List Scenarios { get; set; } public ScenarioCollection() => Scenarios = new List(); } [Serializable] public class Scenario { [XmlAttribute] public string Name { get; set; } [JsonIgnore] [XmlIgnore] public int CurrentStep { get; set; } [XmlElement] public List WorkFlows { get; set; } public Scenario() { WorkFlows = new List(); } } [Serializable] public class WorkFlow { [XmlAttribute] public int Step { get; set; } public string MessageName { get; set; } public string MessageContent { get; set; } } }