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();
        }