Exemplo n.º 1
0
        public WebFile(Builder parent, string url, Builder.FileStorage st)
        {
            _Builder = parent;

            if (!string.IsNullOrEmpty(url))
            {
                Url = url;
            }

            Storage = st;
        }
Exemplo n.º 2
0
        public WebFile(Builder parent, Builder.FileStorage st, params string[] HTMLData)
        {
            Storage = st;

            _Builder = parent;

            if (HTMLData.Length > 0)
            {
                if (!string.IsNullOrEmpty(HTMLData[0]))
                {
                    setDownLoadedBytes(HTMLData[0]);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// download ALL externally referenced files in this file's html, potentially recursively,
        /// to the default download path for this page
        /// </summary>
        public void DownloadExternalFiles(Builder.FileStorage st, params bool[] recursive)
        {
            bool recrsv = false;

            if (recursive.Length != 0)
            {
                recrsv = recursive[0];
            }

            DownloadExternalFiles(st, ExternalFilesFolder, recrsv);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Download a single externally referenced file (if we haven't already downloaded it)
        /// </summary>
        private void DownloadExternalFile(string url, Builder.FileStorage st, string targetFolder,
                                          params bool[] recursive)
        {
            bool recrsv = false;
            WebFile wf = default(WebFile);
            bool isNew = false;

            if (recursive.Length != 0)
            {
                recrsv = recursive[0];
            }

            //-- have we already downloaded (or attempted to) this file?
            if (_Builder.WebFiles.Contains(url) | _Builder.Url == url)
            {
                wf = (WebFile)_Builder.WebFiles[url];
                isNew = false;
            }
            else
            {
                wf = new WebFile(_Builder, url, st);
                isNew = true;
            }

            //-- if we're planning to store this file on disk, make sure we can
            if (st == Builder.FileStorage.DiskPermanent || st == Builder.FileStorage.DiskTemporary)
            {
                if (!Directory.Exists(targetFolder))
                {
                    Directory.CreateDirectory(targetFolder);
                }
                wf.DownloadFolder = targetFolder;
            }

            wf.Download();

            if (isNew)
            {
                //-- add this (possibly) downloaded file to our shared collection
                _Builder.WebFiles.Add(wf.UrlUnmodified, wf);

                //-- if this is an HTML file, it has dependencies of its own;
                //-- download them into a subfolder
                if ((wf.IsHtml || wf.IsCss) & recrsv)
                {
                    wf.DownloadExternalFiles(st, recrsv);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// download ALL externally referenced files in this html, potentially recursively
        /// to a specific download path
        /// </summary>
        private void DownloadExternalFiles(Builder.FileStorage st, string targetFolder, bool recursive)
        {
            NameValueCollection FileCollection = ExternalHtmlFiles();

            if (!FileCollection.HasKeys()) return;

            Debug.WriteLine("Downloading all external files collected from URL:");
            Debug.WriteLine("    " + Url);

            foreach (string Key in FileCollection.AllKeys)
            {
                DownloadExternalFile(FileCollection[Key], st, targetFolder, recursive);
            }
        }