dc/Common/Scenario.cs
13118993771@163.com 5e9d0f1e2d EAP
2022-04-01 17:03:54 +08:00

93 wiersze
4.7 KiB
C#

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<S2F43Item>(), scenario); break;
case "S2F23": scenario.CurrentStep++; Command.S2F23Command(nextWF.MessageContent.FromJson<S2F23Item>(), scenario); break;
case "S1F3": scenario.CurrentStep++; Command.S1F3Command(scenario); break;
case "S2F15": scenario.CurrentStep++; Command.S2F15Command(nextWF.MessageContent.FromJson<S2F15Item>(), scenario); break;
case "S2F15Rcp": scenario.CurrentStep++; Command.S2F15CommandRcp(nextWF.MessageContent.FromJson<S2F15Item>(), scenario); break;
case "S2F31": scenario.CurrentStep++; Command.S2F31Command(nextWF.MessageContent.FromJson<S2F31Item>(), scenario); break;
case "S2F33": scenario.CurrentStep++; Command.S2F33Command(nextWF.MessageContent.FromJson<S2F33Item>(), scenario); break;
case "S2F35": scenario.CurrentStep++; Command.S2F35Command(nextWF.MessageContent.FromJson<S2F35Item>(), scenario); break;
case "S2F37": scenario.CurrentStep++; Command.S2F37Command(nextWF.MessageContent.FromJson<S2F37Item>(), scenario); break;
case "S2F41": scenario.CurrentStep++; Command.S2F41Command(nextWF.MessageContent.FromJson<S2F41Item>(), scenario); break;
case "S5F3": scenario.CurrentStep++; Command.S5F3Command(nextWF.MessageContent.FromJson<S5F3Item>(), scenario); break;
case "S7F1": scenario.CurrentStep++; Command.S7F1Command(nextWF.MessageContent.FromJson<S7F1Item>(), scenario); break;
case "S7F3": scenario.CurrentStep++; Command.S7F3Command(nextWF.MessageContent.FromJson<S7F3Item>(), scenario); break;
case "S7F5": scenario.CurrentStep++; Command.S7F5Command(nextWF.MessageContent.FromJson<S7F5Item>(), scenario); break;
case "S7F17": scenario.CurrentStep++; Command.S7F17Command(nextWF.MessageContent.FromJson<S7F17Item>(), scenario); break;
}
}
}
[Serializable]
public class ScenarioCollection
{
public List<Scenario> Scenarios { get; set; }
public ScenarioCollection() => Scenarios = new List<Scenario>();
}
[Serializable]
public class Scenario
{
[XmlAttribute]
public string Name { get; set; }
[JsonIgnore]
[XmlIgnore]
public int CurrentStep { get; set; }
[XmlElement]
public List<WorkFlow> WorkFlows { get; set; }
public Scenario()
{
WorkFlows = new List<WorkFlow>();
}
}
[Serializable]
public class WorkFlow
{
[XmlAttribute]
public int Step { get; set; }
public string MessageName { get; set; }
public string MessageContent { get; set; }
}
}