Beispiel #1
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public LocState(ILoc entity, RailwayState railwayState)
     : base(entity, railwayState)
 {
     address = entity.Address;
     controlledAutomatically = new StateProperty <bool>(this, false, ValidateControlledAutomatically, null, OnControlledAutomaticallyChanged);
     automaticState          = new ActualStateProperty <AutoLocState>(this, AutoLocState.AssignRoute, null, OnAutomaticStateChanged);
     possibleDeadlock        = new ActualStateProperty <bool>(this, false, null, null);
     currentRoute            = new ActualStateProperty <IRouteStateForLoc>(this, null, null, null);
     waitAfterCurrentRoute   = new ActualStateProperty <bool>(this, false, null, null);
     nextRoute    = new ActualStateProperty <IRouteState>(this, null, null, null);
     currentBlock = new ActualStateProperty <IBlockState>(this, null, ValidateCurrentBlock, x => {
         recentlyVisitedBlocks.Insert(x);
         SaveCurrentBlock();
     });
     currentBlockEnterSide           = new ActualStateProperty <BlockSide>(this, BlockSide.Back, null, x => SaveCurrentBlock());
     startNextRouteTime              = new ActualStateProperty <DateTime>(this, DateTime.Now, null, null);
     durationExceedsCurrentRouteTime = new ActualStateProperty <DateTime>(this, DateTime.MaxValue, null, null);
     speedInSteps   = new StateProperty <int>(this, 0, LimitSpeedSteps, OnRequestedSpeedStepsChanged, null);
     speed          = new SpeedProperty(this);
     direction      = new StateProperty <LocDirection>(this, LocDirection.Forward, null, OnRequestedDirectionChanged, x => SaveCurrentBlock());
     reversing      = new ActualStateProperty <bool>(this, false, ValidateReversing, null);
     f0             = new StateProperty <bool>(this, true, null, OnRequestedFunctionChanged, null);
     functionStates = new Dictionary <LocFunction, IStateProperty <bool> >();
     foreach (var lf in entity.Functions)
     {
         var f = new StateProperty <bool>(this, false, null, OnRequestedFunctionChanged, null);
         functionStates[lf.Function] = f;
     }
     lastRouteOptions = new ActualStateProperty <IRouteOption[]>(this, null, null, null);
 }
 /// <summary>
 /// Default ctor
 /// </summary>
 public SwitchState(ISwitch entity, RailwayState railwayState)
     : base(entity, railwayState)
 {
     address         = entity.Address;
     feedbackAddress = entity.HasFeedback ? (entity.FeedbackAddress ?? entity.Address) : null;
     direction       = new StateProperty <SwitchDirection>(this, SwitchDirection.Straight, null, OnRequestedDirectionChanged, null);
 }
Beispiel #3
0
        /// <summary>
        /// Prepare this state for use in a live railway.
        /// Make sure all relevant connections to other state objects are resolved.
        /// </summary>
        /// <returns>True if the entity is now ready for use in a live railway, false otherwise.</returns>
        protected override bool TryPrepareForUse(IStateUserInterface ui, IStatePersistence statePersistence)
        {
            // Resolve command station
            var cs = RailwayState.SelectCommandStation(Entity);

            if (cs == null)
            {
                return(false);
            }
            cs.AddInput(this);

            // Resolve destination blocks
            var routes = RailwayState.RouteStates.Where(x => x.Contains(this));

            destinationBlocks = routes.Select(x => x.To).ToList();
            if (Entity.Block != null)
            {
                var blockState = RailwayState.BlockStates[Entity.Block];
                if ((blockState != null) && (!destinationBlocks.Contains(blockState)))
                {
                    destinationBlocks.Add(blockState);
                }
            }

            return(true);
        }
Beispiel #4
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public Clock4StageOutputState(IClock4StageOutput output, RailwayState railwayState)
     : base(output, railwayState)
 {
     address1 = output.Address1;
     address2 = output.Address2;
     period   = new StateProperty <Clock4Stage>(this, Clock4Stage.Morning, null, OnPeriodRequestedValueChanged, null);
     pattern  = new StateProperty <int>(this, DefaultValues.DefaultClock4StageOutputMorningPattern, null, OnPatternRequestedChanged, OnPatternActualChanged);
 }
 /// <summary>
 /// Default ctor
 /// </summary>
 public BlockSignalState(IBlockSignal entity, RailwayState railwayState)
     : base(entity, railwayState)
 {
     address1 = entity.Address1;
     address2 = (address1 != null) ? entity.Address2: null;
     address3 = (address2 != null) ? entity.Address3 : null;
     address4 = (address3 != null) ? entity.Address4 : null;
     color    = new StateProperty <BlockSignalColor>(this, BlockSignalColor.Red, ValidateColor, OnRequestedColorChanged, null);
 }
 /// <summary>
 /// Default ctor
 /// </summary>
 public EntityStateSet(IEnumerable <TEntity> entities, RailwayState railwayState)
 {
     foreach (var entity in entities)
     {
         var state = entity.Accept(Default <StateBuilder> .Instance, railwayState);
         entries.Add(entity, (TInternalState)state);
     }
     list = entries.Values.OrderBy(x => x.Description).ToList();
 }
