private void ExecuteSitemapGeneration() { try { btnRun.Enabled = false; if (CheckDestinationExistence() != DialogResult.OK) { btnRun.Enabled = true; return; } filter = this.Filter; fileLocation = this.DestinationFolder; culture = Program.GetUICulture(); logger = new Logger() { OmitDuplicatedLog = true, }; bw = new BackgroundWorker() { WorkerReportsProgress = true, WorkerSupportsCancellation = true, }; generator = new SitemapGenerator(this.URL, this.bw) { LastModification = this.LastModification, ChangeFrequency = this.ChangeFrequency, Priority = this.Priority, FileEncoding = this.Encoding, GenerateHtmlFile = this.GenerateHtmlFile, GenerateXmlFile = this.GenerateXmlFile, IncludeNotFoundFiles = this.IncludeNotFoundFiles, Logger = this.logger, SpecifiedDate = this.dateTimePicker.Value, PageTitle = this.PageTitle, FromLocalFiles = this.FromLocalFiles, }; if (FromLocalFiles) { PathInfo localPathInfo = new PathInfo(this.URL, this.LocalPath); generator.LocalPathInfo = localPathInfo; } bw.DoWork += DoSitemapGenerationBackground; bw.RunWorkerAsync(); progressDialog = new ProgressDialog(bw); progressDialog.Progress = this.logger; progressDialog.Text = Resources.String19; ProgressDialogResult result = progressDialog.ShowDialog(); if (result == ProgressDialogResult.Success) { if (logger.LogIsEmpty) { ResultDialog resultDialog = new ResultDialog() { Text = Resources.String9, MainMessage = Resources.String10, Details = Resources.String12 + Environment.NewLine, Directory = this.DestinationFolder, Icon = SystemIcons.Information, Sound = System.Media.SystemSounds.Asterisk, }; resultDialog.ShowDialog(); } else { ResultDialog resultDialog = new ResultDialog() { Text = Resources.String9, MainMessage = Resources.String10, Details = Resources.String11 + Environment.NewLine + Environment.NewLine + logger.Log, Directory = this.DestinationFolder, Icon = SystemIcons.Information, Sound = System.Media.SystemSounds.Asterisk, }; resultDialog.ShowDialog(); } } else if (result == ProgressDialogResult.Failure) { ResultDialog resultDialog = new ResultDialog() { Directory = null, Text = Resources.String8, MainMessage = Resources.String13, Details = Resources.String11 + Environment.NewLine + Environment.NewLine + logger.Log, Icon = SystemIcons.Error, Sound = System.Media.SystemSounds.Hand, }; resultDialog.ShowDialog(); } } catch (Exception e) { ResultDialog resultDialog = new ResultDialog() { Directory = null, Text = Resources.String8, MainMessage = Resources.String13, Details = Resources.String11 + Environment.NewLine + Environment.NewLine + e.Message, Icon = SystemIcons.Hand, Sound = System.Media.SystemSounds.Hand, }; resultDialog.ShowDialog(); } finally { btnRun.Enabled = true; btnRun.Focus(); } }
public void Fetch(Encoding encoding, bool inquiryLastModified, bool fromLocal, PathInfo localPathInfo) { string url = fromLocal ? localPathInfo.LocalFilePathFor(Uri) : Uri.AbsoluteUri; WebRequest request = WebRequest.Create(url); using (WebResponse response = request.GetResponse()) { this.ContentType = response.ContentType; if (inquiryLastModified) { if (fromLocal) { FileInfo fi = new FileInfo(url); this.SavedDate = fi.LastWriteTime; } else { this.SavedDate = (response as HttpWebResponse).LastModified; } } } if (this.ContentType.Contains("text") || fromLocal) { HtmlAgilityPack.HtmlWeb web = new HtmlAgilityPack.HtmlWeb(); this.htmlDocument = new HtmlAgilityPack.HtmlDocument(); if (encoding == null) { web.AutoDetectEncoding = true; htmlDocument = web.Load(url); } else { web.AutoDetectEncoding = false; web.OverrideEncoding = encoding; htmlDocument = web.Load(url); } this.TitleElement = this.GetTitleElement(this.htmlDocument); this.H1Element = this.GetH1Element(this.htmlDocument); } }