private VSumEntry Simulate(XmlReader xmlReader) { try { Helper.ToConsole(">> inner Simulate"); var run = VectoApi.VectoInstance(xmlReader); SimJob job2 = new SimJob(run); run.WaitFinished = false; run.RunSimulation(); while (!run.IsFinished) { Thread.Sleep(100); } Helper.ToConsole(">> inner Simulate, done"); bool bAnyAbortedCycle = job2.ContainsAbortedCycles(); if (bAnyAbortedCycle == true) { } string strVSum = job2.CreateVSumBlob(DateTime.Now.ToUniversalTime() .ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'")); VSumEntry entry = new VSumEntry(); entry.ApiVersion = VectoApi.GetVectoCoreVersion(); entry.LoadString(strVSum); Helper.ToConsole(">> inner Simulate, inner done"); return(entry); } catch (Exception e) { Helper.ToConsole(string.Format("!! Reco3Simulator.Simulate, inner: {0}", e.Message)); } return(null); }
static void Main(string[] args) { try { /* * DatabaseContext ctx = new DatabaseContext(); * int n = 0; * int nn = 0; * List<VSumRecord> records = ctx.VSum.Where(x => x.SimulationId == 2).Where(x=>x.VehicleId==0).ToList(); * foreach (var record in records) * { * nn++; * n++; * string strVIN = record.VIN; * if (strVIN.Contains("VEH-") == true) * strVIN = strVIN.Substring(4); * int nVehicleId = ctx.VehicleIdFromVIN(strVIN); * if (nVehicleId!=-1) * { * record.VehicleId = nVehicleId; * record.SimulationTimeStamp = DateTime.Now; * } * if (nn==300) * { * ctx.SaveChanges(); * nn = 0; * } * } * * ctx.SaveChanges(); * * return; */ //string strXML = ctx.VehicleXmlByVid(460352); // XMLDeclarationWriter writer = new XMLDeclarationWriter("Scania"); // writer.CreateAxleWheels() WriteToConsole(ConsoleColor.Gray, "1 =============================================================="); ConfigModel config = new ConfigModel(); Reco3Simulator simulator = new Reco3Simulator(); System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.High; /* * simulator.ReQueue(32); * return; */ WriteToConsole(ConsoleColor.Gray, "2 =============================================================="); simulator.MsmqHost = config.Reco3Config.MSMQ.HostName; // ConfigurationManager.AppSettings.Get("MsmqHost"); simulator.IsLocalQueue = false; // Convert.ToBoolean(ConfigurationManager.AppSettings.Get("IsLocalQueue")); simulator.MsmqHostIp = config.Reco3Config.MSMQ.IP; // ConfigurationManager.AppSettings.Get("MsmqHostIp"); simulator.MsmqQueueName = config.Reco3Config.MSMQ.SimulationQueue; // ConfigurationManager.AppSettings.Get("MsmqQueue"); simulator.MsmqHealthQueueName = config.Reco3Config.MSMQ.HealthQueueName; // ConfigurationManager.AppSettings.Get("MsmqHealthQueueName"); simulator.MaxIterations = Convert.ToInt32(config.Reco3Config.Client.MaxIterations); // Convert.ToInt32(ConfigurationManager.AppSettings.Get("MaxIterations")); simulator.msSleepWhenEmptyQueue = Convert.ToInt32(config.Reco3Config.Client.MsSleepWhenEmptyQueue); // Convert.ToInt32(ConfigurationManager.AppSettings.Get("msSleepWhenEmptyQueue")); simulator.MsTeamsUrl = ""; // config.Reco3Config.Integrations.ToList().Find(x => x.id == "Teams").BaseUrl; WriteToConsole(ConsoleColor.Gray, "Reco3Console, ready to serve with the following configuration:"); WriteToConsole(ConsoleColor.Gray, "=============================================================="); WriteToConsole(ConsoleColor.Green, "MsmqHost: {0}", simulator.MsmqHost); WriteToConsole(ConsoleColor.Green, "IsLocalQueue: {0}", simulator.IsLocalQueue); WriteToConsole(ConsoleColor.Green, "MsmqHostIp: {0}", simulator.MsmqHostIp); WriteToConsole(ConsoleColor.Green, "MsmqQueueName: {0}", simulator.MsmqQueueName); WriteToConsole(ConsoleColor.Green, "MsmqHealthQueueName: {0}", simulator.MsmqHealthQueueName); WriteToConsole(ConsoleColor.Green, "MaxIterations: {0}", simulator.MaxIterations); WriteToConsole(ConsoleColor.Green, "msSleepWhenEmptyQueue: {0}", simulator.msSleepWhenEmptyQueue); WriteToConsole(ConsoleColor.Green, "MsTeamsUrl: {0}", simulator.MsTeamsUrl); WriteToConsole(ConsoleColor.Green, "Vectoversion: {0}", VectoApi.GetVectoCoreVersion()); WriteToConsole(ConsoleColor.Gray, "=============================================================="); WriteToConsole(ConsoleColor.Gray, "Initializing the simulator..."); if (true == simulator.Init(ref config)) { WriteToConsole(ConsoleColor.Gray, "Simulator ready!"); // simulator.Run(); Helper.GetUserResponse(); WriteToConsole(ConsoleColor.DarkRed, " Signaling shutdown..."); simulator.Stop(); WriteToConsole(ConsoleColor.DarkRed, " Initiating shutdown..."); simulator.UnInit(); } else { WriteToConsole(ConsoleColor.Red, "!!! CATASTROPHIC FAILURE !!! Failed to initialize Reco3Simulator. "); } } catch (Exception e) { WriteToConsole(ConsoleColor.Red, "!!! CATASTROPHIC FAILURE !!! Exception: {0}", e.Message); } WriteToConsole(ConsoleColor.Red, "Reco3Console signed out. Press Enter to quit."); Helper.GetUserResponse(); }