Esempio n. 1
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 });
        }
Esempio n. 2
0
        private void InitializeSimulationModel(string simModelFile)
        {
            this.simModelFile = simModelFile;
            SimulationModelReader smr = new SimulationModelReader();

            simModelInfo    = smr.readModel(simModelFile);
            updateFrequency = simModelInfo.GetUpdateFrequency();
        }
Esempio n. 3
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();
        }
Esempio n. 4
0
        protected EventListener(NetworkClient server)
        {
            myQM = QueueManager.UniqueInstance();

            SimulationModelReader smr          = new SimulationModelReader();
            SimulationModelInfo   simModelInfo = smr.readModel("SimulationModel.xml");

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

            dist.RegisterClient(ref cc);
            server.Subscribe("MoveDone");
        }
Esempio n. 5
0
        protected EventListener(NetworkClient server)
        {
            myQM = QueueManager.UniqueInstance();

            SimulationModelReader smr = new SimulationModelReader();
            SimulationModelInfo simModelInfo = smr.readModel("SimulationModel.xml");

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

            dist.RegisterClient(ref cc);
            server.Subscribe("MoveDone");

        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            string scenarioFile = args[0];

            new ScenarioToQueues(scenarioFile);
            //           string hostname = "dgeller";
            string hostname = args[1];
//            int port = 9999;
            int port = int.Parse(args[2]);
            //           string simModelName = "SimulationModel.xml";
            string        simModelName = args[3];
            NetworkClient c            = new NetworkClient();

            c.Connect(hostname, port);
            EventCommunicator eventCommunicator = new EventCommunicator(c);

            SimulationModelReader smr          = new SimulationModelReader();
            SimulationModelInfo   simModelInfo = smr.readModel(simModelName);

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

            dist.RegisterClient(ref cc);



            sink = new Watcher(400);
            ThreadStart stub       = new ThreadStart(sink.WatcherThread);
            Thread      stubThread = new Thread(stub);

            stubThread.Start();


            for (int i = 0; i < 5; i++) // in test the move happens at time 2
            {
                TimerTicker.NextTick();
            }
            IncomingList.Add(new MoveComplete_Event("UNIT0"));
            for (int i = 0; i < 2; i++)
            {
                TimerTicker.NextTick();
            }

            Console.WriteLine("The end");
        }
Esempio n. 7
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!");
            }
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            string scenarioFile = args[0];
            new ScenarioToQueues(scenarioFile);
 //           string hostname = "dgeller";
            string hostname=args[1];
//            int port = 9999;
            int port = int.Parse(args[2]);
 //           string simModelName = "SimulationModel.xml";
            string simModelName = args[3];
            NetworkClient c = new NetworkClient();
            c.Connect(hostname, port);
            EventCommunicator eventCommunicator = new EventCommunicator(c);

            SimulationModelReader smr = new SimulationModelReader();
            SimulationModelInfo simModelInfo = smr.readModel(simModelName);

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

            dist.RegisterClient(ref cc);



            sink = new Watcher(400);
            ThreadStart stub = new ThreadStart(sink.WatcherThread);
            Thread stubThread = new Thread(stub);
            stubThread.Start();


            for (int i = 0; i < 5; i++) // in test the move happens at time 2
            {
                TimerTicker.NextTick();
            }
            IncomingList.Add(new MoveComplete_Event("UNIT0"));
            for (int i = 0; i < 2; i++)
            {
                TimerTicker.NextTick();
            }
 
            Console.WriteLine("The end");


        }
Esempio n. 9
0
        //[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;
            }
        }
Esempio n. 10
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");
        }
Esempio n. 11
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();
        }
Esempio n. 12
0
        //[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;
            }
        }