private PageToDownloadFactory(PageDownloadContext downloadContext, Control parentControl) { _context = downloadContext; _parentControl = parentControl; }
/// <summary> /// Creates a new PageToDownloadFactory /// </summary> /// <param name="url">The url that represents the root page to download</param> /// <param name="downloadContext">Context that control factory behavior</param> /// <param name="parent">The control that should be used as a parent</param> public PageToDownloadFactory(string url, PageDownloadContext downloadContext, Control parent) : this(downloadContext, parent) { _url = url; }
/// <summary> /// Creates a new PageToDownloadFactory based upon an existing HTMLDocument /// </summary> /// <param name="lightWeightHTMLDocument">The HTMLDocument that represents this page</param> /// <param name="downloadContext">Context that control factory behavior</param> /// <param name="parent">The control that should be used as a parent</param> public PageToDownloadFactory(LightWeightHTMLDocument lightWeightHTMLDocument, PageDownloadContext downloadContext, Control parentControl) : this(downloadContext, parentControl) { _lightWeightHTMLDocument = lightWeightHTMLDocument; _url = lightWeightHTMLDocument.Url; }
private string DownloadTemplateFiles(string templateContents, string templateUrl, IProgressHost progress) { progress.UpdateProgress(Res.Get(StringId.ProgressDownloadingSupportingFiles)); FileBasedSiteStorage files = new FileBasedSiteStorage(_blogTemplateDir); // convert the string to a stream MemoryStream templateStream = new MemoryStream(); StreamWriter writer = new StreamWriter(templateStream, Encoding.UTF8); writer.Write(templateContents); writer.Flush(); templateStream.Seek(0, SeekOrigin.Begin); //read the stream into a lightweight HTML. Note that we use from LightWeightHTMLDocument.FromIHTMLDocument2 //instead of LightWeightHTMLDocument.FromStream because from stream improperly shoves a saveFrom declaration //above the docType (bug 289357) IHTMLDocument2 doc = HTMLDocumentHelper.StreamToHTMLDoc(templateStream, templateUrl, true); LightWeightHTMLDocument ldoc = LightWeightHTMLDocument.FromIHTMLDocument2(doc, templateUrl, true, false); PageDownloadContext downloadContext = new PageDownloadContext(0); ApplyCredentials(downloadContext, templateUrl); using (PageToDownloadFactory downloadFactory = new PageToDownloadFactory(ldoc, downloadContext, _parentControl)) { //calculate the dependent styles and resources ProgressTick tick = new ProgressTick(progress, 50, 100); downloadFactory.CreatePagesToDownload(tick); tick.UpdateProgress(100, 100); //download the dependent styles and resources tick = new ProgressTick(progress, 50, 100); PageAndReferenceDownloader downloader = new PageAndReferenceDownloader(downloadFactory.PagesToDownload, files); this.ApplyCredentials(downloader, templateUrl); downloader.Download(tick); tick.UpdateProgress(100, 100); //Expand out the relative paths in the downloaded HTML file with absolute paths. //Note: this is necessary so that template resources are not improperly resolved relative // to the location of the file the editor is editing. string blogTemplateFile = Path.Combine(_blogTemplateDir, files.RootFile); string origFile = blogTemplateFile + ".token"; File.Move(blogTemplateFile, origFile); string absPath = String.Format(CultureInfo.InvariantCulture, "file:///{0}/{1}", _blogTemplateDir.Replace('\\', '/'), downloader.PathToken); TextHelper.ReplaceInFile(origFile, downloader.PathToken, blogTemplateFile, absPath); File.Delete(origFile); //fix up the files FixupDownloadedFiles(blogTemplateFile, files, downloader.PathToken); //complete the progress. progress.UpdateProgress(100, 100); File.WriteAllText(blogTemplateFile + ".path", absPath); return blogTemplateFile; } }
private void ApplyCredentials(PageDownloadContext downloadContext, string url) { WinInetCredentialsContext credentialsContext = CreateCredentialsContext(url); if (credentialsContext != null && credentialsContext.CookieString != null) downloadContext.CookieString = credentialsContext.CookieString.Cookies; }