예제 #1
0
        public void HistoricalEvent_ChangeHFStateXML_Parses()
        {
            var world = LoadingWorld.GetTestWorld();
            var xdoc  = new XDocument(new XElement("historical_event",
                                                   new XElement("id", 0),
                                                   new XElement("year", 1),
                                                   new XElement("seconds72", -1),
                                                   new XElement("type", "change hf state"),
                                                   new XElement("hfid", 264),
                                                   new XElement("state", "settled"),
                                                   new XElement("site_id", -1),
                                                   new XElement("subregion_id", 4),
                                                   new XElement("feature_layer_id", -1),
                                                   new XElement("coords", "20,16")
                                                   )
                                      );


            var historicalevent = HistoricalEvent.Create(xdoc, world);

            Assert.AreEqual(historicalevent.Id, 0);
            Assert.AreEqual(historicalevent.Year, 1);
            Assert.AreEqual(HistoricalEvent.Types[historicalevent.Type], "change hf state");
            Assert.IsInstanceOfType(historicalevent, typeof(HE_ChangeHFState));
            var changehfstateEvent = historicalevent as HE_ChangeHFState;

            Assert.AreEqual(changehfstateEvent.HfId, 264);
            Assert.AreEqual(HE_ChangeHFState.States[changehfstateEvent.State.Value], "settled");
            Assert.IsNull(changehfstateEvent.SiteId);
            Assert.AreEqual(changehfstateEvent.SubregionId.Value, 4);
            Assert.IsNull(changehfstateEvent.FeatureLayerId);
            Assert.AreEqual(changehfstateEvent.Coords, new Point(20, 16));
        }
예제 #2
0
        public void HistoricalEvent_NewTypeXML_Parses()
        {
            var world = LoadingWorld.GetTestWorld();
            var xdoc  = new XDocument(new XElement("historical_event",
                                                   new XElement("id", 0),
                                                   new XElement("year", 1),
                                                   new XElement("seconds72", -1),
                                                   new XElement("type", "unknown event type")
                                                   )
                                      );

            var historicalevent = HistoricalEvent.Create(xdoc, world);

            Assert.AreEqual(historicalevent.Id, 0);
            Assert.AreEqual(historicalevent.Year, 1);
            Assert.IsInstanceOfType(historicalevent, typeof(HE_UnassessedEvent));
        }
예제 #3
0
        /// <summary>
        /// Now at the open tag of a single object in our XML, we want to dump the entire contents into an XDocument.
        ///   If we have a historical event or historical event collection we want to use their factory methods to create a new version of those with the given XDocument.
        ///   For all other object types we want to use their constructor to make a new object of that type.
        ///   In any case we add the object after making it to the appropriate dictionary.
        /// Individual object reads are separated out to allow us to work past failing to load any specific XML item for some weird reason.
        /// </summary>
        private static void LoadItem <T>(IDictionary <int, T> WorldList, World world, XmlReader xReader) where T : XMLObject
        {
            XDocument xdoc = null;

            try
            {
                xdoc = XDocument.Load(xReader.ReadSubtree());

                if (typeof(T) == typeof(HistoricalEvent))
                {
                    var evt = HistoricalEvent.Create(xdoc, world);
                    world.HistoricalEvents.Add(evt.ID, evt);
                }
                else if (typeof(T) == typeof(HistoricalEventCollection))
                {
                    var evtcol = HistoricalEventCollection.Create(xdoc, world);
                    world.HistoricalEventCollections.Add(evtcol.ID, evtcol);
                }
                else
                {
                    var WorldObject = (T)Activator.CreateInstance(typeof(T), new object[] { xdoc, world });
                    WorldList.Add(WorldObject.ID, WorldObject);
                }
            }
            catch (OutOfMemoryException e)
            {
                Program.Log(LogType.Error, "Error reading XML item: id\n" + e.Message);


                var fi = new FileInfo(_path);
                Program.Log(LogType.Error, "XML file is" + Math.Round(fi.Length / 1024f / 1024f / 1024f, 2) + " GB");

                Program.Log(LogType.Error, string.Format("Running {0} Bit World Viewer", (Environment.Is64BitProcess ? "64" : "32")));
                Program.Log(LogType.Error, string.Format("Running {0} Bit Operating System", (Environment.Is64BitOperatingSystem ? "64" : "32")));

                if (!Environment.Is64BitOperatingSystem) //Running 32 bit OS
                {
                    Program.Log(LogType.Error, "32 Bit World Viewer does not support Huge XML files");
                }
                else if (!Environment.Is64BitProcess) //Running 32 bit app in 64 bit OS
                {
                    Program.Log(LogType.Error, "Recommend using 64 Bit World Viewer");
                }
                else
                {
                    Program.Log(LogType.Error, "Please report Log");
                }


                MemoryFailureQuitParsing = true;
            }
            catch (Exception e)
            {
                try
                {
                    if (xdoc != null)
                    {
                        int id = Int32.Parse(((XElement)xdoc.Root.Nodes().ToArray()[1]).Value);

                        if (id < 0)
                        {
                            if (xdoc.Root.Name.LocalName == "historical_event")
                            {
                                if (!workflowDetected)
                                {
                                    Program.Log(LogType.Error,
                                                "Negative ID historical event.  Likely due to dfHack Workflow, ignoring\n" + xdoc);
                                    workflowDetected = true;
                                }
                            }
                            else if (xdoc.Root.Name.LocalName == "historical_figure")
                            {
                                if (!autochopDetected)
                                {
                                    Program.Log(LogType.Error,
                                                "Negative ID historical figure detected. Likely due to autochop, ignoring\n" + xdoc);
                                    autochopDetected = true;
                                }
                            }
                            else
                            {
                                Program.Log(LogType.Error,
                                            "Negative ID " + xdoc.Root.Name.LocalName + " detected. Unknown cause, ignoring\n" + xdoc);
                            }
                        }
                        else
                        {
                            Program.Log(LogType.Error, "Error reading XML item: id\n" + e.Message);
                        }
                    }
                }
                catch (Exception)
                {
                    Program.Log(LogType.Error, "Error reading XML item: id\n" + e.Message);
                    throw;
                }
            }
        }