public static void sendEventsAtTime(int?time, NetworkClient target) { //while loop at removes and sends to SimCore all events at time = time while (EventQueue.ContainsKey(time) && EventQueue[time].Count > 0) { Console.WriteLine("Sending..."); Console.WriteLine(SimulationEventFactory.XMLSerialize(EventQueue[time][0])); target.PutEvent(EventQueue[time][0]); EventQueue[time].RemoveAt(0); } }
private void saveEventsButton_Click(object sender, EventArgs e) { if (sfd.ShowDialog() == DialogResult.OK) { StreamWriter wr = new StreamWriter(sfd.FileName); foreach (EventListBoxItem lbi in eventsListBox.Items) { wr.WriteLine(SimulationEventFactory.XMLSerialize(lbi.simEvent)); } wr.Flush(); wr.Close(); } }
static void Main(string[] args) { string hostname = args[0]; int port = Int32.Parse(args[1]); //NetworkClient nc = new NetworkClient(); nc.Connect(hostname, port); ConsoleKeyInfo cki; Console.TreatControlCAsInput = false; Console.CancelKeyPress += new ConsoleCancelEventHandler(MyExitHandler); //Console.CancelKeyPress += new ConsoleCancelEventHandler(MyExitHandler,nc); //ConsoleCancelEventArgs if (args.Length > 2) { for (int i = 2; i < args.Length; i++) { nc.Subscribe(args[i]); } } else { nc.Subscribe("ALL"); } List <SimulationEvent> events; while (nc.IsConnected()) { events = nc.GetEvents(); foreach (SimulationEvent e in events) { System.Console.WriteLine(SimulationEventFactory.XMLSerialize(e)); } Thread.Sleep(50); } return; }
/// <summary> /// This method is used to send an event to the DDD Server. /// </summary> /// <param name="e">The event</param> public void PutEvent(SimulationEvent e) { if (isConnected) { NetMessage m = new NetMessage(); m.type = NetMessageType.EVENT; try { m.msg = SimulationEventFactory.XMLSerialize(e); } catch (Exception exc) { ErrorLog.Write(String.Format("NONFATAL Serialize Error in NetworkClient: {0}", e.eventType)); ErrorLog.Write(exc.ToString()); return; } m.clientID = clientID; m.Send(ref netStream, TerminalID); } }
public void WriteToLog() { try { //SimulationEventDistributor dist = new SimulationEventDistributor(ref simModelInfo); //cc = new SimulationEventDistributorClient(); List <SimulationEvent> incomingEvents = new List <SimulationEvent>(); FileStream file = new FileStream(logPath, FileMode.Create); StreamWriter sr = new StreamWriter(file); sr.WriteLine("<Creator><Version>" + productVersion + "</Version><CompiledOn>" + compileDate + "</CompiledOn></Creator>"); actualTime = 0; //dist.RegisterClient(ref cc); foreach (string subString in simModelInfo.eventModel.events.Keys) { //cc.Subscribe(subString); //If the user wants the detailed log, or if the event is flagged with the shouldLog //bool value, it should subscribe to that event. Otherwise, don't subscribe. if ((logMode == "Detailed") || simModelInfo.eventModel.events[subString].shouldLog) { cc.Subscribe(subString); } } isRunning = true; while (isRunning) { //incomingEvents = cc.GetEvents(); incomingEvents = cc.GetEvents(); if (incomingEvents.Count != 0) { foreach (SimulationEvent se in incomingEvents) { if (se.eventType == "TimeTick") { actualTime = ((IntegerValue)se["Time"]).value; } ((IntegerValue)se["Time"]).value = actualTime; try { sr.WriteLine(SimulationEventFactory.XMLSerialize(se)); } catch (Exception exc) { ErrorLog.Write(String.Format("NONFATAL Serialize Error in ReplayLogger: {0}", se.eventType)); ErrorLog.Write(exc.ToString()); continue; } sr.Flush(); } incomingEvents.Clear(); } Thread.Sleep(100); } sr.Close(); file.Close(); //dist.RemoveClient(cc.id); //is this correct? //server.Disconnect(); } catch (ThreadAbortException) { } catch (Exception exc) { MessageBox.Show("An error '" + exc.Message + "' has occurred in the Simulation Server.\nPlease email the C:\\DDDErrorLog.txt file to Aptima customer support with a description of what you were doing at the time of the error."); ErrorLog.Write(exc.ToString() + "\n"); throw new Exception(); } }
static void Main(string[] args) { /* setup the exit handler */ Console.TreatControlCAsInput = false; Console.CancelKeyPress += new ConsoleCancelEventHandler(MyExitHandler); /* read in the config file */ if (args.Length != 2) { Console.WriteLine(String.Format("Usage: {0} [CONFIG_FILE] [DDD_SIMULATION_MODEL]", Environment.CommandLine)); Environment.Exit(1); } string configFileName = args[0]; Console.WriteLine(String.Format("Reading config file: {0}", configFileName)); string simModelFile = args[1]; SimulationModelInfo simModel = null; SimulationModelReader smr = new SimulationModelReader(); try { simModel = smr.readModel(simModelFile); } catch (Exception e) { Console.WriteLine(e.Message); Environment.Exit(1); } ConfigFile config = new ConfigFile(); try { config.readFile(configFileName); } catch (Exception e) { Console.WriteLine(e.Message); Environment.Exit(1); } try { config.verifyConfig(); } catch (Exception e) { Console.WriteLine(e.Message); Environment.Exit(1); } /* connect to the DDD Server */ dddNetworkClient = new NetworkClient(); if (!dddNetworkClient.Connect(config.dddServerHostname, config.dddServerPortNumber)) { Environment.Exit(1); } /* connect to the IMAP server */ imapServer = new Chilkat.Imap(); imapServer.Port = config.emailServerPortNumber; imapServer.Ssl = config.emailServerUseSSL; bool success; // Anything unlocks the component and begins a fully-functional 30-day trial. success = imapServer.UnlockComponent("SAptimaIMAPMAIL_yyq2ULZCFw4G"); if (success != true) { Console.WriteLine(imapServer.LastErrorText); ExitApp(); } /* loop reading from the IMAP Server until user cancels or the DDD disconnects us */ int count = config.emailCheckFrequency; while (dddNetworkClient.IsConnected()) { if (count == config.emailCheckFrequency) { Console.WriteLine("Checking email"); // Connect to an IMAP server. success = imapServer.Connect(config.emailServerHostname); if (success != true) { Console.WriteLine(imapServer.LastErrorText); ExitApp(); } // Login success = imapServer.Login(config.emailUsername, config.emailPassword); if (success != true) { Console.WriteLine(imapServer.LastErrorText); ExitApp(); } // Select an IMAP mailbox success = imapServer.SelectMailbox("Inbox"); if (success != true) { Console.WriteLine(imapServer.LastErrorText); ExitApp(); } Chilkat.MessageSet messageSet; // We can choose to fetch UIDs or sequence numbers. bool fetchUids; fetchUids = true; /* downloading new emails from IMAP server */ messageSet = imapServer.Search("NOT SEEN", fetchUids); if (messageSet == null) { Console.WriteLine(imapServer.LastErrorText); ExitApp(); } // Fetch the emails into a bundle object: Chilkat.EmailBundle bundle; bundle = imapServer.FetchBundle(messageSet); if (bundle == null) { Console.WriteLine(imapServer.LastErrorText); ExitApp(); } imapServer.Disconnect(); int i; Chilkat.Email email; for (i = 0; i <= bundle.MessageCount - 1; i++) { email = bundle.GetEmail(i); SimulationEvent ev = SimulationEventFactory.BuildEvent(ref simModel, "ExternalEmailReceived"); ((StringValue)ev["FromAddress"]).value = email.FromAddress; for (int k = 0; k < email.NumTo; k++) { ((StringListValue)ev["ToAddresses"]).strings.Add(email.GetToAddr(k)); //Console.WriteLine("To:" + email.GetToAddr(k)); } //Console.WriteLine("Wall clock time:" + email.LocalDate.ToString()); ((StringValue)ev["WallClockTime"]).value = email.LocalDate.ToString(); //Console.WriteLine("Subject:" + email.Subject); ((StringValue)ev["Subject"]).value = email.Subject; //Console.WriteLine("Body:" + email.Body); ((StringValue)ev["Body"]).value = email.Body; //Console.WriteLine("NumAttachments:" + email.NumAttachments.ToString()); string attachName; string attachDir; string dirPath; for (int j = 0; j < email.NumAttachments; j++) { attachName = email.GetAttachmentFilename(j); //Console.WriteLine("filename=" + email.GetAttachmentFilename(j)); attachDir = String.Format("Attachments{0}", email.LocalDate.ToString("yyyyMMddHHmmss")); dirPath = String.Format("{0}\\{1}", config.attachmentBaseDirectory, UniqueDirName(config.attachmentBaseDirectory, attachDir)); Directory.CreateDirectory(dirPath); attachName = String.Format("{0}\\{1}", dirPath, email.GetAttachmentFilename(j)); ((StringListValue)ev["Attachments"]).strings.Add(attachName); email.SaveAttachedFile(j, dirPath); } dddNetworkClient.PutEvent(ev); Console.WriteLine(SimulationEventFactory.XMLSerialize(ev)); } count = 0; } Thread.Sleep(1000); count++; } ExitApp(); }
public void SendEvents() { NetMessage m = new NetMessage(); List <SimulationEvent> events = null; int count = 0; while (true) { try { if (eventDistClient != null) { events = eventDistClient.GetEvents(); foreach (SimulationEvent e in events) { m.type = NetMessageType.EVENT; m.clientID = eventDistClient.id; try { m.msg = SimulationEventFactory.XMLSerialize(e); } catch (Exception exc) { ErrorLog.Write(String.Format("NONFATAL Serialize Error in NetworkServer: {0}", e.eventType)); ErrorLog.Write(exc.ToString()); continue; } m.Send(ref netStream, String.Empty); } Thread.Sleep(50); count += 1; if (count >= 100) { count = 0; m.type = NetMessageType.PING; m.clientID = eventDistClient.id; m.Send(ref netStream, String.Empty); } } } catch (System.IO.IOException exc) { ForceClose(); return; } catch (System.ObjectDisposedException) { return; } catch (ThreadAbortException) { return; } catch (Exception exc) { MessageBox.Show("An error has occured in the Simulation Server.\nPlease email the C:\\DDDErrorLog.txt file to Aptima customer support with a description of what you were doing at the time of the error."); ErrorLog.Write(exc.ToString() + "\n"); throw new Exception(); } } }
//[STAThread] static void Main(string[] args) { string hostname = args[0]; int port = Int32.Parse(args[1]); string simModelName = args[2]; SimulationModelReader smr = new SimulationModelReader(); SimulationModelInfo simModelInfo = smr.readModel(simModelName); SimulationEventDistributor dist = new SimulationEventDistributor(ref simModelInfo); SimulationEventDistributorClient cc = new SimulationEventDistributorClient(); dist.RegisterClient(ref cc); cc.Subscribe("ALL"); ScenarioReader scenarioReader = new ScenarioReader(); QueueManager queueManager = QueueManager.UniqueInstance(); c = new NetworkClient(); c.Connect(hostname, port); EventListener myEL = EventListener.UniqueInstance(c); int t = 0; int dt = simModelInfo.simulationExecutionModel.updateFrequency; SimulationEvent tick = SimulationEventFactory.BuildEvent(ref simModelInfo, "TimeTick"); ((IntegerValue)tick["Time"]).value = t; ConsoleKeyInfo cki; //Console.TreatControlCAsInput = false; //This explodes my code for some reason, but is in Gabe's client code and works fine, what does it do? Console.CancelKeyPress += new ConsoleCancelEventHandler(MyExitHandler); List <SimulationEvent> events = null; while (c.IsConnected() && queueManager.count() > 0) { //Read incoming events queue //if any events deal with a conditional event, remove the conditional //event from the conditional list, and place it onto the event queue //if a unit dies, remove them from the event queue and condition list while (c.IsConnected() && !(queueManager.eventsAtTime(t))) { events = c.GetEvents(); foreach (SimulationEvent e in events) { if (e.eventType == "MoveDone") { c.PutEvent(myEL.MoveDoneReceived(e, simModelInfo, tick)); } System.Console.WriteLine(SimulationEventFactory.XMLSerialize(e)); } ((IntegerValue)tick["Time"]).value = t; c.PutEvent(tick); //Console.WriteLine("Sending..."); //Console.WriteLine(SimulationEventFactory.XMLSerialize(tick)); Thread.Sleep(dt); t += dt; } if (c.IsConnected()) { QueueManager.sendEventsAtTime(t, c); ((IntegerValue)tick["Time"]).value = t; c.PutEvent(tick); //Console.WriteLine("Sending..."); //Console.WriteLine(SimulationEventFactory.XMLSerialize(e)); t += dt; } } while (c.IsConnected()) { ((IntegerValue)tick["Time"]).value = t; c.PutEvent(tick); //Console.WriteLine("Sending..."); //Console.WriteLine(SimulationEventFactory.XMLSerialize(tick)); Thread.Sleep(dt); t += dt; } }