using System; using System.Collections.Generic; using System.Linq; using StatementMachineService.Service; namespace StatementMachineService.Core { public class StateService : IStateService { private readonly Dictionary _services=new Dictionary(); public void CreateMachine(int id, StateEventHandler upAsyncCallback, StateEventHandler downAsyncCallback) { var signalStateService=new SignalStateService(); signalStateService.DownExecuteEvent += downAsyncCallback; signalStateService.UpExecuteEvent += upAsyncCallback; signalStateService.CreateService(id); _services.Add(id, signalStateService); } public void ExecuteState(int id,ushort state) { if( !_services.Keys.Contains(id)) throw new Exception("未定义信号"); var signal = _services[id]; signal.ExecuteSate(state); } } }