Beispiel #1
0
        private void btnWriteCoordsData_Click(object sender, EventArgs e)
        {
            XmlDocument doc = XmlStore.ValidateXmlDoc("http://TeleportCalculator/TeleportSchema.xsd",
                                                      Settings.Default.XsdSchemataFolderName + @"\TeleportSchema.xsd",
                                                      Path.Combine(Application.StartupPath, Settings.Default.XmlCostsName));

            if (doc != null)
            {
                doc.Load(Path.Combine(Application.StartupPath, Settings.Default.XmlCostsName));
            }

            XmlNode teleportPointsNode = doc.DocumentElement;

            // Version check
            //
            if (teleportPointsNode.Attributes != null)
            {
                Console.WriteLine("Attributes");
                foreach (XmlAttribute attr in teleportPointsNode.Attributes)
                {
                    Console.WriteLine("{0}: {1}", attr.Name, attr.Value);
                    if (attr.Name == "Version")
                    {
                        if (!XmlStore.CheckCostsVersion(attr.Value))
                        {
                            MessageBox.Show("Version check failed");
                        }
                    }
                }
                Console.WriteLine();
            }
            else
            {
                throw new XmlException("File version is absent");
            }

            Console.WriteLine("{0}: {1}", teleportPointsNode.Name, teleportPointsNode.Value);


            // TeleportPoint enumeration
            //
            foreach (XmlNode teleportPointNode in teleportPointsNode.ChildNodes)
            {
                TeleportNode point = null;

                // Inner nodes
                //
                foreach (XmlNode teleportPointElementNode in teleportPointNode.ChildNodes)
                {
                    if (teleportPointElementNode.ChildNodes.Count == 1)
                    {
                        switch (teleportPointElementNode.Name)
                        {
                        case "ID":
                            point = database.Points[ushort.Parse(teleportPointElementNode.InnerText)];
                            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
                            nsmgr.AddNamespace("ab", teleportPointNode.NamespaceURI);
                            XmlNode absoluteXNode = teleportPointNode.SelectSingleNode("ab:AbsoluteX", nsmgr);
                            XmlNode absoluteYNode = teleportPointNode.SelectSingleNode("ab:AbsoluteY", nsmgr);
                            absoluteXNode.LastChild.Value = point.AbsoluteX.ToString("0.00000", CultureInfo.InvariantCulture.NumberFormat);
                            absoluteYNode.LastChild.Value = point.AbsoluteY.ToString("0.00000", CultureInfo.InvariantCulture.NumberFormat);

                            continue;

                            break;

                        default:
                            break;
                        }
                        Console.WriteLine("{0}: {1}", teleportPointElementNode.Name, teleportPointElementNode.InnerText);
                    }
                }
            }

            doc.Save(Path.Combine(Application.StartupPath, Settings.Default.XmlCostsName));
            MessageBox.Show("File successfully saved");
        }
 protected Database()
 {
     db = XmlStore.Instance();
 }