Пример #1
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);
        }
Пример #2
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));
        }
Пример #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)
        {
            var cs = RailwayState.SelectCommandStation(Entity);

            if (cs == null)
            {
                return(false);
            }
            this.statePersistence = statePersistence;
            cs.AddLoc(this);
            commandStation = cs;
            return(true);
        }
Пример #4
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 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);
        }