StateService.cs 1019 B

1234567891011121314151617181920212223242526272829
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using StatementMachineService.Service;
  5. namespace StatementMachineService.Core
  6. {
  7. public class StateService : IStateService
  8. {
  9. private readonly Dictionary<int, SignalStateService> _services=new Dictionary<int, SignalStateService>();
  10. public void CreateMachine(int id, StateEventHandler upAsyncCallback, StateEventHandler downAsyncCallback)
  11. {
  12. var signalStateService=new SignalStateService();
  13. signalStateService.DownExecuteEvent += downAsyncCallback;
  14. signalStateService.UpExecuteEvent += upAsyncCallback;
  15. signalStateService.CreateService(id);
  16. _services.Add(id, signalStateService);
  17. }
  18. public void ExecuteState(int id,ushort state)
  19. {
  20. if( !_services.Keys.Contains(id))
  21. throw new Exception("未定义信号");
  22. var signal = _services[id];
  23. signal.ExecuteSate(state);
  24. }
  25. }
  26. }