コード例 #1
0
ファイル: ScenarioToQueues.cs プロジェクト: wshanshan/DDD
        public ScenarioToQueues(string scenarioFile)
        {
            TimerQueueClass timerQueue = new TimerQueueClass();
            // Extract fields from the XML file (and schema)
            // see http://weblogs.asp.net/dbrowning/articles/114561.aspx  
            // paths to xml/xsd
           // const string path = @"C:\Documents and Settings\dgeller\My Documents\Visual Studio 2005\Projects\";
            //const string scenarioFile = path + @"DDD\Scenario.xml";
           // const string xsdPath = path + @"XMLTrial\XMLTrial\ScenarioSchema.xsd";




            FileStream fs;
            Boolean returnVal;


            try
            {
                returnVal = ValidateSchema(scenarioFile);
            }
            catch (ApplicationException e)
            {
                Console.WriteLine("Could not validate scenario file " + scenarioFile + " against schema");
                if (e.Message != null)
                {
                    Console.WriteLine(e.Message);
                }
                else
                {
                    Console.WriteLine("No further information available.  Sorry.");
                }
                return;
            }

            if (!returnVal)
            {
                return;
            }


            try
            {
                fs = File.Open(scenarioFile, FileMode.Open);
            }
            catch
            {
                ApplicationException e = new ApplicationException("Could not open scenario file.");
                throw e;

            }
 

            reader = new XmlTextReader(fs);
            parser = new Parser(reader);

            reader.Read(); // opens, gets to xml declaration
            reader.Read();
            if ("Scenario" == reader.Name) // only Scenario can be top level
            {
                reader.Read(); // pass by "Scenario"
                while (!reader.EOF  && !((XmlNodeType.EndElement==reader.NodeType)&&("Scenario"==reader.Name)))
                {

                    Console.WriteLine(".");

                    switch (reader.NodeType)
                    {

                        case XmlNodeType.Element:
                            Console.WriteLine("ELEMENT <{0}>", reader.Name);
                            switch(reader.Name)
                            {
                                case "Create_Event":
                           Create_EventType createEvent = parser.GetCreate_EventType();
                           TimerQueueClass.Add(createEvent.Timer, createEvent);
                                    Console.WriteLine(" createEvent ");
                                break;
                                case "Move_Event":
                                Move_EventType moveEvent = parser.GetMove_EventType();
                                TimerQueueClass.Add(moveEvent.Timer, moveEvent);

                                    Console.WriteLine(" moveEvent ");
                                break;
                                case "Completion_Event":
                                    HappeningCompletionType completionType = parser.GetHappeningCompletionType();
                                    HappeningList.Add(completionType);
                                    break;

                                default:
                                Console.WriteLine(" Unknown Element is *{0}* ", reader.Name);


                                break;
                            }

                            break;
                        case XmlNodeType.Text:
                            Console.WriteLine("TEXT <{0}>", reader.Value);
                            break;
                        case XmlNodeType.CDATA:
                            Console.WriteLine("CDATA <![CDATA[{0}]]>", reader.Value);
                            break;
                        case XmlNodeType.ProcessingInstruction:
                            Console.WriteLine("PROC INS<?{0} {1}?>", reader.Name, reader.Value);
                            break;
                        case XmlNodeType.Comment:
                            Console.WriteLine("COMMENT <!--{0}-->", reader.Value);
                            break;
                        case XmlNodeType.XmlDeclaration:
                            Console.WriteLine("<?xml version='1.0'?>");
                            break;
                        case XmlNodeType.Document:
                            break;
                        case XmlNodeType.DocumentType:
                            Console.WriteLine("DOCTYPE <!DOCTYPE {0} [{1}]", reader.Name, reader.Value);
                            break;
                        case XmlNodeType.EntityReference:
                            Console.WriteLine(reader.Name);
                            break;
                        case XmlNodeType.EndElement:
                            Console.WriteLine("END ELEMENT </{0}>", reader.Name);
                            break;
                    }

                }

            }

            Console.WriteLine("Done\n");








        }
