Example #1
0
        /// <summary>
        /// Parses a SqlDataReader object into a location object
        /// </summary>
        /// <param name="DataReader"></param>
        private void ParseSqlDataReader(SqlDataReader DataReader)
        {
            //Validate Argument
            ArgumentValidation.ValidateSqlDataReader(DataReader, Globals.UserSettings.GetCultureInfo());

            this._ID          = DataReader.GetInt32(DataReader.GetOrdinal("id"));
            this._SimID       = DataReader.GetInt16(DataReader.GetOrdinal("sim_id"));
            this._Name        = DataReader.GetString(DataReader.GetOrdinal("name"));
            this.TIPLOC       = DataReader.GetNullableString("tiploc");
            this.SimSigCode   = DataReader.GetString(DataReader.GetOrdinal("simsig_code"));
            this.EntryPoint   = DataReader.GetBoolean(DataReader.GetOrdinal("simsig_entry_point"));
            this.LocationType = (SimSigLocationType)SqlDataReaderExtensions.GetNullableByte(DataReader, "location_type_id");
        }
Example #2
0
        /// <summary>
        /// Instantiates a new Location object from the supplied arguements
        /// </summary>
        /// <param name="Simulation">The location to which the location belongs</param>
        /// <param name="Name">The location name</param>
        /// <param name="TIPLOC">The TIPLOC code for the location.</param>
        /// <param name="SimSigCode">The SimSig code for the location.</param>
        /// <param name="EntryPoint">Indicates whether the location is an entry point for the location</param>
        /// <param name="LocationType">Indicates the type of location</param>
        /// <param name="SQLConnector">The GFSqlConnector to the GroundFrame.SQL database</param>
        public Location(Simulation Simulation, string Name, string TIPLOC, string SimSigCode, bool EntryPoint, SimSigLocationType LocationType, GFSqlConnector SQLConnector)
        {
            CultureInfo Culture = Globals.UserSettings.GetCultureInfo();

            //Check Arguments
            ArgumentValidation.ValidateName(Name, Culture);
            ArgumentValidation.ValidateSimSigCode(SimSigCode, Culture, 16);
            ArgumentValidation.ValidateSQLConnector(SQLConnector, Culture);
            ArgumentValidation.ValidateSimulation(Simulation, Culture);

            if (Simulation.ID == 0)
            {
                throw new ArgumentException(ExceptionHelper.GetStaticException("CreateLocationUnsavedSimError", null, Culture));
            }

            this._ID           = 0;
            this._SimID        = Simulation.ID;
            this._Name         = Name;
            this.SimSigCode    = SimSigCode;
            this._SQLConnector = new GFSqlConnector(SQLConnector); //Instantiates a new copy of the SQLConnector object to stop conflicts between Connections, Commands and Readers
            this.TIPLOC        = TIPLOC;
            this.EntryPoint    = EntryPoint;
            this.LocationType  = LocationType;
        }
Example #3
0
        public void LocationNode_Constructor_ByProperties_SimSigCode(string Platform, string Electrification, SimSigLocationType LocationType, int?Length, bool FreightOnly, string Line, string Path)
        {
            Length TestLength = null;

            if (Length != null)
            {
                TestLength = new Length(Convert.ToInt32(Length));
            }

            Core.SimSig.LocationNode TestLocationNode = new Core.SimSig.LocationNode(this._TestSimulation.ID, this._TestLocation.SimSigCode, this._TestSimulation.GetSimulationEras().Find(x => x.Type == EraType.Template).ID, this._TestVersion, Platform, new Core.Electrification(Electrification), LocationType, TestLength, FreightOnly, Line, Path, this._SQLConnection);
            Assert.Equal(LocationType, TestLocationNode.LocationType);
            Assert.Equal(Platform, TestLocationNode.Platform);
            Assert.Equal(Line, TestLocationNode.Line);
            Assert.Equal(Path, TestLocationNode.Path);
            Assert.Equal(this._TestLocation.SimSigCode, TestLocationNode.LocationSimSigCode);
            Assert.Equal(this._TestLocation.ID, TestLocationNode.LocationID);

            if (Length == null)
            {
                Assert.Null(TestLocationNode.Length);
            }
            else
            {
                Assert.Equal(TestLength.Meters, TestLocationNode.Length.Meters);
            }

            Assert.Equal(FreightOnly, TestLocationNode.FreightOnly);
            Assert.Equal(new Electrification(Electrification).BitWise, TestLocationNode.Electrification.BitWise);
            Assert.Equal(0, TestLocationNode.ID);
        }
