Beispiel #1
0
 protected virtual void AddDispatcher(
     Type stateType,
     IStateDispatcher <TMachineState, TMachineEvent> dispatcher)
 {
     this.dispatch.AddEntry(new SimpleDispatchEntry <IStateDispatcher <TMachineState, TMachineEvent> >(
                                stateType,
                                dispatcher));
 }
Beispiel #2
0
 private void AddDispatcher(
     Type stateType,
     IStateDispatcher <TMachineState, TMachineEvent, TGeneratedEvent> dispatcher)
 {
     this.dispatch.AddEntry(new SimpleDispatchEntry <IStateDispatcher <TMachineState, TMachineEvent, TGeneratedEvent> >(
                                stateType,
                                dispatcher));
 }
Beispiel #3
0
        /// <summary>
        /// Default ctor
        /// </summary>
        public HeartBeat(AutomaticLocController automaticLocController, IStateDispatcher dispatcher)
        {
            this.automaticLocController = automaticLocController;
            this.dispatcher             = dispatcher;

            var thread = new Thread(Run);

            thread.Name = "heartbeat";
            thread.Start();
        }
Beispiel #4
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public Client(LocoBuffer lb, RailwayState railwayState, ICommandStationState cs, IStateDispatcher stateDispatcher, Logger log)
 {
     if (lb == null)
     {
         throw new ArgumentNullException("lb");
     }
     if (cs == null)
     {
         throw new ArgumentNullException("cs");
     }
     if (stateDispatcher == null)
     {
         throw new ArgumentNullException("stateDispatcher");
     }
     this.railwayState    = railwayState;
     this.lb              = lb;
     this.log             = log;
     this.stateDispatcher = stateDispatcher;
     this.cs              = cs;
     StartIdleDetection();
 }
Beispiel #5
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public Master(LocoBuffer lb, RailwayState railwayState, ICommandStationState cs, IStateDispatcher stateDispatcher, Logger log)
 {
     if (lb == null)
     {
         throw new ArgumentNullException("lb");
     }
     if (cs == null)
     {
         throw new ArgumentNullException("cs");
     }
     if (stateDispatcher == null)
     {
         throw new ArgumentNullException("stateDispatcher");
     }
     this.railwayState    = railwayState;
     this.lb              = lb;
     this.log             = log;
     this.stateDispatcher = stateDispatcher;
     this.cs              = cs;
     slotTable            = new SlotTable(cs);
 }
Beispiel #6
0
        /// <summary>
        /// Default ctor
        /// </summary>
        public RailwayState(IRailway railway, bool runInVirtualMode)
            : base(railway, null)
        {
            // Setup fields
            dispatcher  = new StateDispatcher();
            virtualMode = new VirtualMode(runInVirtualMode, this);
            clock       = new Clock(this);

            // Resolve single entities
            commandStationStates = new EntityStateSet <CommandStationState, ICommandStationState, ICommandStation>(ResolveCommandStations(railway, runInVirtualMode), this);
            locStates            = new EntityStateSet <LocState, ILocState, ILoc>(ResolveLocs(railway), this);

            // Resolve modules
            var modules = ResolveModules(railway).ToList();

            blockStates      = new EntityStateSet <BlockState, IBlockState, IBlock>(modules.SelectMany(x => x.Blocks), this);
            blockGroupStates = new EntityStateSet <BlockGroupState, IBlockGroupState, IBlockGroup>(modules.SelectMany(x => x.BlockGroups), this);
            junctionStates   = new EntityStateSet <JunctionState, IJunctionState, IJunction>(modules.SelectMany(x => x.Junctions), this);
            sensorStates     = new EntityStateSet <SensorState, ISensorState, ISensor>(modules.SelectMany(x => x.Sensors), this);
            signalStates     = new EntityStateSet <SignalState, ISignalState, ISignal>(modules.SelectMany(x => x.Signals), this);
            outputStates     = new EntityStateSet <OutputState, IOutputState, IOutput>(modules.SelectMany(x => x.Outputs), this);

            // Build routes
            var internalRouteStates    = modules.SelectMany(x => x.Routes).Where(x => x.IsInternal()).Select(x => new RouteState(x, this)).ToList();
            var interModuleRouteStates = ResolveInterModuleRoutes(railway, modules).ToList();

            routeStates = new EntityStateList <RouteState, IRouteState, IRoute>(internalRouteStates.Concat(interModuleRouteStates.Cast <RouteState>()));

            // Setup properties
            power = new PowerProperty(this);
            automaticLocController = new AutomaticLocController(this);

            // Catch unhandled exception, so we can stop when they occur
            AppDomain.CurrentDomain.UnhandledException += OnCurrentDomainUnhandledException;

            // Connect to property changes
            onPropertyChanged        = (s, x) => dispatcher.PostAction(OnModelChanged);
            railway.PropertyChanged += onPropertyChanged;
        }
Beispiel #7
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public Visitor(IStateDispatcher stateDispatcher)
 {
     this.stateDispatcher = stateDispatcher;
 }