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(); }
public void TextDataManagerAddUpdateDelete() { IServiceCall service = new NodeServiceCall(); GraphNode newnode = new GraphNode(); newnode.Label = "TESTING"; newnode.NodeID = 100; newnode.AdjacentNodes = new List <GraphAdjacentNode>(); var result = service.Add(newnode, ServiceURI); Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode)); result = service.Update(newnode, ServiceURI); Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode)); result = service.Delete(100, ServiceURI); Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode)); }