protected void CopySettingsFromProvider(IBlogProvider blogAccountProvider) { _providerId = blogAccountProvider.Id; _serviceName = blogAccountProvider.Name; _clientType = blogAccountProvider.ClientType; _postApiUrl = ProcessPostUrlMacros(blogAccountProvider.PostApiUrl); }
private bool AttemptUrlBasedDetection(string url, IEnumerable <IBlogProvider> availableBlogProviders) { // matched provider IBlogProvider blogAccountProvider = null; // do url-based matching foreach (IBlogProvider provider in availableBlogProviders) { if (provider.IsProviderForHomepageUrl(url)) { blogAccountProvider = provider; break; } } if (blogAccountProvider != null) { CopySettingsFromProvider(blogAccountProvider); return(true); } else { return(false); } }
public StorageController(IStorageProvider storageProvider, IAuthorProvider authorProvider, IBlogProvider blogProvider, IPostProvider postProvider) { _storageProvider = storageProvider; _authorProvider = authorProvider; _blogProvider = blogProvider; _postProvider = postProvider; }
private bool AttemptContentBasedDetection(string homepageContent) { // matched provider IBlogProvider blogAccountProvider = null; // do url-based matching foreach (IBlogProvider provider in BlogProviderManager.Providers) { if (provider.IsProviderForHomepageContent(homepageContent)) { blogAccountProvider = provider; break; } } if (blogAccountProvider != null) { CopySettingsFromProvider(blogAccountProvider); return(true); } else { return(false); } }
public HomeController(IBlogProvider blogProvider, IPostProvider postProvider, IFeedProvider feedProvider, IAuthorProvider authorProvider, IThemeProvider themeProvider, IStorageProvider storageProvider) { _blogProvider = blogProvider; _postProvider = postProvider; _feedProvider = feedProvider; _authorProvider = authorProvider; _themeProvider = themeProvider; _storageProvider = storageProvider; }
public IActionResult Blog(string seriesRef, string tag, [FromServices] IBlogProvider blogs) { return(View(new BlogIndexViewModel { Series = blogs.GetBlogSeries() .Where(s => seriesRef == null || s.Series.Reference == seriesRef) .Where(s => tag == null || s.Series.Tags.Contains(tag)), TagFilter = tag })); }
public Task Invoke(HttpContext httpContext, IBlogProvider blogs) { var post = blogs.GetBlogPostFromSeoUrlOrNull(httpContext.Request.Path, out int postIndex); if (post != null) { httpContext.Request.Path = $"/BlogPost/{post.Series.Reference}/{postIndex}"; } return(_next(httpContext)); }
public BlogController(IBlogProvider blogProvider, ISettingsProvider settingsProvider) { _blogProvider = blogProvider ?? throw new ArgumentNullException(nameof(blogProvider)); if (settingsProvider == null) { throw new ArgumentNullException(nameof(settingsProvider)); } _settings = settingsProvider.GetSettings <BlogSettings>(nameof(BlogSettings)); }
public HomeController(IBlogProvider blogProvider, IPostProvider postProvider, IFeedProvider feedProvider, IAuthorProvider authorProvider, IThemeProvider themeProvider, IStorageProvider storageProvider, ICompositeViewEngine compositeViewEngine) { _blogProvider = blogProvider; _postProvider = postProvider; _feedProvider = feedProvider; _authorProvider = authorProvider; _themeProvider = themeProvider; _storageProvider = storageProvider; _compositeViewEngine = compositeViewEngine; }
/// <summary> /// Do special Blogger-specific detection logic. We want to /// use the Blogger Atom endpoints specified in the HTML, not /// the Blogger endpoint in the RSD. /// </summary> private async Task <bool> AttemptBloggerDetection(string homepageUrl, string html) { html = html ?? ""; BloggerDetectionHelper bloggerDetectionHelper = new BloggerDetectionHelper(homepageUrl, html); if (!bloggerDetectionHelper.IsBlogger()) { return(false); } const string BLOGGER_ATOM_PROVIDER_ID = "B6F817C3-9D39-45c1-A634-EAC792B8A635"; IBlogProvider bloggerProvider = BlogProviderManager.FindProvider(BLOGGER_ATOM_PROVIDER_ID); if (bloggerProvider == null) { //Trace.Fail("Couldn't retrieve Blogger provider"); return(false); } _providerId = bloggerProvider.Id; _serviceName = bloggerProvider.Name; _clientType = bloggerProvider.ClientType; _postApiUrl = "http://www.blogger.com/feeds/default/blogs"; BlogAccountDetector blogAccountDetector = new BlogAccountDetector(bloggerProvider.ClientType, "http://www.blogger.com", _credentials); if (await blogAccountDetector.ValidateServiceAsync()) { _usersBlogs = blogAccountDetector.UsersBlogs; foreach (BlogInfo blog in _usersBlogs) { string blogHomepageUrl = blog.HomepageUrl; if (NormalizeBloggerHomepageUrl(blogHomepageUrl) == NormalizeBloggerHomepageUrl(homepageUrl)) { _hostBlogId = blog.Id; _postApiUrl = blog.Id; _blogName = blog.Name; return(true); } } // We didn't find the specific blog, but we'll prompt the user with the list of blogs return(true); } else { AuthenticationErrorOccurred = blogAccountDetector.Exception is BlogClientAuthenticationException; ReportErrorAndFail(blogAccountDetector.ErrorMessageType, blogAccountDetector.ErrorMessageParams); return(false); } }
public IActionResult BlogPost(string seriesRef, string postIndex, [FromServices] IBlogProvider blogs) { var series = blogs.GetBlogSeries().FirstOrDefault(s => s.Series.Reference == seriesRef); if (series == null) { return(Redirect("/Blog")); } BlogPost lastBlog = null; BlogPost currentBlog = null; BlogPost nextBlog = null; var postIndexNumString = postIndex.Split('-').FirstOrDefault(); // Allows SEO keywords after the post index. var isNumber = Int32.TryParse(postIndexNumString, out int postIndexValue); if (!isNumber) { return(Redirect($"/Blog/{seriesRef}")); } if (postIndexValue > 0 && series.Posts.Count > 1) { lastBlog = series.Posts[postIndexValue - 1]; } if (postIndexValue < series.Posts.Count) { currentBlog = series.Posts[postIndexValue]; } else { return(Redirect($"/Blog/{seriesRef}")); } if (postIndexValue < series.Posts.Count - 1) { nextBlog = series.Posts[postIndexValue + 1]; } return(View(new BlogPostViewModel { Series = series.Series, LastPost = lastBlog, CurrentPost = currentBlog, NextPost = nextBlog })); }
public static IBlogClient CreateClient(string clientType, string postApiUrl, IBlogCredentialsAccessor credentials, string providerId, IDictionary optionOverrides, IDictionary userOptionOverrides, IDictionary homepageOptionOverrides) { // create blog client reflecting the settings IBlogClient blogClient = CreateClient(clientType, postApiUrl, credentials); // if there is a provider associated with the client then use it to override options // as necessary for this provider IBlogProvider provider = BlogProviderManager.FindProvider(providerId); if (provider != null) { IBlogClientOptions providerOptions = provider.ConstructBlogOptions(blogClient.Options); blogClient.OverrideOptions(providerOptions); } if (homepageOptionOverrides != null) { OptionOverrideReader homepageOptionsReader = new OptionOverrideReader(homepageOptionOverrides); IBlogClientOptions homepageOptions = BlogClientOptions.ApplyOptionOverrides(new OptionReader(homepageOptionsReader.Read), blogClient.Options, true); blogClient.OverrideOptions(homepageOptions); } // if there are manifest overrides then apply them if (optionOverrides != null) { OptionOverrideReader manifestOptionsReader = new OptionOverrideReader(optionOverrides); IBlogClientOptions manifestOptions = BlogClientOptions.ApplyOptionOverrides(new OptionReader(manifestOptionsReader.Read), blogClient.Options, true); blogClient.OverrideOptions(manifestOptions); } // if there are user overrides then apply them if (userOptionOverrides != null) { OptionOverrideReader userOptionsReader = new OptionOverrideReader(userOptionOverrides); IBlogClientOptions userOptions = BlogClientOptions.ApplyOptionOverrides(new OptionReader(userOptionsReader.Read), blogClient.Options, true); blogClient.OverrideOptions(userOptions); } // return the blog client return(blogClient); }
public void DisplayException(IWin32Window owner, Exception ex) { // display a custom display message for exceptions that have one // registered, otherwise display the generic error form if (ex is BlogClientProviderException) { IBlogProvider provider = BlogProviderManager.FindProvider(_settings.ProviderId); if (provider != null) { BlogClientProviderException pe = ex as BlogClientProviderException; MessageId messageId = provider.DisplayMessageForProviderError(pe.ErrorCode, pe.ErrorString); if (messageId != MessageId.None) { DisplayMessage.Show(messageId, owner); return; } } } else if (ex is WebException) { WebException we = (WebException)ex; HttpWebResponse resp = we.Response as HttpWebResponse; if (resp != null) { string friendlyError = HttpRequestHelper.GetFriendlyErrorMessage(we); Trace.WriteLine("Server response body:\r\n" + friendlyError); ex = new BlogClientHttpErrorException( UrlHelper.SafeToAbsoluteUri(resp.ResponseUri), friendlyError, we); } else { DisplayMessage msg = new DisplayMessage(MessageId.ErrorConnecting); ex = new BlogClientException(msg.Title, msg.Text); } HttpRequestHelper.LogException(we); } // no custom message, use default UI DisplayableExceptionDisplayForm.Show(owner, ex); }
/// <summary> /// Do special Blogger-specific detection logic. We want to /// use the Blogger Atom endpoints specified in the HTML, not /// the Blogger endpoint in the RSD. /// </summary> private bool AttemptBloggerDetection(string homepageUrl, string html) { Debug.Assert(string.IsNullOrEmpty(homepageUrl), "Google Blogger blogs don't know the homepageUrl"); Debug.Assert(string.IsNullOrEmpty(html), "Google Blogger blogs don't know the homepageUrl"); const string BLOGGER_V3_PROVIDER_ID = "343F1D83-1098-43F4-AE86-93AFC7602855"; IBlogProvider bloggerProvider = BlogProviderManager.FindProvider(BLOGGER_V3_PROVIDER_ID); if (bloggerProvider == null) { Trace.Fail("Couldn't retrieve Blogger provider"); return(false); } BlogAccountDetector blogAccountDetector = new BlogAccountDetector(bloggerProvider.ClientType, bloggerProvider.PostApiUrl, _credentials); if (blogAccountDetector.ValidateService()) { CopySettingsFromProvider(bloggerProvider); _usersBlogs = blogAccountDetector.UsersBlogs; if (_usersBlogs.Length == 1) { _hostBlogId = _usersBlogs[0].Id; _blogName = _usersBlogs[0].Name; _homepageUrl = _usersBlogs[0].HomepageUrl; } // If we didn't find the specific blog, we'll prompt the user with the list of blogs return(true); } else { AuthenticationErrorOccurred = blogAccountDetector.Exception is BlogClientAuthenticationException; ReportErrorAndFail(blogAccountDetector.ErrorMessageType, blogAccountDetector.ErrorMessageParams); return(false); } }
/// <summary> /// Initializes the provider. /// </summary> /// <param name="providerString"> /// E.g. "Fan.Blogs.SqlBlogProvider, Fan.Blogs" /// </param> public static void Initialize(string providerString) { if (Provider == null) { lock (_lock) { if (Provider == null) { Provider = Activator.CreateInstance(Type.GetType(providerString)) as IBlogProvider; if (Provider == null) throw new ProviderException(string.Format("Failed to load '{0}'.", providerString)); } } } }
/// <summary> /// Default constructor /// </summary> /// <param name="blogProvider">IBlogProvider instance</param> public BlogSitemapProvider(IBlogProvider blogProvider) { _blogProvider = blogProvider ?? throw new ArgumentNullException(nameof(blogProvider)); }
public AssistantController(IBlogProvider blogProvider) { _blogProvider = blogProvider; }
public BlogSitemapProvider(IBlogProvider blogs) { this._blogs = blogs; }
public BlogSearchKeywordProvider(IBlogProvider blogProvider) { _blogProvider = blogProvider ?? throw new ArgumentNullException(nameof(blogProvider)); }
public BlogController(IBlogProvider blogProvider) { _blogProvider = blogProvider; }
protected void CopySettingsFromProvider(IBlogProvider blogAccountProvider) { _providerId = blogAccountProvider.Id; _serviceName = blogAccountProvider.Name; _clientType = blogAccountProvider.ClientType; _postApiUrl = ProcessPostUrlMacros(blogAccountProvider.PostApiUrl); }
protected override object DetectBlogService(IProgressHost progressHost) { using (BlogClientUIContextSilentMode uiContextScope = new BlogClientUIContextSilentMode()) //suppress prompting for credentials { try { // copy basic account info IBlogProvider provider = BlogProviderManager.FindProvider("4AA58E69-8C24-40b1-BACE-3BB14237E8F9"); _providerId = provider.Id; _serviceName = provider.Name; _clientType = provider.ClientType; //calculate the API url based on the homepage Url. // API URL Format: <blogurl>/_layouts/metaweblog.aspx string homepagePath = UrlHelper.SafeToAbsoluteUri(new Uri(_homepageUrl)).Split('?')[0]; if (homepagePath == null) { homepagePath = "/"; } //trim off any file information included in the URL (ex: /default.aspx) int lastPathPartIndex = homepagePath.LastIndexOf("/", StringComparison.OrdinalIgnoreCase); if (lastPathPartIndex != -1) { string lastPathPart = homepagePath.Substring(lastPathPartIndex); if (lastPathPart.IndexOf('.') != -1) { homepagePath = homepagePath.Substring(0, lastPathPartIndex); if (homepagePath == String.Empty) { homepagePath = "/"; } } } if (homepagePath != "/" && homepagePath.EndsWith("/", StringComparison.OrdinalIgnoreCase)) //trim off trailing slash { homepagePath = homepagePath.Substring(0, homepagePath.Length - 1); } //Update the homepage url _homepageUrl = homepagePath; _postApiUrl = String.Format(CultureInfo.InvariantCulture, "{0}/_layouts/metaweblog.aspx", homepagePath); if (VerifyCredentialsAndDetectAuthScheme(_postApiUrl, _blogCredentials, _credentials)) { AuthenticationErrorOccurred = false; //detect the user's blog ID. if (!BlogProviderParameters.UrlContainsParameters(_postApiUrl)) { // we detected the provider, now see if we can detect the weblog id // (or at lease the list of the user's weblogs) UpdateProgress(progressHost, 80, Res.Get(StringId.ProgressAnalyzingWeblogList)); AttemptUserBlogDetection(); } } else { AuthenticationErrorOccurred = true; } } catch (OperationCancelledException) { // WasCancelled == true } catch (BlogClientOperationCancelledException) { Cancel(); // WasCancelled == true } catch (BlogAccountDetectorException) { // ErrorOccurred == true } catch (BlogClientAuthenticationException) { AuthenticationErrorOccurred = true; // ErrorOccurred == true } catch (Exception ex) { // ErrorOccurred == true ReportError(MessageId.WeblogDetectionUnexpectedError, ex.Message); } } return(this); }
private bool AttemptGenericAtomLinkDetection(string url, string html, bool preferredOnly) { const string GENERIC_ATOM_PROVIDER_ID = "D48F1B5A-06E6-4f0f-BD76-74F34F520792"; if (html == null) { return(false); } HtmlExtractor ex = new HtmlExtractor(html); if (ex .SeekWithin("<head>", "<body>") .SeekWithin("<link href rel='service' type='application/atomsvc+xml'>", "</head>") .Success) { IBlogProvider atomProvider = BlogProviderManager.FindProvider(GENERIC_ATOM_PROVIDER_ID); BeginTag bt = ex.Element as BeginTag; if (preferredOnly) { string classes = bt.GetAttributeValue("class"); if (classes == null) { return(false); } if (!Regex.IsMatch(classes, @"\bpreferred\b")) { return(false); } } string linkUrl = bt.GetAttributeValue("href"); Debug.WriteLine("Atom service link detected in the blog homepage"); _providerId = atomProvider.Id; _serviceName = atomProvider.Name; _clientType = atomProvider.ClientType; _blogName = string.Empty; _postApiUrl = GetAbsoluteUrl(url, linkUrl); IBlogClient client = BlogClientManager.CreateClient(atomProvider.ClientType, _postApiUrl, _credentials); client.VerifyCredentials(); _usersBlogs = client.GetUsersBlogs(); if (_usersBlogs.Length == 1) { _hostBlogId = _usersBlogs[0].Id; _blogName = _usersBlogs[0].Name; /* * if (_usersBlogs[0].HomepageUrl != null && _usersBlogs[0].HomepageUrl.Length > 0) * _homepageUrl = _usersBlogs[0].HomepageUrl; */ } // attempt to read the blog name from the homepage title if (_blogName == null || _blogName.Length == 0) { HtmlExtractor ex2 = new HtmlExtractor(html); if (ex2.Seek("<title>").Success) { _blogName = ex2.CollectTextUntil("title"); } } return(true); } return(false); }