Example #4
0
        public void LocationNode_Constructor_GroundFrameDBID(string Platform, string Electrification, SimSigLocationType LocationType, int?Length, bool FreightOnly, string Line, string Path)
        {
            Length TestLength = null;

            if (Length != null)
            {
                TestLength = new Length(Convert.ToInt32(Length));
            }

            SimulationEra SimEra = this._TestSimulation.GetSimulationEras().Find(x => x.Type == EraType.Template);

            Core.Electrification     ElecObject       = new Core.Electrification(Electrification);
            Core.SimSig.LocationNode TestLocationNode = new Core.SimSig.LocationNode(this._TestSimulation.ID, this._TestLocation.SimSigCode, SimEra.ID, this._TestVersion, Platform, ElecObject, LocationType, TestLength, FreightOnly, Line, Path, this._SQLConnection);
            TestLocationNode.SaveToSQLDB();
            Assert.Equal(LocationType, TestLocationNode.LocationType);
            Assert.Equal(Platform, TestLocationNode.Platform);
            Assert.Equal(Line, TestLocationNode.Line);
            Assert.Equal(Path, TestLocationNode.Path);
            Assert.Equal(this._TestLocation.SimSigCode, TestLocationNode.LocationSimSigCode);
            Assert.Equal(this._TestLocation.ID, TestLocationNode.LocationID);

            if (Length == null)
            {
                Assert.Null(TestLocationNode.Length);
            }
            else
            {
                Assert.Equal(TestLength.Meters, TestLocationNode.Length.Meters);
            }

            Assert.Equal(FreightOnly, TestLocationNode.FreightOnly);
            Assert.Equal(new Electrification(Electrification).BitWise, TestLocationNode.Electrification.BitWise);
            Assert.NotEqual(0, TestLocationNode.ID);

            //Load the LocationNode into a new object and compare
            Core.SimSig.LocationNode TestLoadLocationNode = new Core.SimSig.LocationNode(TestLocationNode.ID, this._SQLConnection, true);

            Assert.Equal(TestLocationNode.LocationType, TestLoadLocationNode.LocationType);
            Assert.Equal(TestLocationNode.Platform, TestLoadLocationNode.Platform);
            Assert.Equal(TestLocationNode.Line, TestLoadLocationNode.Line);
            Assert.Equal(TestLocationNode.Path, TestLoadLocationNode.Path);
            Assert.Equal(TestLocationNode.LocationSimSigCode, TestLoadLocationNode.LocationSimSigCode);
            Assert.Equal(TestLocationNode.LocationID, TestLoadLocationNode.LocationID);

            if (TestLocationNode.Length == null)
            {
                Assert.Null(TestLoadLocationNode.Length);
            }
            else
            {
                Assert.Equal(TestLocationNode.Length.Meters, TestLoadLocationNode.Length.Meters);
            }

            Assert.Equal(TestLocationNode.FreightOnly, TestLoadLocationNode.FreightOnly);
            Assert.Equal(TestLocationNode.Electrification.BitWise, TestLoadLocationNode.Electrification.BitWise);
            Assert.Equal(TestLocationNode.ID, TestLoadLocationNode.ID);
        }
Example #5
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="LocationSimSigCode">The SimSig location code 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, string LocationSimSigCode, 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
            using SimulationExtension LocNodeSimulation = new SimulationExtension(this.SimID, this._SQLConnector);

            //Validate locations and eras
            if (LocNodeSimulation.Locations.Any(x => x.SimSigCode == LocationSimSigCode) == 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._LocationSimSigCode = LocationSimSigCode;
            this._LocationID         = LocNodeSimulation.Locations.Find(x => x.SimSigCode == this._LocationSimSigCode).ID;
            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;
        }