Example #1
0
        public void TextDataManagerGetOneException(int NodeID, int?expected)
        {
            IServiceCall service = new NodeServiceCall();
            GraphNode    g       = (GraphNode)service.GetOne(NodeID, ServiceURI);

            Assert.That(expected, Is.EqualTo(g));
        }
Example #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();
        }