Example #1
0
        internal List <XmlFile> GetAllAttachments(string rootLocalPath, string rootUrl)
        {
            WebResourceLoader webResourceLoader   = new WebResourceLoader();
            List <XmlFile>    attachmentData      = new List <XmlFile>();
            List <string>     filepaths           = this.GetWadlfileList(rootLocalPath);
            List <string>     resourcePathsSingle = this.FindAttachments(filepaths);
            List <string>     resourcePathsDouble = this.DublicateData(resourcePathsSingle);
            List <string>     attachmentNames     = this.GetAttachmentNames(resourcePathsSingle);
            List <string>     attachmentPaths     = this.AttachmentPathGen(resourcePathsDouble);
            List <string>     attachmentUrls      = WebResourceLoader.GetAttachmentUrls(attachmentNames, resourcePathsDouble, rootUrl);

            attachmentData = webResourceLoader.FetchMultipleXmlAndSaveToDisk(attachmentUrls, attachmentPaths, attachmentNames, 10).Result;
            foreach (XmlFile attachment in attachmentData)
            {
                attachment.Attachment = true;
            }

            return(attachmentData);
        }
Example #2
0
        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();
        }
Example #3
0
        private static void Main(string[] args)
        {
            WebResourceLoader webResourceLoader = new WebResourceLoader();
            var rootXmlDocument = new XDocument();
            // XmlIO xmlIO = new XmlIO();
            // List<string> localPathList = new List<string>();
            string rootUrl       = "https://intensapp003.internal.visma.com/rest/";
            string rootLocalPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\rest\\";
            // string rootXmlString = webResourceLoader.FetchSiteAsString(rootUrl + "/rest/").Result;
            // rootXmlDocument = XDocument.Parse(rootXmlString);
            // xmlIO.SaveXmlDocument(rootXmlDocument, rootLocalPath, "rest.xml");
            List <Link> links = new List <Link>();

            WebResponse myResponse = GetResponseFromSite(rootUrl);
            Stream      myStream   = myResponse.GetResponseStream();
            XmlReader   xmlReader  = XmlReader.Create(myStream);

            Console.WriteLine(rootLocalPath);

            string localPath = rootLocalPath;

            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;

                                GetCorrectFilename(ref desc);
                            }
                        }

                        localPath += desc + "\\";

                        Directory.CreateDirectory(localPath);
                        Console.WriteLine(localPath);
                    }
                    else if (xmlReader.Name == "link")
                    {
                        Link tempLink = new Link();
                        while (xmlReader.NodeType != XmlNodeType.Text)
                        {
                            xmlReader.Read();
                        }

                        tempLink.Href = xmlReader.Value;

                        while (xmlReader.NodeType != XmlNodeType.Text)
                        {
                            xmlReader.Read();
                        }

                        tempLink.Description = xmlReader.Value;

                        tempLink.Filepath = localPath;

                        links.Add(tempLink);
                    }

                    // 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 + "\\";
                    }

                    // Console.WriteLine("END " + xmlReader.Name);
                    break;
                }
            }
            xmlReader.Close();
            myResponse.Close();

            // List of Links is ready

            //LinkList linkList = XmlToLinkList(rootXmlDocument);

            List <string> serverXmlPath = new List <string>();
            List <string> localFilePath = new List <string>();
            List <string> localFileName = new List <string>();

            foreach (Link link in links)
            {
                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);
            }

            webResourceLoader.FetchMultipleXmlAndSaveToDisk(serverXmlPath, localFilePath, localFileName, 60).Wait();

            Console.WriteLine("Complete!");
            Console.ReadKey();
        }
Example #4
0
        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);
        }