Beispiel #7
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public RouteState(IRoute[] routes, RailwayState railwayState)
     : base(routes[0], railwayState)
 {
     this.routes = routes;
     permissions = new LocRoutePermissionsState(routes, railwayState);
     closed      = routes.Any(x => x.Closed);
     events      = routes.Last().Events.Select(x => new RouteEventState(x, railwayState)).ToList();
     enteringDestinationTrigger = new ActionTriggerState(routes[routes.Length - 1].EnteringDestinationTrigger, railwayState);
     destinationReachedTrigger  = new ActionTriggerState(routes[routes.Length - 1].DestinationReachedTrigger, railwayState);
 }
Beispiel #8
0
        /// <summary>
        /// Select the command station to use for this state.
        /// </summary>
        protected virtual CommandStationState SelectCommandStation()
        {
            var aEntity = Entity as IAddressEntity;

            if (aEntity == null)
            {
                throw new NotSupportedException("Entity must have an address");
            }
            return(RailwayState.SelectCommandStation(aEntity));
        }
Beispiel #9
0
 /// <summary>
 /// Default ctor
 /// </summary>
 protected CommandStationState(ICommandStation entity, RailwayState railwayState, string[] addressSpaces)
     : base(entity, railwayState)
 {
     Log                = LogManager.GetLogger(LogNames.CommandStationPrefix + entity.Description);
     myWorker           = new AsynchronousWorker("csworker-" + entity.Description);
     this.addressSpaces = addressSpaces ?? Empty <string> .Array;
     power              = new StateProperty <bool>(this, false, null,
                                                   x => PostWorkerAction(() => OnRequestedPowerChanged(x)),
                                                   OnActualPowerChanged, false);
     myWorker.Wait += OnWorkerWait;
 }
Beispiel #10
0
        /// <summary>
        /// Prepare this state for use in a live railway.
        /// Make sure all relevant connections to other state objects are resolved.
        /// </summary>
        /// <returns>True if the entity is now ready for use in a live railway, false otherwise.</returns>
        protected override bool TryPrepareForUse(IStateUserInterface ui, IStatePersistence statePersistence)
        {
            var cs = RailwayState.SelectCommandStation(Entity);

            if (cs == null)
            {
                return(false);
            }
            this.statePersistence = statePersistence;
            cs.AddLoc(this);
            commandStation = cs;
            return(true);
        }
Beispiel #11
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public TurnTableState(ITurnTable entity, RailwayState railwayState)
     : base(entity, railwayState)
 {
     positionAddress1 = entity.PositionAddress1;
     positionAddress2 = (positionAddress1 != null) ? entity.PositionAddress2 : null;
     positionAddress3 = (positionAddress2 != null) ? entity.PositionAddress3 : null;
     positionAddress4 = (positionAddress3 != null) ? entity.PositionAddress4 : null;
     positionAddress5 = (positionAddress4 != null) ? entity.PositionAddress5 : null;
     positionAddress6 = (positionAddress5 != null) ? entity.PositionAddress6 : null;
     invertPositions  = entity.InvertPositions;
     writeAddress     = entity.WriteAddress;
     invertWrite      = entity.InvertWrite;
     busyAddress      = entity.BusyAddress;
     invertBusy       = entity.InvertBusy;
     firstPosition    = entity.FirstPosition;
     lastPosition     = entity.LastPosition;
     initialPosition  = entity.InitialPosition;
     position         = new StateProperty <int>(this, -1, null, OnRequestedPositionChanged, null);
     busyInput        = new BusyInput(this);
 }
        /// <summary>
        /// Prepare this state for use in a live railway.
        /// Make sure all relevant connections to other state objects are resolved.
        /// </summary>
        /// <returns>True if the entity is now ready for use in a live railway, false otherwise.</returns>
        protected override bool TryPrepareForUse(IStateUserInterface ui, IStatePersistence statePersistence)
        {
            // Resolve block.
            var entity = Entity;

            block = (entity.Block != null) ? RailwayState.BlockStates[entity.Block] : null;
            if (block == null)
            {
                return(false);
            }

            // Resolve command station
            var cs = RailwayState.SelectCommandStation(Entity);

            if (cs == null)
            {
                return(false);
            }

            commandStation = cs;
            commandStation.AddSignal(this);
            return(true);
        }
