public void QueueRoadmapFleet() { try { ConsoleHarness.WriteToConsole(ConsoleColor.Green, string.Format("QueueRoadmapFleet, Starting.")); DatabaseContext dbx = new DatabaseContext(); BatchQueue.BatchQueue queue = new BatchQueue.BatchQueue(); queue.IsLocalQueue = false; string strMSMQHost = GetConfig.Reco3Config.MSMQ.HostName; string strMSMQSimulationQueue = GetConfig.Reco3Config.MSMQ.SimulationQueue; queue.IsLocalQueue = true; queue.SetRecieverEndpoint(strMSMQHost, strMSMQSimulationQueue); List <string> VINs = GetList(@"H:\Tools\Reco3Core\MissedVehicles.csv"); foreach (string vin in VINs) { Vehicle vehicle = dbx.Vehicle.Where(x => x.VIN == vin).First(); Reco3Msg msg = new Reco3Msg(); msg.MsgType = Reco3MsgType.PendingRoadmapSimulation; msg.RoadmapId = 6; msg.VehicleId = vehicle.VehicleId; queue.SendMsg(msg); } ConsoleHarness.WriteToConsole(ConsoleColor.Green, string.Format("QueueRoadmapFleet, Done! Processed {0} vehicles.", VINs.Count)); } catch (Exception e) { ConsoleHarness.WriteToConsole(ConsoleColor.Red, string.Format("QueueRoadmapFleet, Exception raised: {0}", e.Message)); } }
/// <summary> /// This method is called when the service gets a request to start. /// </summary> /// <param name="args">Any command line arguments</param> public void OnStart(string[] args) { try { string strMsmqHost = GetConfig.Reco3Config.MSMQ.HostName; string strMSMQConversionQueue = GetConfig.Reco3Config.MSMQ.ConversionQueue; string strMSMQHealthQueue = GetConfig.Reco3Config.MSMQ.HealthQueueName; _conversionQueue = new BatchQueue.BatchQueue(); _conversionQueue.Configuration = GetConfig; _conversionQueue.SetEndpoint(strMsmqHost, strMSMQConversionQueue, false, true); _clientHealthQueue = new BatchQueue.BatchQueue(); _clientHealthQueue.Configuration = GetConfig; _clientHealthQueue.SetEndpoint(strMsmqHost, strMSMQHealthQueue, false, true); //_conversionQueue.SendMsg(new Reco3Msg(3, 57)); /* * // Must look at this again!.... * */ } catch (Exception ex) { ConsoleHarness.WriteToConsole(ConsoleColor.Red, string.Format("OnStart, Exception raised: {0}", ex.Message)); } }
public ActionResult SimulateRoadmap(string roadmapid, string roadmapgroupid) { try { // Post a msmq-msg to indicate the newly uploaded file! BatchQueue.BatchQueue queue = new BatchQueue.BatchQueue(); Reco3Config.ConfigModel Configuration = new ConfigModel(WebConfigurationManager.AppSettings["ConfigFile"]); //ConfigModel model = new ConfigModel(System.IO.Path.Combine(HttpContext.Server.MapPath("~/Config"), "Reco3Config.xml")); queue.IsLocalQueue = true; queue.SetRecieverEndpoint(Configuration.Reco3Config.MSMQ.HostName, Configuration.Reco3Config.MSMQ.ConversionQueue); Reco3Msg msg = new Reco3Msg(Convert.ToInt32(roadmapgroupid), Convert.ToInt32(roadmapid)); msg.MsgType = Reco3_Enums.Reco3MsgType.QueueRoadmapSimulation; queue.SendMsg(msg); return(Json(new { success = true, message = "Roadmap successfully updated with baseline." }, JsonRequestBehavior.AllowGet)); /* * AgentBase ABase = new AgentBase(); * DatabaseContext dbx = ABase.GetContext(); * if (true == dbx.RMManager.SaveRoadmap(Convert.ToInt32(StartYear), Convert.ToInt32(EndYear), Alias, Convert.ToInt32(RoadmapGroupID))) * return Json(new { success = true, message = "RoadmapGroup successfully updated." }, JsonRequestBehavior.AllowGet); */ //return Json(new { success = true, message = "Failed to save roadmapGroup. Internal error while finding the targetmap." }, JsonRequestBehavior.AllowGet); } catch (Exception e) { Console.WriteLine(e); return(Json(new { success = false, message = e.Message }, JsonRequestBehavior.AllowGet)); } //return RedirectToAction("Index"); }
private void _worker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { try { // Helper.ToConsole("=> Reco3Simulator._worker_DoWork"); BatchQueue.BatchQueue SimulationQueue = new BatchQueue.BatchQueue(); SimulationQueue.SetEndpoint(MsmqHost, MsmqQueueName, true, false); BatchQueue.BatchQueue HealthQueue = new BatchQueue.BatchQueue(); HealthQueue.SetEndpoint(MsmqHost, MsmqHealthQueueName, true, false); PingServer(HealthQueue); bool bGoToSleep = true; do { bGoToSleep = ProcessQueue(SimulationQueue, HealthQueue, ref e); if (bGoToSleep == true) { // Helper.ToConsole(">> Reco3Simulator._worker_DoWork, setting timer and cleaning up before going to sleep....Zzzzzz"); GC.Collect(); SimulationQueue.ResetQueueObj(); Thread.Sleep(msSleepWhenEmptyQueue); PingServer(HealthQueue, true); } } while (bGoToSleep == true); // Helper.ToConsole("<= Reco3Simulator._worker_DoWork"); } catch (Exception exception) { Helper.ToConsole(string.Format("!! Reco3Simulator._worker_DoWork: {0}", exception.Message)); } }
public ActionResult ConvertRoadmap(string roadmapid, string roadmapgroupid) { try { // Post a msmq-msg to indicate the newly uploaded file! BatchQueue.BatchQueue queue = new BatchQueue.BatchQueue(); Reco3Config.ConfigModel Configuration = new ConfigModel(WebConfigurationManager.AppSettings["ConfigFile"]); queue.IsLocalQueue = true; queue.SetRecieverEndpoint(Configuration.Reco3Config.MSMQ.HostName, Configuration.Reco3Config.MSMQ.ConversionQueue); queue.SendMsg(new Reco3Msg(Convert.ToInt32(roadmapgroupid), Convert.ToInt32(roadmapid))); return(Json(new { success = true, message = "Roadmap successfully updated with baseline." }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { Console.WriteLine(e); return(Json(new { success = false, message = e.Message }, JsonRequestBehavior.AllowGet)); } //return RedirectToAction("Index"); }
private void PingServer(BatchQueue.BatchQueue queue, bool bSleeping = false) { try { // Helper.ToConsole(">> PingServer"); m_ClientInfo.Update(); m_ClientInfo.QueueSize = ResultList.Count; m_ClientInfo.Sleeping = bSleeping; string strXml = ""; if (true == m_ClientInfo.Serialize(ref strXml)) { MessageQueue queue2 = queue._manager.GetQueue(MsmqHostIp); if (queue2 != null) { Reco3Msg msg = new Reco3Msg(Reco3MsgType.PushHealth, -1, -1); msg.Text = strXml; Message m1 = new Message(); m1.Label = string.Format("Health:{0}-{1}", m_ClientInfo.NodeName, m_ClientInfo.ProcId); m1.Body = msg; m1.UseDeadLetterQueue = true; m1.Recoverable = true; queue2.Send(m1); // Helper.ToConsole(" Health is posted!"); } else { Helper.ToConsole(" Failed to get queue,...."); } } } catch (Exception e) { Console.WriteLine(e); } // Helper.ToConsole("<< PingServer"); }
private bool ProcessQueue(BatchQueue.BatchQueue queue, BatchQueue.BatchQueue healthqueue, ref System.ComponentModel.DoWorkEventArgs e) { try { int nIterationCounter = 0; Reco3Msg msg = null; using (DatabaseContext dbx = new DatabaseContext()) { while (null != (msg = queue.GetNextMsg(MsmqHostIp))) { if (msg.MsgType == Reco3MsgType.PendingRoadmapSimulation) { // Simulate vehicle, will post back result to Db SimulateRoadmapVehicle(msg, dbx); } else { // Simulate vehicle, will post back result to Db Simulate(msg, dbx); } // Ping health to server every 10 records... if (nIterationCounter % 10 == 0) { PingServer(healthqueue); } if (nIterationCounter++ == MaxIterations) { Helper.ToConsole(">> Reached MaxIterations, submitting all results."); PublishResult(dbx); nIterationCounter = 0; PingServer(healthqueue); Helper.ToConsole(">> All results published."); } if (_worker.CancellationPending) { Helper.ToConsole(">> Cancel initiated, submitting all results."); PublishResult(dbx); nIterationCounter = 0; PingServer(healthqueue); Helper.ToConsole(">> All results published."); PostMessage(m_ClientInfo, "Signing out, cancelled by user.", false); e.Cancel = true; _worker.ReportProgress(0); return(false); } } if (ResultList.Count > 0) { Helper.ToConsole(">> Queue emptied, submitting all results."); PublishResult(dbx); nIterationCounter = 0; PingServer(healthqueue); PostMessage(m_ClientInfo, "Signing out, queue emptied.", false); Helper.ToConsole(">> All results published."); } } return(true); } catch (Exception exception) { PostMessage(m_ClientInfo, exception.Message, true); Helper.ToConsole(string.Format("!! Reco3Simulator.ProcessQueue: {0}", exception.Message)); } return(false); }
public ActionResult UploadBaseline(string RoadmapGroupId) { try { int nRoadmapGroupId = -1; if (RoadmapGroupId.Contains("-1") == true) { logger.Debug("UploadBaseline failed, due to invalid GroupId (-1)"); return(Json(new { success = false, message = "Failed to upload baseline. Internal error: RoadmapId is invalid." }, JsonRequestBehavior.AllowGet)); } nRoadmapGroupId = Convert.ToInt32(RoadmapGroupId); AgentBase ABase = new AgentBase(); DatabaseContext dbx = ABase.GetContext(); RoadmapGroup map = dbx.RMManager.GetRoadmapGroup(nRoadmapGroupId, false); if (map != null) { if (map.Protected == true) { logger.Debug("UploadBaseline failed, due to locked roadmp"); return(Json(new { success = false, message = "Roadmap is locked for further changes. Action is aborted." }, JsonRequestBehavior.AllowGet)); } if (Request.Files.Count > 0) { var root = "/Filedrop"; string strDropFolder = GetVirtualFolder(root); if (strDropFolder.Length <= 0) { logger.Debug("UploadBaseline failed, due to filedrop-area is missing (Virtual folder"); return(Json(new { success = false, message = "Server-error, filedrop-area is missing (Virtual folder). Action is aborted." }, JsonRequestBehavior.AllowGet)); } for (int i = 0; i < Request.Files.Count; i++) { // First save the stream to disk var files = Request.Files[i]; var fileName = System.IO.Path.GetFileName(files.FileName); var path = System.IO.Path.Combine(strDropFolder, fileName); files.SaveAs(path); var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete); using (StreamReader reader = new StreamReader(fs, Encoding.UTF8)) { string content = reader.ReadToEnd(); map.Validation_Status = Reco3_Enums.ValidationStatus.Processing; map.XML = content; dbx.SaveChanges(); // Lets validate the input Reco3Config.ConfigModel Configuration = new ConfigModel(WebConfigurationManager.AppSettings["ConfigFile"]); map.XMLSchemaFilename = ""; string strVectoSchemaFilename = Configuration.Reco3Config.Schemas.ToList().Find(x => x.id == "Vecto.Declaration").filename; string strConversionLogFile = string.Format("{0}{1}", Configuration.Reco3Config.BackEnd.FilePaths.ToList().Find(x => x.id == "Log").path, "BaselineModel.b.Conversion.txt"); BaselineModel.BaselineModel fleet = new BaselineModel.BaselineModel(strConversionLogFile); if (false == fleet.InitializeFromXML(map.XML, map.XMLSchemaFilename)) { // Tag the baseline as "not ok" map.Validation_Status = Reco3_Enums.ValidationStatus.ValidatedWithFailures; dbx.SaveChanges(); logger.Debug("UploadBaseline failed, due to validation-error of the baseline"); return(Json(new { success = false, message = "Failed to save roadmap. Internal error while validating the baseline using: " + map.XMLSchemaFilename + "." }, JsonRequestBehavior.AllowGet)); } // Tag the baseline as "ok" map.Validation_Status = Reco3_Enums.ValidationStatus.ValidatedWithSuccess; dbx.SaveChanges(); /* * try * { * // Indicating that there are no available roadmaps, so lets generated them * int nRoadmapId = -1; * if (nRoadmapId == -1) * { * for (int n = map.StartYear; n <= map.EndYear; n++) * { * Roadmap oldMap = map.Roadmaps.First(x => x.CurrentYear == n); * if (oldMap == null) * { * Roadmap newMap = new Roadmap(map, n); * map.Roadmaps.Add(newMap); * dbx.SaveChanges(); * if (nRoadmapId == -1) * nRoadmapId = newMap.RoadmapId; * } * * } * } * } * catch (Exception ex) * { * logger.Debug("UploadBaseline failed, failed to create roadmaps. {0}", ex.Message); * return Json(new { success = false, message = "Failed to create roadmaps for group : " + ex.Message }, JsonRequestBehavior.AllowGet); * } */ // Post a msmq-msg to indicate the newly uploaded file! BatchQueue.BatchQueue queue = new BatchQueue.BatchQueue(); queue.IsLocalQueue = true; queue.SetRecieverEndpoint(Configuration.Reco3Config.MSMQ.HostName, Configuration.Reco3Config.MSMQ.ConversionQueue); // Must look at this again!.... foreach (Roadmap map2 in map.Roadmaps) { if (map2.Protected == false) { queue.SendMsg(new Reco3Msg(map.RoadmapGroupId, map2.RoadmapId)); } } return(Json(new { success = true, message = "File uploaded successfully, file is queued for validation." }, JsonRequestBehavior.AllowGet)); } } return(Json(new { success = false, message = "Failed to save roadmap. Internal error while finding the targetmap." }, JsonRequestBehavior.AllowGet)); } } } catch (Exception ex) { return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = false, message = "Fatal error!" }, JsonRequestBehavior.AllowGet)); }
static void Main(string[] args) { /* * DatabaseContext dbx = new DatabaseContext(); * * * * ThreeDExperience exp = new ThreeDExperience(); * exp.Reset(); * DateTime dtThen = DateTime.Now; * exp.AddPDNum("2808389"); * List<Reco3Component> components = exp.Query(); * dbx.Reco3Components.AddRange(components); * dbx.SaveChanges(); * * exp.AddPDNum("2743387"); * exp.AddPDNum("2743590"); * exp.AddPDNum("2743609"); * exp.AddPDNum("2743633"); * exp.AddPDNum("2744987"); * exp.AddPDNum("2765794"); * exp.AddPDNum("2765815"); * exp.AddPDNum("2765816"); * exp.AddPDNum("2765831"); * * DateTime dtNow = DateTime.Now; * var diffInSeconds = (dtNow-dtThen).TotalMilliseconds; * exp.Reset(); * * exp.AddPDNum("2766389"); * exp.AddPDNum("2766390"); * exp.AddPDNum("2766391"); * exp.AddPDNum("2766392"); * exp.AddPDNum("2766393"); * exp.AddPDNum("2766394"); * exp.AddPDNum("2766425"); * exp.AddPDNum("2766426"); * exp.AddPDNum("2766427"); * exp.AddPDNum("2766428"); * components = exp.Query(); * dbx.Reco3Components.AddRange(components); * exp.Reset(); * * exp.AddPDNum("2766429"); * exp.AddPDNum("2766430"); * exp.AddPDNum("2766431"); * exp.AddPDNum("2766432"); * exp.AddPDNum("2766433"); * exp.AddPDNum("2766434"); * exp.AddPDNum("2766435"); * exp.AddPDNum("2766436"); * exp.AddPDNum("2766437"); * exp.AddPDNum("2766438"); * components = exp.Query(); * exp.Reset(); * * exp.AddPDNum("2766439"); * exp.AddPDNum("2766440"); * exp.AddPDNum("2766441"); * exp.AddPDNum("2766442"); * exp.AddPDNum("2766443"); * exp.AddPDNum("2766444"); * exp.AddPDNum("2766445"); * exp.AddPDNum("2766446"); * exp.AddPDNum("2766447"); * exp.AddPDNum("2766448"); * exp.AddPDNum("2766575"); * * components = exp.Query(); * exp.Reset(); */ // BatchQueue.BatchQueue SimulationQueue = new BatchQueue.BatchQueue(); // SimulationQueue.SetEndpoint("RD0045111", "YDMC.Batch.Simulation"); string strMsmqHost = ConfigurationManager.AppSettings.Get("MsmqHost"); string strMSMQConversionQueue = ConfigurationManager.AppSettings.Get("MSMQConversionQueue"); string strMSMQHealthQueue = ConfigurationManager.AppSettings.Get("MsmqHealthQueueName"); BatchQueue.BatchQueue ConversionQueue = new BatchQueue.BatchQueue(); ConversionQueue.SetEndpoint(strMsmqHost, strMSMQConversionQueue, false, true); BatchQueue.BatchQueue ClientHealthQueue = new BatchQueue.BatchQueue(); ClientHealthQueue.SetEndpoint(strMsmqHost, strMSMQHealthQueue, false, true); Thread.Sleep(100); ConversionQueue.SendMsg(new Reco3Msg(Reco3_Enums.Reco3MsgType.UpdateComponentData, 0, 0)); //ConversionQueue.SendMsg(new Reco3Msg(Reco3Msg.Reco3MsgType.PendingConversion, 1)); /* * * ConversionQueue.SendMsg(new Reco3Msg(Reco3Msg.Reco3MsgType.PendingSimulation, -1, 2, 1)); * ConversionQueue.SendMsg(new Reco3Msg(Reco3Msg.Reco3MsgType.PendingSimulation, -1, 3, 1)); * ConversionQueue.SendMsg(new Reco3Msg(Reco3Msg.Reco3MsgType.PendingSimulation, -1, 4, 1)); */ Helper.ToConsole("Press Enter to quit"); Helper.GetUserResponse(); }