1234567891011121314151617181920212223242526272829 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using StatementMachineService.Service;
- namespace StatementMachineService.Core
- {
- public class StateService : IStateService
- {
- private readonly Dictionary<int, SignalStateService> _services=new Dictionary<int, SignalStateService>();
- 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);
- }
-
- }
- }
|