Ejemplo n.º 1
0
        private void generateDocButton_Click(object sender, EventArgs e)
        {
            SimulationModelReader smr = new SimulationModelReader();
            SimulationModelInfo simModel;

            try
            {
                simModel = smr.readModel(simModelTextBox.Text);
            }
            catch (Exception x)
            {
                MessageBox.Show(x.ToString(),"Error reading simulation model!");
                return;
            }

            StreamWriter outFile;

            try
            {
                outFile = new StreamWriter(ouputTextBox.Text);
            }
            catch (Exception x)
            {
                MessageBox.Show(x.ToString(), "Error opening output file!");
                return;
            }

            string headerHtml = "<html><head><title>DDD Event Documentation</title></head><body><p><h2>DDD Event Documentation</h2></p>";
            string footerHtml = "</body></html>";

            outFile.WriteLine(headerHtml);


            outFile.WriteLine(String.Format("<a name=\"TOC\"><h2>Table of Contents</h2></a>"));
            outFile.WriteLine("<ul>");
            List<string> eventKeys = new List<string>(simModel.eventModel.events.Keys);
            eventKeys.Sort();
            foreach (string s in eventKeys)
            {
                outFile.WriteLine("<li><a href=\"#{0}\">{0}</a></li>",s);
            }
            outFile.WriteLine("</ul>");

            foreach (string key in eventKeys)
            {
                WriteEventHTML(ref outFile, simModel.eventModel.events[key]);
            }

            outFile.WriteLine(footerHtml);
            outFile.Flush();
            outFile.Close();
        }
Ejemplo n.º 2
0
 private void SetSimulationModel()
 {
     string name = simulationModelTextBox.Text;
     if (System.IO.File.Exists(name))
     {
         SimulationModelReader r = new SimulationModelReader();
         simModel = r.readModel(name);
         updateFrequency = simModel.GetUpdateFrequency();
         NetworkEnable();
         EventsEnable();
         SimulationModelDisable();
         
     }
     else
     {
         MessageBox.Show("Invalid simulation model file!");
     }
 }
Ejemplo n.º 3
0
        public static void Coordinate(
            string scenarioFile,
            string schemaFile,
            ref SimulationEventDistributor distributor,
            //string hostname,
            //string portString,
            string simModelName,
            string contextControl,//*NETWORK"
            string updateIncr,
            string lowerLevel, //GUI
            List<string> logTypes,
            string debugFile
            )
        {
            /// <summary>


            debugLogger = new DebugLogger();
            //DateTime dt = DateTime.Now;
            if (!Directory.Exists(debugFile.Remove(debugFile.LastIndexOf("\\"))))
            {
                Directory.CreateDirectory(debugFile.Remove(debugFile.LastIndexOf("\\")));
            }

            DebugLogger.SetDebugStyleFile(debugFile);
            //DebugLogger.SetDebugStyle(DebugLogger.DebugStyleValues.FileReporting);
            DebugLogger.SetLoggingType("general", true);
            foreach (string s in logTypes)
            {
                DebugLogger.SetLoggingType(s, true);
                debugLogger.Writeline("Coordinator", s + " is being recorded.", "general");
            }

            // DebugLogger.SetLoggingType("all", false);


            debugLogger.Writeline("Coordinator", "Hello", "general");

            //int port = int.Parse(portString);
            SimulationModelReader smr = new SimulationModelReader();
            SimulationModelInfo simModelInfo = smr.readModel(simModelName);

            if (distributor == null)
            {
                distributor = new SimulationEventDistributor(ref simModelInfo);
            }

            //SimulationEventDistributor dist = new SimulationEventDistributor(ref simModelInfo);
            //SimulationEventDistributorClient cc = new SimulationEventDistributorClient();

            updateIncrement = simModelInfo.GetUpdateFrequency();
            int enteredIncrement = Int32.Parse(updateIncr);
            if (enteredIncrement > 0)
            {
                updateIncrement = enteredIncrement;
            }
            tickController.UpdateIncrement = updateIncrement;
            try
            {
                new ScenarioToQueues(scenarioFile, schemaFile);
                new ForkReplayToQueues(replayFile,simModelInfo);
            }
            catch (System.Exception f)
            {
                if (f.Message.StartsWith("User Cancelled"))
                {//This means a missing map or icon library, and the user wanted to stop the server.  Do not write to error log, just stop the server. 
                    throw f;
                }
                throw new ApplicationException("Failure in ScenarioToQueues: " + f.Message);
            }

            //NetworkClient c = new NetworkClient();
            SimulationEventDistributorClient distClient = new SimulationEventDistributorClient();
            distributor.RegisterClient(ref distClient);
            try
            {
                //c.Connect(hostname, port);

                EventCommunicator eventCommunicator = new EventCommunicator(ref distClient, simModelName);
                eCommReceiver = new Thread(new ThreadStart(eventCommunicator.WaitForEvents));
                eCommReceiver.CurrentCulture = new System.Globalization.CultureInfo("en-US", true);
                eCommReceiver.Start();


            }
            catch (System.Exception e)
            {
                //Coordinator.debugLogger.WriteLine("Unable to  connect");
                Coordinator.debugLogger.Writeline("Coordinator", "Error in startup: System message: "+e.Message, "general");
                MessageBox.Show("Startup error: " + e.Message);
                Application.Exit();
            }
            EventCommunicator.SendSimStartEvent();

            //dist.RegisterClient(ref cc);


            /*
             * Temporary event  watcher to allow for insertion of events from below
             */
            if (lowerLevel != "GUI")
            {
                //NetworkClient client = new NetworkClient();
                //client.Connect(hostname, port);
                /* 
                       // Tickwatcher is used only to simulate events from lower levels
                              TickWatcher sink = new TickWatcher(client, simModelName);
                              ThreadStart stub = new ThreadStart(sink.TickEventGetter);
                              Thread stubThread = new Thread(stub);
                              stubThread.Start();
                */
            }
            TimerQueueClass.SendImmediates();

            if ("NETWORK" == contextControl)
            {
                while (!readyToTick)
                {
                    Thread.Sleep(1000);
                }
                tickController.SetCallback(new Metronome.SendTimeTick(SendTimeTick));
                tickController.Start();
                while (true)
                {
                    while (pause)
                    {
                        Thread.Sleep(1000);
                    }
                    timeSlice = (timeSlice + 1) % TimeSliceIncrement;

                    //next tick will have 100ms between calls, will not handle sending time ticks, just recent incoming events.
                    //a callback will handle sending time ticks

                    TimerTicker.NextTimeSlice();
                    Thread.Sleep((int)((updateIncrement / TimeSliceIncrement) / speedFactor));
                }
            }

            Coordinator.debugLogger.Writeline("Coordinator", "The End", "general");

        }
