Exemple #1
0
 private void ShowSchemaButton_Click(object sender, EventArgs e)
 {
     // Scheme view
     System.IO.StringWriter swXML = new System.IO.StringWriter();
     XmlDataSet.WriteXmlSchema(swXML);
     textBox1.Text = swXML.ToString();
 }
Exemple #2
0
        public void ProducesMetadata()
        {
            XmlDocument document = new XmlDocument();

            document.LoadXml("<root><rows><row a=\"42\" b=\"x\"><metadata xmlns=\"http://www.gallio.org/\"><entry key=\"Metadata\" value=\"abc\"/></metadata></row><row a=\"53\" b=\"y\"><metadata xmlns=\"http://www.gallio.org/\"><entry key=\"Metadata\" value=\"def\"/></metadata></row></rows></root>");

            XmlDataSet dataSet = new XmlDataSet(delegate { return(document); }, "//row", false);

            dataSet.DataLocationName = "<inline>";
            Assert.AreEqual("<inline>", dataSet.DataLocationName);

            DataBinding      binding = new DataBinding(null, "@a");
            List <IDataItem> items   = new List <IDataItem>(dataSet.GetItems(new DataBinding[] { binding }, true));

            Assert.AreEqual("42", ((XPathNavigator)items[0].GetValue(binding)).Value);
            PropertyBag map = DataItemUtils.GetMetadata(items[0]);

            Assert.AreEqual("<inline>", map.GetValue(MetadataKeys.DataLocation));
            Assert.AreEqual("abc", map.GetValue("Metadata"));

            Assert.AreEqual("53", ((XPathNavigator)items[1].GetValue(binding)).Value);
            map = DataItemUtils.GetMetadata(items[1]);
            Assert.AreEqual("<inline>", map.GetValue(MetadataKeys.DataLocation));
            Assert.AreEqual("def", map.GetValue("Metadata"));
        }
        /// <inheritdoc />
        protected override void PopulateDataSource(IPatternScope scope, DataSource dataSource, ICodeElementInfo codeElement)
        {
            var dataSet = new XmlDataSet(delegate { return(OpenXPathDocument(codeElement)); }, itemPath, IsDynamic);

            dataSet.DataLocationName = GetDataLocationName();

            dataSource.AddDataSet(dataSet);
        }
Exemple #4
0
        static async Task <UpdateResult> DoUpdate(bool useMaster = false)
        {
            try
            {
                string tree;
                var    repo = XianxiaRepo;

                if (useMaster)
                {
                    tree = "master-wip";
                }
                else
                {
                    tree = await GitHubGetters.GetLatestVersion(repo);
                }
                var xmlPath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
                xmlPath = Path.Combine(xmlPath, XmlData.Files.Xianxia);
                XmlDataSet fileData = XmlData._LoadXmlData(xmlPath);

                if (useMaster == false)
                {
                    var currentVersion   = NuGetVersion.Parse(fileData.Version);
                    var availableVersion = NuGetVersion.Parse(tree);
                    //If current version is at or greater than the available version, return
                    if (VersionComparer.Compare(currentVersion, availableVersion, VersionComparison.Default) >= 0)
                    {
                        Console.WriteLine("Xianxia data file is current, no need for update");
                        return(UpdateResult.NoneNecessary);
                    }
                }
                if (await UpdateStatusEffects(repo, tree, fileData) != UpdateResult.UpdatedFiles)
                {
                    Console.WriteLine("Error! Could not parse status file!");
                    return(UpdateResult.Error);
                }
                if (await UpdateFlags(repo, tree, fileData) != UpdateResult.UpdatedFiles)
                {
                    Console.WriteLine("Error! Could not parse flag file!");
                    return(UpdateResult.Error);
                }
                fileData.Version = tree;
                if (XmlData._SaveXml(xmlPath, fileData) != XmlLoadingResult.Success)
                {
                    Console.WriteLine("Error! Could not save xml!");
                    return(UpdateResult.Error);
                }
                Console.WriteLine("saved xml!");
            }
            catch (Exception e)
            {
                Console.WriteLine("Error! " + e.ToString());
                return(UpdateResult.Error);
            }
            return(UpdateResult.UpdatedFiles);
        }
Exemple #5
0
        public void GetItemsReturnsNothingIfIsDynamicAndNotIncludingDynamicRows()
        {
            XmlDocument document = new XmlDocument();

            document.LoadXml("<root><rows><row a=\"42\"/></rows></root>");

            XmlDataSet       dataSet = new XmlDataSet(delegate { return(document); }, "//row", true);
            List <IDataItem> items   = new List <IDataItem>(dataSet.GetItems(EmptyArray <DataBinding> .Instance, false));

            Assert.Count(0, items);
        }
Exemple #6
0
        public void IsDynamicPropertyIsSameAsWasSpecifiedInTheConstructor(bool isDynamic)
        {
            XmlDocument document = new XmlDocument();

            document.LoadXml("<root><rows><row a=\"42\"/></rows></root>");

            XmlDataSet       dataSet = new XmlDataSet(delegate { return(document); }, "//row", isDynamic);
            List <IDataItem> items   = new List <IDataItem>(dataSet.GetItems(EmptyArray <DataBinding> .Instance, true));

            Assert.Count(1, items);
            Assert.AreEqual(isDynamic, items[0].IsDynamic);
        }
Exemple #7
0
        public void CanGetDescriptiveDataBindingsFromItem()
        {
            XmlDocument document = new XmlDocument();

            document.LoadXml("<root><rows><row a=\"42\" b=\"x\"/><row a=\"53\" b=\"y\"/></rows></root>");

            XmlDataSet       dataSet = new XmlDataSet(delegate { return(document); }, "//row", false);
            List <IDataItem> items   = new List <IDataItem>(dataSet.GetItems(EmptyArray <DataBinding> .Instance, true));

            Assert.AreElementsEqual(new[]
            {
                new DataBinding(null, ".")
            }, items[0].GetBindingsForInformalDescription());
        }
