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); }
/// <summary> /// Validates the Simulation Era argument /// </summary> /// <param name="SimEra">The Simualation Era object to validate</param> /// <param name="Culture">The culture in which any exception messages should be thrown</param> internal static void ValidateSimEra(SimulationEra SimEra, CultureInfo Culture) { ResourceManager ExceptionMessageResources = new ResourceManager("GroundFrame.Core.Resources.ExceptionResources", Assembly.GetExecutingAssembly()); if (SimEra == null) { throw new ArgumentNullException(ExceptionMessageResources.GetString("InvalidSimEraArgument", Culture)); } }
public async Task <QueuerResponseStatus> Execute() { bool DebugMode = Convert.ToBoolean(this._Config["debugMode"]); //Add process started Response this._Responses.Add(new QueuerResponse(QueuerResponseStatus.Running, "processStarted", null)); //Check user was authenticated at time of queue if (this._Authenticated == false) { this._Responses.Add(new QueuerResponse(QueuerResponseStatus.CompletedWithWarning, "processUserNotAuthenticatedAtQueue", null)); return(QueuerResponseStatus.CompletedWithWarning); } try { //Initialise simulation this._Simulation = new Simulation(this.Config["simName"].ToString(), this.Config["simDescription"] == null ? string.Empty: this.Config["simDescription"].ToString(), this.Config["simWikiLink"] == null ? string.Empty : this.Config["simWikiLink"].ToString(), this.Config["simSimSigCode"].ToString(), this._SQLConnector); //Declare the individual async tasks Task <WTT> SourceWTT = this.LoadTimeTable(); Task <bool> SimulationExists = this.CheckSimulationExists(); //Declare list of all the async tasks List <Task> allTasks = new List <Task> { SourceWTT, SimulationExists }; while (allTasks.Any()) { Task finished = await Task.WhenAny(allTasks).ConfigureAwait(false); if (finished == SourceWTT) { if (DebugMode) { this._Responses.Add(new QueuerResponse(QueuerResponseStatus.DebugMesssage, "Completed build the WTT object from the source WTT file", null)); } #if DEBUG Console.WriteLine($"{DateTime.UtcNow.ToLongTimeString()}:- Completed reading WTT"); #endif this._TimeTable = SourceWTT.Result; } else if (finished == SimulationExists) { if (DebugMode) { this._Responses.Add(new QueuerResponse(QueuerResponseStatus.DebugMesssage, "Completed checking if the simulation already exists inthe GroundFrame.SQL database", null)); } #if DEBUG Console.WriteLine($"{DateTime.UtcNow.ToLongTimeString()}:- Completed checking whether the sim Exists"); #endif } allTasks.Remove(finished); } //Check is simulation already exists in the data. If it does save the simulation to the GroundFrame.SQL database if (SimulationExists.Result == true) { this._Responses.Add(new QueuerResponse(QueuerResponseStatus.CompletedWithWarning, "processSimulationAlreadyExists", null)); #if DEBUG Console.WriteLine($"{DateTime.UtcNow.ToLongTimeString()}:- The simulation already exists so the process is stopped"); #endif return(QueuerResponseStatus.CompletedWithWarning); } else { try { this._Simulation.SaveToSQLDB(); //Now load the Extension version so we can keep track of the nodes this._SimExt = new SimulationExtension(this._Simulation.ID, this._SQLConnector); if (DebugMode) { this._Responses.Add(new QueuerResponse(QueuerResponseStatus.DebugMesssage, $"Simulation saved to the GroundFrame.SQL database. ID = {this._Simulation.ID}.", null)); } #if DEBUG Console.WriteLine($"{DateTime.UtcNow.ToLongTimeString()}:- Simulation saved to GroundFrame.SQL database"); #endif } catch (Exception Ex) { ResourceManager ExceptionMessageResources = new ResourceManager("GroundFrame.Core.Resources.ExceptionResources", Assembly.GetExecutingAssembly()); string ExceptionMessage = ExceptionMessageResources.GetString("QueuerErrorSavingSimulation", Globals.UserSettings.GetCultureInfo()); throw new Exception(ExceptionMessage, Ex); } } //Build the next stage of the task by setting the individual lasts Task <List <MapperLocation> > GetLocationMapperTask = this.GetLocationMapperFromWTT(); //Gets the location mapper list from the WTT Task <List <MapperLocationNode> > GetLocationNodeMapperTask = this.GetLocationNodeMapperFromWTT(); //Gets the location node mapper list from the WTT Task <SimSig.Version> SimVersionTask = this.GetSimSigVersion(); //Gets SimSig version requested from the GroundFrame.SQL database Task <SimSig.SimulationEra> TemplateSimEraTask = this.GetSimTemplateEra(); //Gets the era template for the simulation //Build All List task allTasks = new List <Task> { GetLocationMapperTask, GetLocationNodeMapperTask, SimVersionTask, TemplateSimEraTask }; //Wait for the tasks to finish while (allTasks.Any()) { Task finished = await Task.WhenAny(allTasks).ConfigureAwait(false); if (finished == GetLocationMapperTask) { if (DebugMode) { this._Responses.Add(new QueuerResponse(QueuerResponseStatus.DebugMesssage, "Completed getting the Location Mapper from the source WTT", null)); } #if DEBUG Console.WriteLine($"{DateTime.UtcNow.ToLongTimeString()}:- Completed getting Location Mapper"); #endif _LocationMapper = GetLocationMapperTask.Result; } else if (finished == GetLocationNodeMapperTask) { if (DebugMode) { this._Responses.Add(new QueuerResponse(QueuerResponseStatus.DebugMesssage, "Completed getting the Location Node Mapper from the source WTT", null)); } #if DEBUG Console.WriteLine($"{DateTime.UtcNow.ToLongTimeString()}:- Completed getting Location Node Mapper"); #endif _LocationNodeMapper = GetLocationNodeMapperTask.Result; } else if (finished == SimVersionTask) { if (DebugMode) { this._Responses.Add(new QueuerResponse(QueuerResponseStatus.DebugMesssage, "Completed getting the Simulation version from the GroundFrame.SQL database", null)); } #if DEBUG Console.WriteLine($"{DateTime.UtcNow.ToLongTimeString()}:- Completed getting SimSig version"); #endif _Version = SimVersionTask.Result; } else if (finished == TemplateSimEraTask) { if (DebugMode) { this._Responses.Add(new QueuerResponse(QueuerResponseStatus.DebugMesssage, "Completed getting the Simulation template era from the GroundFrame.SQL database", null)); } #if DEBUG Console.WriteLine($"{DateTime.UtcNow.ToLongTimeString()}:- Completed getting the template era"); #endif _TemplateSimEra = TemplateSimEraTask.Result; } allTasks.Remove(finished); } //Next create the locations in the GroundFrame.SQL database await CreateLocationsFromMap().ConfigureAwait(false); if (DebugMode) { this._Responses.Add(new QueuerResponse(QueuerResponseStatus.DebugMesssage, "Completed creating the locations in the GroundFrame.SQL database", null)); } #if DEBUG using SimulationExtension SimExtentionLocations = new SimulationExtension(this._Simulation.ID, this._SQLConnector); Console.WriteLine($"{DateTime.UtcNow.ToLongTimeString()}:- The Simulation contains {SimExtentionLocations.Locations.Count} location(s)."); #endif //Next create the location nodes in the GroundFrame.SQL database await CreateLocationNodesFromMap(this._SimExt).ConfigureAwait(false); if (DebugMode) { this._Responses.Add(new QueuerResponse(QueuerResponseStatus.DebugMesssage, "Completed creating the location nodes in the GroundFrame.SQL database", null)); } #if DEBUG Console.WriteLine($"{DateTime.UtcNow.ToLongTimeString()}:- The Simulation contains {this._SimExt.LocationNodes.Count} location nodes(s)."); #endif //Next create the path edges in the GroundFrame.SQL database await CreatePathEdgesFromMap(this._SimExt).ConfigureAwait(false); if (DebugMode) { this._Responses.Add(new QueuerResponse(QueuerResponseStatus.DebugMesssage, "Completed creating the path edges in the GroundFrame.SQL database", null)); } #if DEBUG Console.WriteLine($"{DateTime.UtcNow.ToLongTimeString()}:- The Simulation contains {this._SimExt.LocationNodes.Sum(x => x.PathEdges.Count)} path edge(s)."); #endif this._Responses.Add(new QueuerResponse(QueuerResponseStatus.Success, "processSuccess", null)); return(QueuerResponseStatus.Success); } catch (AggregateException Ex) { ResourceManager ExceptionMessageResources = new ResourceManager("GroundFrame.Core.Resources.ExceptionResources", Assembly.GetExecutingAssembly()); string ExceptionMessage = ExceptionMessageResources.GetString("QueuerGenericFailureMessage", Globals.UserSettings.GetCultureInfo()); foreach (Exception Inner in Ex.InnerExceptions) { this._Responses.Add(new QueuerResponse(QueuerResponseStatus.Failed, ExceptionMessage, Inner)); } return(QueuerResponseStatus.Failed); } catch (Exception Ex) { ResourceManager ExceptionMessageResources = new ResourceManager("GroundFrame.Core.Resources.ExceptionResources", Assembly.GetExecutingAssembly()); string ExceptionMessage = ExceptionMessageResources.GetString("QueuerGenericFailureMessage", Globals.UserSettings.GetCultureInfo()); this._Responses.Add(new QueuerResponse(QueuerResponseStatus.Failed, ExceptionMessage, Ex)); return(QueuerResponseStatus.Failed); } }