示例#1
0
        protected async Task AttemptUserBlogDetectionAsync()
        {
            BlogAccountDetector blogAccountDetector = new BlogAccountDetector(
                _clientType, _postApiUrl, _credentials);

            if (await blogAccountDetector.ValidateServiceAsync())
            {
                BlogInfo blogInfo = blogAccountDetector.DetectAccount(_homepageUrl, _hostBlogId);
                if (blogInfo != null)
                {
                    // save the detected info
                    // TODO: Commenting out next line for Spaces demo tomorrow.
                    // need to decide whether to keep it commented out going forward.
                    // _homepageUrl = blogInfo.HomepageUrl;
                    _hostBlogId = blogInfo.Id;
                    _blogName   = blogInfo.Name;
                }

                // always save the list of user's blogs
                _usersBlogs = blogAccountDetector.UsersBlogs;
            }
            else
            {
                AuthenticationErrorOccurred = blogAccountDetector.Exception is BlogClientAuthenticationException;
                ReportErrorAndFail(blogAccountDetector.ErrorMessageType, blogAccountDetector.ErrorMessageParams);
            }
        }
示例#2
0
        /// <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);
            }
        }