/// <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; }
/// <summary> /// Detect power off /// </summary> public override bool Visit(GlobalPowerOff msg, Client data) { data.Reset(); stateDispatcher.PostAction(() => data.cs.Power.Actual = false); return(true); }
/// <summary> /// Detect power off /// </summary> public override bool Visit(GlobalPowerOff msg, Master data) { stateDispatcher.PostAction(() => data.cs.Power.Actual = false); return(true); }