Ejemplo n.º 4
0
        public void StartConnect(string host, string shareName, int port, ConnectCompleteDelegate callback)
        {
            if (_dddConnection != null)
            {
                if (_dddConnection.IsConnected())
                    _dddConnection.Disconnect();
            }
            _simModelPath = String.Format(@"\\{0}\{1}\SimulationModel.xml", host, shareName);
            SimulationModelReader rdr = new SimulationModelReader();
            _simModel = rdr.readModel(_simModelPath);
            _dddConnection.DDDClientPath = String.Format(@"\\{0}\{1}", host, shareName);
            _connectCompleteCallback = callback;
            //bool result = false;// = _dddConnection.ConnectToServer(host, port);
            //_connectRunning = true;
            //while (true)
            //{
            //    lock (_connectionLock)
            //    {
            //        if (!_connectRunning)
            //        {
            //            break;
            //        }
            //    }

            //    Thread.Sleep(1000);
            //}
            _connectThread = new Thread(new ParameterizedThreadStart(T_Connect));
            _connectThread.Start(new object[] { host, port });
        }
Ejemplo n.º 5
0
 /// <summary>
 /// A helper function used by ReadSimModel().
 /// </summary>
 /// <param name="path"></param>
 /// <returns></returns>
 public bool ReadSimModel(String path)
 {
     SimulationModelReader reader = new SimulationModelReader();
     try
     {
         m_simModel = reader.readModel(path);
         return true;
     }
     catch
     {
         m_simModel = null;
         return false;
     }
 }
Ejemplo n.º 6
0
        private void ReadSimulationModel()
        {
            Stream str = null;
            SimulationModelReader s = new SimulationModelReader();
            try
            {

                System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
                str = assembly.GetManifestResourceStream(this.GetType(), "SimulationModel.xml");
            }
            catch (Exception)
            {
                MessageBox.Show("Unable to read the Simulation Model.");
            }
            DDD_Global.Instance.SimModel = s.readModel(str);

        }
Ejemplo n.º 7
0
        private void ReadSimulationModel(string hostname)
        {
            try
            {
                SimulationModelReader s = new SimulationModelReader();
                if (hostname != string.Empty)
                {
                    DDD_Global.Instance.SimModel = s.readModel(string.Format("{0}SimulationModel.xml", DDD_Global.Instance.DDDClientShareFolder));
                }
                else
                {
                    DDD_Global.Instance.SimModel = s.readModel("SimulationModel.xml");
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Couldn't find Simulation Model.");
            }

        }
Ejemplo n.º 8
0
        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();
        }