/// <summary> /// /// </summary> /// <param name="progress"></param> /// <param name="targetTemplateTypes"></param> /// <param name="templateStrategies">equivalent strategies for manipulating the blog homepage DOM into an editing template type</param> /// <returns></returns> private BlogEditingTemplateFile[] DetectTemplates(IProgressHost progress, BlogEditingTemplateType[] targetTemplateTypes, BlogEditingTemplateStrategy[] templateStrategies) { RecentPostRegionLocatorStrategy recentPostLocatorStrategy = new RecentPostRegionLocatorStrategy(_blogClient, _blogAccount, _credentials, _blogHomepageUrl, new PageDownloader(RequestPageDownload)); TemporaryPostRegionLocatorStrategy tempPostLocatorStrategy = new TemporaryPostRegionLocatorStrategy(_blogClient, _blogAccount, _credentials, _blogHomepageUrl, new PageDownloader(RequestPageDownload), new BlogPostRegionLocatorBooleanCallback(recentPostLocatorStrategy.HasBlogPosts)); //setup the strategies for locating the title/body regions in the blog homepage. BlogPostRegionLocatorStrategy[] regionLocatorStrategies = new BlogPostRegionLocatorStrategy[] { recentPostLocatorStrategy, tempPostLocatorStrategy }; // template files to return BlogEditingTemplateFile[] blogTemplateFiles = null; // try each strategy as necessary for (int i = 0; i < regionLocatorStrategies.Length && blogTemplateFiles == null; i++) { CheckCancelRequested(progress); //reset the progress for each iteration BlogPostRegionLocatorStrategy regionLocatorStrategy = regionLocatorStrategies[i]; try { blogTemplateFiles = GetBlogTemplateFiles(progress, regionLocatorStrategy, templateStrategies, targetTemplateTypes, _blogHomepageUrl); progress.UpdateProgress(100, 100); //if any exception occurred along the way, clear them since one of the template strategies //was successful. _exception = null; } catch (OperationCancelledException) { // cancel just means our template will be String.Empty _exception = null; } catch (BlogClientOperationCancelledException e) { // cancel just means our template will be String.Empty // (setting this exception here means that at least the user // will be notified that they won't be able to edit with style) _exception = e; } catch (BlogClientAbortGettingTemplateException e) { _exception = e; //Do not proceed with the other strategies if getting the template was aborted. break; } catch (WebException e) { _exception = e; Trace.WriteLine("Error occurred while downloading weblog style: " + e.ToString()); if (e.Response != null) { Trace.WriteLine(String.Format(CultureInfo.InvariantCulture, "Blogpost homepage request failed: {0}", _blogHomepageUrl)); //Debug.WriteLine(HttpRequestHelper.DumpResponse((HttpWebResponse)e.Response)); } } catch (Exception e) { _exception = e; Trace.WriteLine("Error occurred while downloading weblog style: " + e.ToString()); } } // return the detected templates return(blogTemplateFiles); }
/// <summary> /// /// </summary> /// <param name="progress"></param> /// <param name="targetTemplateTypes"></param> /// <param name="templateStrategies">equivalent strategies for manipulating the blog homepage DOM into an editing template type</param> /// <returns></returns> private BlogEditingTemplateFile[] DetectTemplates(IProgressHost progress, BlogEditingTemplateType[] targetTemplateTypes, BlogEditingTemplateStrategy[] templateStrategies) { RecentPostRegionLocatorStrategy recentPostLocatorStrategy = new RecentPostRegionLocatorStrategy(_blogClient, _blogAccount, _credentials, _blogHomepageUrl, new PageDownloader(RequestPageDownload)); TemporaryPostRegionLocatorStrategy tempPostLocatorStrategy = new TemporaryPostRegionLocatorStrategy(_blogClient, _blogAccount, _credentials, _blogHomepageUrl, new PageDownloader(RequestPageDownload), new BlogPostRegionLocatorBooleanCallback(recentPostLocatorStrategy.HasBlogPosts)); //setup the strategies for locating the title/body regions in the blog homepage. BlogPostRegionLocatorStrategy[] regionLocatorStrategies = new BlogPostRegionLocatorStrategy[] { recentPostLocatorStrategy, tempPostLocatorStrategy }; // template files to return BlogEditingTemplateFile[] blogTemplateFiles = null; // try each strategy as necessary for (int i = 0; i < regionLocatorStrategies.Length && blogTemplateFiles == null; i++) { CheckCancelRequested(progress); //reset the progress for each iteration BlogPostRegionLocatorStrategy regionLocatorStrategy = regionLocatorStrategies[i]; try { blogTemplateFiles = GetBlogTemplateFiles(progress, regionLocatorStrategy, templateStrategies, targetTemplateTypes); progress.UpdateProgress(100, 100); //if any exception occured along the way, clear them since one of the template strategies //was successful. _exception = null; } catch (OperationCancelledException) { // cancel just means our template will be String.Empty _exception = null; } catch (BlogClientOperationCancelledException e) { // cancel just means our template will be String.Empty // (setting this exception here means that at least the user // will be notified that they won't be able to edit with style) _exception = e; } catch (WebException e) { _exception = e; Trace.WriteLine("Error occurred while downloading weblog style: " + e.ToString()); if (e.Response != null) { Trace.WriteLine(String.Format(CultureInfo.InvariantCulture, "Blogpost homepage request failed: {0}", _blogHomepageUrl)); //Debug.WriteLine(HttpRequestHelper.DumpResponse((HttpWebResponse)e.Response)); } } catch (Exception e) { _exception = e; Trace.WriteLine("Error occurred while downloading weblog style: " + e.ToString()); } } // return the detected tempaltes return blogTemplateFiles; }