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)); } }
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"); }
protected void UpdateSimulationEntry(Reco3Msg msg, ref DatabaseContext dbx, bool bFinished) { try { /* * Simulation sim = dbx.Simulation.SingleOrDefault(x => x.VehicleId == msg.VehicleId); * if (sim != null) * sim.Finished = bFinished; */ } catch { } }
private void Simulate(Reco3Msg msg, DatabaseContext dbx) { try { // Helper.ToConsole("=> Reco3Simulator.Simulate"); // if (dbx.Vehicle == null) // Helper.ToConsole(">> Reco3Simulator.Simulate: dbx.vehicle=null"); string strVehicleXML = dbx.Vehicle.SingleOrDefault(mytable => mytable.VehicleId == msg.VehicleId).XML; if (strVehicleXML.Length > 0) { // Helper.ToConsole(">> Creating XML-reader..."); long startTick = DateTime.Now.Ticks; // Helper.ToConsole(string.Format("Start Sim: {0}", msg.VehicleId)); using (XmlReader xmlReader = XmlReader.Create(new StringReader(strVehicleXML))) { // Helper.ToConsole(">> Feeding Vecto,...."); VSumEntry entry = Simulate(xmlReader); entry.SetSimulationId(msg.SimulationJobId, DateTime.Now, msg.VehicleId); UpdateSimulationEntry(msg, ref dbx, true); dbx.SaveChanges(); ResultList.Add(entry); //dbx.VSum.AddRange(entry.Records); //dbx.SaveChanges(); } long endTick = DateTime.Now.Ticks; long elapsedTicks = endTick - startTick; TimeSpan elapsedSpan = new TimeSpan(elapsedTicks); Helper.ToConsole(string.Format("Sim-time: {0} ({1:N2}seconds)", msg.VehicleId, elapsedSpan.TotalSeconds)); // Helper.ToConsole(">> Forcing garbage-collection!"); GC.Collect(); } } catch (Exception e) { Helper.ToConsole(string.Format("!! Reco3Simulator.Simulate: {0}", e.Message)); } }
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); }