Exemple #8
0
        public void CanBindReturnsTrueIfAndOnlyIfTheColumnPathCanBeResolvedInTheDocument()
        {
            XmlDocument document = new XmlDocument();

            document.LoadXml("<root><rows><row a=\"42\"/><row a=\"53\"/></rows></root>");

            XmlDataSet dataSet = new XmlDataSet(delegate { return(document); }, "//row", false);

            Assert.IsFalse(dataSet.CanBind(new DataBinding(null, null)),
                           "CanBind should return false if there is no binding path.");
            Assert.IsFalse(dataSet.CanBind(new DataBinding(null, "not valid xpath")),
                           "CanBind should return false if the binding path is an invalid XPath expression.");
            Assert.IsFalse(dataSet.CanBind(new DataBinding(null, "@b")),
                           "CanBind should return false if the binding path cannot be resolved in the rows.");
            Assert.IsTrue(dataSet.CanBind(new DataBinding(null, "@a")),
                          "CanBind should return true if the binding path can be resolved in the rows.");
        }
Exemple #9
0
        static async Task <UpdateResult> UpdateFlags(string repo, string tree, XmlDataSet fileData)
        {
            var    file = XianxiaFlagsFile;
            string content;

            try
            {
                content = await GitHubGetters.GetContentFile(repo, tree, file);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error getting " + file + ":");
                Console.WriteLine(e);
                return(UpdateResult.Error);
            }
            XmlEnum[] flags = ParseFlags(content);
            fileData.Flags = flags;
            return(UpdateResult.UpdatedFiles);
        }
Exemple #10
0
        public void GetItemsReturnsXPathNavigatorsForAllSelectedValues()
        {
            XmlDocument document = new XmlDocument();

            document.LoadXml("<root><rows><row a=\"42\" b=\"x\"/><row a=\"53\" b=\"y\"/></rows></root>");

            XmlDataSet dataSet = new XmlDataSet(delegate { return(document); }, "//row", false);

            DataBinding[] bindings = new DataBinding[]
            {
                new DataBinding(null, "@a"),
                new DataBinding(null, "@b")
            };

            List <IDataItem> items = new List <IDataItem>(dataSet.GetItems(bindings, true));

            Assert.AreEqual("42", ((XPathNavigator)items[0].GetValue(bindings[0])).Value);
            Assert.AreEqual("x", ((XPathNavigator)items[0].GetValue(bindings[1])).Value);
            Assert.AreEqual("53", ((XPathNavigator)items[1].GetValue(bindings[0])).Value);
            Assert.AreEqual("y", ((XPathNavigator)items[1].GetValue(bindings[1])).Value);

            Assert.Throws <DataBindingException>(delegate { items[0].GetValue(new DataBinding(0, null)); });
            Assert.Throws <DataBindingException>(delegate { items[0].GetValue(new DataBinding(null, "not valid xpath")); });
        }
Exemple #11
0
        private void DownloadXmlButton_Click(object sender, EventArgs e)
        {
            // Dowloads files to data base
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    var filePath = openFileDialog1.FileName;
                    using (Stream str = openFileDialog1.OpenFile())
                    {
                        XmlDataSet.ReadXml(filePath);

                        dataGridView1.DataSource = XmlDataSet;
                        dataGridView1.DataMember = "Document";
                    }
                }
                catch (ApplicationException ex)
                {
                    // Show Error Message Box
                    MessageBox.Show($"Error!.\n\nError message: {ex.Message}\n\n" +
                                    $"Details:\n\n{ex.StackTrace}");
                }
            }
        }
Exemple #12
0
        public void ColumnCountIsZero()
        {
            XmlDataSet dataSet = new XmlDataSet(delegate { return(new XmlDocument()); }, "", false);

            Assert.AreEqual(0, dataSet.ColumnCount);
        }
Exemple #13
0
 //=====================================================================
 //  FunctionName : LoadXmlToDataSet
 /// <summary>
 /// 将XML文件读取为DataTable数据
 /// </summary>
 //=====================================================================
 public void LoadXmlToDataSet()
 {
     XmlDataSet.ReadXml(FileName);
 }
Exemple #14
0
 //=====================================================================
 //  FunctionName : SaveDataSetToXml
 /// <summary>
 /// 将DataTable数据保存为XML文件
 /// </summary>
 //=====================================================================
 public void SaveDataSetToXml()
 {
     XmlDataSet.WriteXml(FileName, XmlWriteMode.WriteSchema);
 }
Exemple #15
0
        static async Task <UpdateResult> UpdateStatusEffects(string repo, string tree, XmlDataSet fileData)
        {
            var    file = XianxiaStatusEffectsFile;
            string content;

            try
            {
                content = await GitHubGetters.GetContentFile(repo, tree, file);

                Dictionary <string, string> olddescs = new Dictionary <string, string>();
                //collect the old descriptions
                foreach (XmlNamedVector4 status in fileData.Statuses)
                {
                    if (status.Description != null && status.Description != "")
                    {
                        olddescs.Add(status.Name, status.Description);
                    }
                }
                var statusEffects = ParseStatusEffects(content, olddescs);
                if (statusEffects == null)
                {
                    return(UpdateResult.Error);
                }
                fileData.Statuses = statusEffects;
            }
            catch (Exception e)
            {
                Console.WriteLine("Error with getting/parsing " + file + ":");
                Console.WriteLine(e);
                return(UpdateResult.Error);
            }

            return(UpdateResult.UpdatedFiles);
        }