Ejemplo n.º 1
0
        /// <summary>
        /// Creates the mapped location in the Target Simulation
        /// </summary>
        /// <param name="SQLConnector">The target simulation where the location should be created</param>
        /// <param name="TargetSimulation">A GFSqlConnector object connected to the GroundFrame.SQL database</param>
        /// <param name="Version">The version under which the location node was created</param>
        /// <param name="SimEra">The era for which the location node is valid</param>
        /// <param name="Location">The location against which the location node will be created</param>
        public void CreateLocationNode(ref SimSig.SimulationExtension TargetSimulation, GFSqlConnector SQLConnector, SimSig.Location Location, SimSig.Version Version, SimSig.SimulationEra SimEra)
        {
            //Validate Arguments
            ArgumentValidation.ValidateSQLConnector(SQLConnector, Globals.UserSettings.GetCultureInfo());
            ArgumentValidation.ValidateSimulation(TargetSimulation, Globals.UserSettings.GetCultureInfo());
            ArgumentValidation.ValidateVersion(Version, Globals.UserSettings.GetCultureInfo());
            ArgumentValidation.ValidateLocation(Location, Globals.UserSettings.GetCultureInfo());
            ArgumentValidation.ValidateSimEra(SimEra, Globals.UserSettings.GetCultureInfo());

            //Default Value
            Electrification DefaultElectrification = new Electrification("D");

            //Instantiate Location Node
            SimSig.LocationNode NewLocationNode = new SimSig.LocationNode(TargetSimulation.ID, Location.ID, SimEra.ID, Version, this.Platform, DefaultElectrification, SimSig.SimSigLocationType.Unknown, null, false, this.Line, this.Path, SQLConnector);

            if (TargetSimulation.LocationNodes.Exists(NewLocationNode) == false)
            {
                //Save to GroundFrame.SQL database
                NewLocationNode.SaveToSQLDB();
                //Add location node to MapperLocationNode
                this._LocationNode = NewLocationNode;
                //Add location to the simulation
                TargetSimulation.LocationNodes.Add(NewLocationNode);
            }

            //Dispose
            NewLocationNode.Dispose();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Instantiates a new Location node object from the supplied arguments
        /// </summary>
        /// <param name="SimulationID">The GroundFrame.SQL database id of the simulation</param>
        /// <param name="LocationID">The GroundFrame.SQL database id of the location</param>
        /// <param name="EraID">The GroundFrame.SQL database id of the simulation era</param>
        /// <param name="Version">The version of SimSig this created under</param>
        /// <param name="Platform">The platform</param>
        /// <param name="Electrification">The valid electrification options for this location node</param>
        /// <param name="LocationType">The location type of for this location node</param>
        /// <param name="Length">A length object representing the length for this location node</param>
        /// <param name="FreightOnly">Flag to indicate whether the location is freight only</param>
        /// <param name="Line">The line code</param>
        /// <param name="Path">The path code</param>
        /// <param name="SQLConnector">The GFSqlConnector to the GroundFrame.SQL database</param>
        public LocationNode(int SimulationID, int LocationID, int EraID, Version Version, string Platform, Electrification Electrification, SimSigLocationType LocationType, Length Length, bool FreightOnly, string Line, string Path, GFSqlConnector SQLConnector)
        {
            CultureInfo Culture = Globals.UserSettings.GetCultureInfo();

            //Check Arguments
            ArgumentValidation.ValidateSQLConnector(SQLConnector, Culture);
            this._SQLConnector = new GFSqlConnector(SQLConnector);
            ArgumentValidation.ValidateVersion(Version, Culture);


            if (SimulationID == 0)
            {
                throw new ArgumentException(ExceptionHelper.GetStaticException("CreateLocationNodeUnsavedSimError", null, Culture));
            }

            this._SimID = SimulationID;
            //Load simulation into a SimSig Simulation object
            //TODO: Find a way of not loading the extension data from the Database. This is silly.
            using SimulationExtension LocNodeSimulation = new SimulationExtension(this.SimID, this._SQLConnector);

            //Validate locations and eras
            if (LocNodeSimulation.Locations.Any(x => x.ID == LocationID) == false)
            {
                throw new ArgumentException(ExceptionHelper.GetStaticException("CreateLocationNodeInvalidLocationError", null, Culture));
            }

            if (LocNodeSimulation.GetSimulationEras().Any(x => x.ID == EraID) == false)
            {
                throw new ArgumentException(ExceptionHelper.GetStaticException("CreateLocationNodeInvalidSimEraError", null, Culture));
            }

            //Set Properties

            this._LocationID         = LocationID;
            this._LocationSimSigCode = LocNodeSimulation.Locations.Find(x => x.ID == this._LocationID).SimSigCode;
            this._EraID          = EraID;
            this._Version        = Version;
            this.Platform        = Platform;
            this.Electrification = Electrification;
            this.LocationType    = LocationType;
            this.Length          = Length;
            this.FreightOnly     = FreightOnly;
            this.Line            = Line;
            this.Path            = Path;
        }