//Author: Zuko Mgwili //Date: 19/06/2012 //Purpose of the method is to return source name and type private string GetSourceResourceAsXml(string source, dynamic serviceData) { var doc = new XmlDocument(); doc.LoadXml(source); XmlNodeList list = doc.ChildNodes; XmlNode root = list[0]; XmlNodeList sourceItem = root.ChildNodes; foreach(XmlNode node in sourceItem) { dynamic serviceInfo = new UnlimitedObject("Dev2Resource"); if(node.Name.Equals("Source")) { if (node.Attributes != null) { serviceInfo.Dev2SourceName = node.Attributes["Name"].Value; serviceInfo.Dev2SourceType = node.Attributes["Type"].Value; } serviceInfo.Dev2SourceContents = node.OuterXml; serviceData.AddResponse(serviceInfo); } } return serviceData.XmlString; }
//Author: Zuko Mgwili //Date: 18/06/2012 //Purpose of the method is to return worker service name and worker service category private string GetWorkerServiceResourceAsXml(string source, dynamic serviceData) { var doc = new XmlDocument(); doc.LoadXml(source); XmlNodeList list = doc.ChildNodes; XmlNode root = list[0]; XmlNodeList workerServices = root.ChildNodes; foreach(XmlNode node in workerServices) { dynamic serviceInfo = new UnlimitedObject("Dev2Resource"); if(node.Name.Equals("Service")) { if (node.Attributes != null) { serviceInfo.Dev2WorkerService = node.Attributes["Name"].Value; } XmlNode tmpNode = node.SelectSingleNode("//Category"); if(tmpNode != null) { serviceInfo.Dev2WorkerServiceCategory = tmpNode.InnerText; } //serviceInfo.Dev2WorkerServiceCategory = node.ChildNodes[3].InnerText; serviceInfo.Dev2WorkerServiceContents = node.OuterXml; serviceData.AddResponse(serviceInfo); } } return serviceData.XmlString; }
// Travis : Fixed all of Zuko's crap service defs private string GetAllDefsAsXML(string source, dynamic serviceData) { var doc = new XmlDocument(); doc.LoadXml(source); XmlNodeList list = doc.ChildNodes; XmlNode root = list[0]; XmlNodeList workerServices = root.ChildNodes; foreach(XmlNode node in workerServices) { dynamic serviceInfo = new UnlimitedObject("Dev2Resource"); if(node.Name.Equals("Service")) { if (node.Attributes != null) { serviceInfo.Dev2WorkerService = node.Attributes["Name"].Value; } XmlNode tmpNode = // ReSharper disable ReplaceWithSingleCallToFirstOrDefault node.ChildNodes.OfType<XmlNode>().Where(x => x.Name == "Category").FirstOrDefault(); // ReSharper restore ReplaceWithSingleCallToFirstOrDefault if(tmpNode != null) { serviceInfo.Dev2WorkerServiceCategory = tmpNode.InnerText; } serviceInfo.Dev2WorkerServiceContents = node.OuterXml; serviceData.AddResponse(serviceInfo); } else if(node.Name.Equals("Source")) { if (node.Attributes != null) { serviceInfo.Dev2WorkerService = node.Attributes["Name"].Value; } XmlNode tmpNode = node.ChildNodes.OfType<XmlNode>().Where(x => x.Name == "Category").FirstOrDefault(); if(tmpNode != null) { serviceInfo.Dev2WorkerServiceCategory = tmpNode.InnerText; } serviceInfo.Dev2SourceContents = node.OuterXml; serviceData.AddResponse(serviceInfo); } } return serviceData.XmlString; }
private string GetResourceNameAsXml(string source, dynamic serviceData) { XElement elements = XElement.Parse(source); elements.Descendants() .Where(node => node.Descendants().All(c => c.Name.LocalName == "XamlDefinition")) .Remove(); elements.DescendantsAndSelf().Where(node => node.Name.LocalName == "DataList").Remove(); elements.DescendantsAndSelf().Where(node => node.Name.LocalName == "Plugin").Remove(); if(elements.HasElements) { //foreach(XElement element in elements.Elements()) //{ // //dynamic orphan = GetResourceNameAsXml(element.ToString(), serviceData); // //serviceData.Dev2Service = orphan; //} } while(elements.HasAttributes) { XAttribute attrib = elements.LastAttribute; dynamic serviceInfo = new UnlimitedObject("Dev2Resource"); if(attrib.Name == "Name") { serviceInfo.Dev2ResourceName = attrib.Value; serviceData.AddResponse(serviceInfo); } attrib.Remove(); } return serviceData.XmlString; }