private static void Main(string[] args) { // Sorry, we just didn't have enough time to make it pretty & readable XmlIO xmlIO = new XmlIO(); WebResourceLoader webResourceLoader = new WebResourceLoader(); AttachmentLoader attachmentLoader = new AttachmentLoader(); string rootUrl = ConfigurationManager.ConnectionStrings["Server"].ConnectionString; string rootLocalPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\rest\\"; List <XmlFile> wadlAndXmsData = new List <XmlFile>(); List <XmlFile> attachmentData = new List <XmlFile>(); List <Link> myLinks = WebResourceReader.MainReader(rootUrl, rootLocalPath); List <string> serverXmlPath = new List <string>(); List <string> localFilePath = new List <string>(); List <string> localFileName = new List <string>(); foreach (Link link in myLinks) { serverXmlPath.Add(rootUrl + link.Href.Substring(6) + link.Href.Substring(5) + ".wadl"); serverXmlPath.Add(rootUrl + link.Href.Substring(6) + link.Href.Substring(5) + ".xsd"); localFileName.Add(link.Href.Substring(6) + ".wadl"); localFileName.Add(link.Href.Substring(6) + ".xsd"); localFilePath.Add(link.Filepath); localFilePath.Add(link.Filepath); } try { wadlAndXmsData = webResourceLoader.FetchMultipleXmlAndSaveToDisk(serverXmlPath, localFilePath, localFileName, 10).Result; } catch (Exception ex) { Console.WriteLine(ex); } attachmentData = attachmentLoader.GetAllAttachments(rootLocalPath, rootUrl); Console.WriteLine("Complete!"); Console.ReadKey(); }
public static List <Link> MainReader(string url, ref string rootLocalPath) { List <Link> links = new List <Link>(); WebResourceLoader webResourceLoader = new WebResourceLoader(); WebResponse myResponse = webResourceLoader.GetResponseFromSite(url + "global/agentVersion").Result; Stream myStream = myResponse.GetResponseStream(); XmlReader xmlReader = XmlReader.Create(myStream); string value = string.Empty; while (xmlReader.Read()) { if (xmlReader.NodeType == XmlNodeType.Text) { value = xmlReader.Value; } } int index = value.LastIndexOf("."); string release = value.Substring(index + 1); value = value.Remove(index); index = value.LastIndexOf("."); string version = value.Substring(index + 1); rootLocalPath += version + "." + release + "\\"; string localPath = rootLocalPath; XmlIO xmlIO = new XmlIO(); xmlIO.CreateFolder(localPath); XmlWriter xmlWriter = XmlWriter.Create(localPath + "metadata.xml"); xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement("rest_api_metadata"); xmlWriter.WriteAttributeString("release", release); xmlWriter.WriteAttributeString("version", version); webResourceLoader = new WebResourceLoader(); myResponse = webResourceLoader.GetResponseFromSite(url).Result; myStream = myResponse.GetResponseStream(); xmlReader = XmlReader.Create(myStream); while (xmlReader.Read()) { switch (xmlReader.NodeType) { case XmlNodeType.Element: if (xmlReader.Name == "group") { string desc = string.Empty; while (xmlReader.NodeType != XmlNodeType.EndElement) { xmlReader.Read(); if (xmlReader.NodeType == XmlNodeType.Text) { desc = xmlReader.Value; FixFilename(ref desc); } } localPath += desc + "\\"; xmlIO.CreateFolder(localPath); //Console.WriteLine(localPath); xmlWriter.WriteStartElement("service_group"); xmlWriter.WriteAttributeString("name", desc); } else if (xmlReader.Name == "link") { Link tempLink = new Link(); while (xmlReader.NodeType != XmlNodeType.Text) { xmlReader.Read(); } tempLink.Href = xmlReader.Value; xmlReader.Read(); while (xmlReader.NodeType != XmlNodeType.Text) { xmlReader.Read(); } tempLink.Description = xmlReader.Value; tempLink.Filepath = localPath + tempLink.Href.Substring(5) + "//"; links.Add(tempLink); string name = tempLink.Href; int i = name.LastIndexOf("/"); name = name.Substring(i + 1); xmlWriter.WriteStartElement("service"); xmlWriter.WriteAttributeString("description", tempLink.Description); xmlWriter.WriteAttributeString("name", name); xmlWriter.WriteEndElement(); } // Console.WriteLine(xmlReader.Name + " EN"); // Console.WriteLine(xmlReader.Value + " EV"); break; case XmlNodeType.Text: // Console.WriteLine(xmlReader.Value + " TV"); break; case XmlNodeType.EndElement: if (xmlReader.Name == "group") { var lastFolder = Path.GetDirectoryName(localPath); var pathWithoutLastFolder = Path.GetDirectoryName(lastFolder); localPath = pathWithoutLastFolder + "\\"; xmlWriter.WriteEndElement(); } // Console.WriteLine("END " + xmlReader.Name); break; } } xmlReader.Close(); myResponse.Close(); xmlWriter.WriteEndDocument(); xmlWriter.Close(); return(links); }