Beispiel #13
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public RouteEventState(IRouteEvent @event, RailwayState railwayState)
     : base(@event, railwayState)
 {
     behaviors = @event.Behaviors.Select(x => new RouteEventBehaviorState(x, railwayState)).ToList();
 }
Beispiel #14
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public RouteState(IRoute route, RailwayState railwayState)
     : this(new[] { route }, railwayState)
 {
 }
Beispiel #15
0
 /// <summary>
 /// Default ctor
 /// </summary>
 protected SensorState(ISensor entity, RailwayState railwayState)
     : base(entity, railwayState)
 {
     address = entity.Address;
     active  = new ActualStateProperty <bool>(this, false, null, OnActiveChanged);
 }
Beispiel #16
0
 /// <summary>
 /// Default ctor
 /// </summary>
 protected EntityState(RailwayState railwayState)
 {
     this.railwayState = railwayState;
 }
Beispiel #17
0
 /// <summary>
 /// Default ctor
 /// </summary>
 internal ActionTriggerState(IActionTrigger entity, RailwayState railwayState)
     : base(railwayState)
 {
     actions = entity.Select(x => x.Accept(Default <StateBuilder> .Instance, railwayState)).Cast <IActionState>().ToList();
 }
Beispiel #18
0
 /// <summary>
 /// Build a action state from the given action.
 /// </summary>
 internal static ActionState Build(IAction action, RailwayState railwayState)
 {
     return((ActionState)action.Accept(Default <StateBuilder> .Instance, railwayState));
 }
 /// <summary>
 /// Default ctor
 /// </summary>
 public BlockGroupState(IBlockGroup blockGroup, RailwayState railwayState)
     : base(blockGroup, railwayState)
 {
 }
Beispiel #20
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public RouteEventBehaviorState(IRouteEventBehavior behavior, RailwayState railwayState)
     : base(behavior, railwayState)
 {
     appliesTo = new LocPredicateState(behavior.AppliesTo, railwayState);
 }
Beispiel #21
0
 /// <summary>
 /// Default ctor
 /// </summary>
 protected ActionState(IAction entity, RailwayState railwayState)
     : base(entity, railwayState)
 {
 }
Beispiel #22
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public BinarySensorState(IBinarySensor sensor, RailwayState railwayState)
     : base(sensor, railwayState)
 {
     activateTrigger   = new ActionTriggerState(sensor.ActivateTrigger, railwayState);
     deActivateTrigger = new ActionTriggerState(sensor.DeActivateTrigger, railwayState);
 }
 /// <summary>
 /// Default ctor
 /// </summary>
 public LocFunctionActionState(ILocFunctionAction entity, RailwayState railwayState)
     : base(entity, railwayState)
 {
 }
Beispiel #24
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public PowerProperty(RailwayState owner)
 {
     this.owner = owner;
 }
 /// <summary>
 /// Default ctor
 /// </summary>
 public BinaryOutputState(IBinaryOutput output, RailwayState railwayState)
     : base(output, railwayState)
 {
     active = new StateProperty <bool>(this, false, null, OnActiveRequestedChanged, OnActiveActualChanged);
 }
 /// <summary>
 /// Default ctor
 /// </summary>
 public LocPredicateState(ILocPredicate entity, RailwayState railwayState)
     : base(entity, railwayState)
 {
 }
Beispiel #27
0
 /// <summary>
 /// Default ctor
 /// </summary>
 internal LocRoutePermissionsState(IEnumerable <IRoute> routes, RailwayState railwayState)
     : base(null, railwayState)
 {
     predicates = routes.Where(r => !r.Permissions.IsEmpty).Select(r => new LocPredicateState(r.Permissions, railwayState)).ToList();
 }
 /// <summary>
 /// Default ctor
 /// </summary>
 protected LocActionState(T entity, RailwayState railwayState)
     : base(entity, railwayState)
 {
 }
Beispiel #29
0
 /// <summary>
 /// Default ctor
 /// </summary>
 protected LockableState(T entity, RailwayState railwayState)
     : base(entity, railwayState)
 {
 }
Beispiel #30
0
 /// <summary>
 /// Default ctor
 /// </summary>
 protected JunctionState(IJunction junction, RailwayState railwayState)
     : base(junction, railwayState)
 {
 }