예제 #1
0
        public void TestLoadXML(string input)
        {
            var xml = new System.Xml.XmlDocument();

            xml = new NodeXMLTool().LoadXML(input);
            Assert.That(new System.Xml.XmlDocument().GetType(), Is.EqualTo(xml.GetType()));
        }
예제 #2
0
        static void Main(string[] args)
        {
            XmlDocument xml = new XmlDocument();

            string[]     xmlfiles   = Directory.GetFiles(ConfigurationManager.AppSettings["InputXMLLocation"], "*.xml");
            string       serviceuri = ConfigurationManager.AppSettings["ServiceURI"];
            IServiceCall service    = new NodeServiceCall();
            XMLTool      xmltool    = new NodeXMLTool();

            // First check for any removed XML files. If a file exists in the database but not the
            // filesytem, delete it from the database.
            foreach (GraphNode n in (List <GraphNode>)service.GetAll(serviceuri))
            {
                if (xmlfiles.Where(d => Path.GetFileName(d) == n.InputFilename).Count() == 0)
                {
                    Console.WriteLine($"{n.InputFilename} no longer exists, removing from DB");
                    service.Delete(n.NodeID, serviceuri);
                }
            }

            // Now loop through the files to check for new/updated nodes
            foreach (string file in xmlfiles)
            {
                try
                {
                    xml = xmltool.LoadXML(file);
                }
                catch
                {
                    Console.WriteLine($"Unexpected error loading XML file {file}");
                    continue;
                }

                if (xml != null && xmltool.ValidateXML(xml))
                {
                    GraphNode nn = (GraphNode)xmltool.CreateGraphNodeFromXML(xml);

                    if ((GraphNode)service.GetOne(nn.NodeID, serviceuri) == null)
                    {
                        service.Add(nn, serviceuri);
                        Console.WriteLine($"Added {nn.InputFilename} : {nn.NodeID} : {nn.Label}");
                    }
                    else
                    {
                        service.Update(nn, serviceuri);
                        Console.WriteLine($"Updated {nn.InputFilename} : {nn.NodeID} : {nn.Label}");
                    }
                }
                else
                {
                    Console.WriteLine($"{file} is not a path to XML file or a valid XML document");
                }
            }

            Console.WriteLine($"Press enter to close");
            Console.ReadLine();
        }
예제 #3
0
        public void TestXMLStructure(string input, bool expected)
        {
            var xml = new System.Xml.XmlDocument();

            xml.LoadXml(input);
            bool IsValid = new NodeXMLTool().ValidateXML(xml);

            Assert.That(expected, Is.EqualTo(IsValid));
        }