コード例 #2
0
ファイル: Timer.cs プロジェクト: vishalbelsare/DDD
        public static void NextTick()
        {
            while (readParse.sink.ShouldIWait())
            {
                Thread.Sleep(100);
            }
/* 1. Process the incoming list of events from below */
            // Which units are currently on the incoming list
            List <string> unitList = IncomingList.AffectedUnits();

            for (int i = 0; i < unitList.Count; i++)
            {
                List <IncomingItemType> eventList = IncomingList.Retrieve(unitList[i]);


                /* do things with these events */
                for (int j = 0; j < eventList.Count; j++)
                {
                    ScenarioEventType thisItem = eventList[j].TheEvent;
                    if (thisItem.GetType() == typeof(MoveComplete_Event))
                    {
                        Console.WriteLine("Unit {0} MoveComplete discovered at t={1}", thisItem.UnitID, timer);
                        // scan happenings list for matches
                        for (int h = HappeningList.Happenings.Count - 1; 0 <= h; h--)
                        {
                            ScenarioEventType incident = HappeningList.Happenings[h];
                            if (incident.UnitID == thisItem.UnitID)
                            {
                                ScenarioEventType newEvent = ((HappeningCompletionType)incident).DoThis;
                                newEvent.Timer = timer;
                                TimerQueueClass.Add(timer, newEvent);
                                HappeningList.Happenings.RemoveAt(h);
                            }
                        }    // all happenings affected by this Move_complete have been queued
                    }
                    else
                    {
                        Console.WriteLine("Unknown incoming list item {0}", thisItem.GetType());
                    }
                }

                Console.WriteLine("Unit {0} has {1} elements", unitList[i], eventList.Count);
                /* and then take them off the incoming list */
                List <int> indexList = new List <int>();
                for (int j = 0; j < eventList.Count; j++)
                {
                    indexList.Add(eventList[j].TheIndex);
                }
                IncomingList.RemoveUnit(indexList);
            }
/* 2. Send the tick */
            EventCommunicator.SendEvent(new TickEventType(timer));
/* 3. Pull the events for this tick off the queue and handle them */
            List <ScenarioEventType> events = TimerQueueClass.RetrieveEvents(timer);

            if (events != null)
            {
                for (int v = 0; v < events.Count; v++)
                {
                    EventCommunicator.SendEvent(events[v]);
                    //Console.WriteLine("Timer {0} unit {1} type {2}", timer, events[v].UnitID, events[v].GetType().FullName);
                }
            }


/* Very Last Thing                   */
            timer += 1;
        }
コード例 #3
0
ファイル: ScenarioToQueues.cs プロジェクト: vishalbelsare/DDD
        public ScenarioToQueues(string scenarioFile)
        {
            TimerQueueClass timerQueue = new TimerQueueClass();
            // Extract fields from the XML file (and schema)
            // see http://weblogs.asp.net/dbrowning/articles/114561.aspx
            // paths to xml/xsd
            // const string path = @"C:\Documents and Settings\dgeller\My Documents\Visual Studio 2005\Projects\";
            //const string scenarioFile = path + @"DDD\Scenario.xml";
            // const string xsdPath = path + @"XMLTrial\XMLTrial\ScenarioSchema.xsd";



            FileStream fs;
            Boolean    returnVal;


            try
            {
                returnVal = ValidateSchema(scenarioFile);
            }
            catch (ApplicationException e)
            {
                Console.WriteLine("Could not validate scenario file " + scenarioFile + " against schema");
                if (e.Message != null)
                {
                    Console.WriteLine(e.Message);
                }
                else
                {
                    Console.WriteLine("No further information available.  Sorry.");
                }
                return;
            }

            if (!returnVal)
            {
                return;
            }


            try
            {
                fs = File.Open(scenarioFile, FileMode.Open);
            }
            catch
            {
                ApplicationException e = new ApplicationException("Could not open scenario file.");
                throw e;
            }


            reader = new XmlTextReader(fs);
            parser = new Parser(reader);

            reader.Read();                 // opens, gets to xml declaration
            reader.Read();
            if ("Scenario" == reader.Name) // only Scenario can be top level
            {
                reader.Read();             // pass by "Scenario"
                while (!reader.EOF && !((XmlNodeType.EndElement == reader.NodeType) && ("Scenario" == reader.Name)))
                {
                    Console.WriteLine(".");

                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        Console.WriteLine("ELEMENT <{0}>", reader.Name);
                        switch (reader.Name)
                        {
                        case "Create_Event":
                            Create_EventType createEvent = parser.GetCreate_EventType();
                            TimerQueueClass.Add(createEvent.Timer, createEvent);
                            Console.WriteLine(" createEvent ");
                            break;

                        case "Move_Event":
                            Move_EventType moveEvent = parser.GetMove_EventType();
                            TimerQueueClass.Add(moveEvent.Timer, moveEvent);

                            Console.WriteLine(" moveEvent ");
                            break;

                        case "Completion_Event":
                            HappeningCompletionType completionType = parser.GetHappeningCompletionType();
                            HappeningList.Add(completionType);
                            break;

                        default:
                            Console.WriteLine(" Unknown Element is *{0}* ", reader.Name);


                            break;
                        }

                        break;

                    case XmlNodeType.Text:
                        Console.WriteLine("TEXT <{0}>", reader.Value);
                        break;

                    case XmlNodeType.CDATA:
                        Console.WriteLine("CDATA <![CDATA[{0}]]>", reader.Value);
                        break;

                    case XmlNodeType.ProcessingInstruction:
                        Console.WriteLine("PROC INS<?{0} {1}?>", reader.Name, reader.Value);
                        break;

                    case XmlNodeType.Comment:
                        Console.WriteLine("COMMENT <!--{0}-->", reader.Value);
                        break;

                    case XmlNodeType.XmlDeclaration:
                        Console.WriteLine("<?xml version='1.0'?>");
                        break;

                    case XmlNodeType.Document:
                        break;

                    case XmlNodeType.DocumentType:
                        Console.WriteLine("DOCTYPE <!DOCTYPE {0} [{1}]", reader.Name, reader.Value);
                        break;

                    case XmlNodeType.EntityReference:
                        Console.WriteLine(reader.Name);
                        break;

                    case XmlNodeType.EndElement:
                        Console.WriteLine("END ELEMENT </{0}>", reader.Name);
                        break;
                    }
                }
            }

            Console.WriteLine("Done\n");
        }