Esempio n. 1
0
        protected void AttemptUserBlogDetection()
        {
            BlogAccountDetector blogAccountDetector = new BlogAccountDetector(
                _clientType, _postApiUrl, _credentials);

            if (blogAccountDetector.ValidateService())
            {
                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);
            }
        }
Esempio n. 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);
            }
        }
Esempio n. 3
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 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);
            }
        }
        public override bool ValidatePanel()
        {
            // validate we have select a provider
            if (comboBoxSelectProvider.SelectedItem == BlogProviderDescriptionProxy.SelectProvider)
            {
                DisplayMessage.Show(MessageId.RequiredFieldOmitted, FindForm(), Res.Get(StringId.CWSelectProviderWeblogProvider));
                comboBoxSelectProvider.Focus();
                return false;
            }
            // validate that we have a post api url
            else if (textBoxServerApiUrl.Text.Trim() == String.Empty)
            {
                DisplayMessage.Show(MessageId.RequiredFieldOmitted, FindForm(), Res.Get(StringId.CWSelectProviderApiUrl));
                textBoxServerApiUrl.Focus();
                return false;
            }
            else if (!ValidateNoParameters(textBoxServerApiUrl))
            {
                return false;
            }
            else
            {
                using (new WaitCursor())
                {
                    IBlogProviderDescription provider = SelectedBlogProvider;
                    BlogAccountDetector blogAccountDetector = new BlogAccountDetector(
                        provider.ClientType, provider.PostApiUrl, new BlogCredentialsAccessor(_accountId, _credentials));

                    if (blogAccountDetector.ValidateService())
                    {
                        BlogInfo blogInfo = blogAccountDetector.DetectAccount(_homepageUrl, null);
                        if (blogInfo != null)
                            _targetBlog = blogInfo;
                        _usersBlogs = blogAccountDetector.UsersBlogs;
                        return true;
                    }
                    else
                    {
                        if (blogAccountDetector.ErrorMessageType != MessageId.None)
                            DisplayMessage.Show(blogAccountDetector.ErrorMessageType, FindForm(), blogAccountDetector.ErrorMessageParams);
                        textBoxServerApiUrl.Focus();
                        return false;
                    }
                }
            }
        }
Esempio n. 5
0
        private bool AttemptRsdBasedDetection(IProgressHost progressHost, RsdServiceDescription rsdServiceDescription)
        {
            // always return alse for null description
            if (rsdServiceDescription == null)
            {
                return(false);
            }

            string      providerId  = String.Empty;
            BlogAccount blogAccount = null;

            // check for a match on rsd engine link
            foreach (IBlogProvider provider in BlogProviderManager.Providers)
            {
                blogAccount = provider.DetectAccountFromRsdHomepageLink(rsdServiceDescription);
                if (blogAccount != null)
                {
                    providerId = provider.Id;
                    break;
                }
            }

            // if none found on engine link, match on engine name
            if (blogAccount == null)
            {
                foreach (IBlogProvider provider in BlogProviderManager.Providers)
                {
                    blogAccount = provider.DetectAccountFromRsdEngineName(rsdServiceDescription);
                    if (blogAccount != null)
                    {
                        providerId = provider.Id;
                        break;
                    }
                }
            }

            // No provider associated with the RSD file, try to gin one up (will only
            // work if the RSD file contains an API for one of our supported client types)
            if (blogAccount == null)
            {
                // try to create one from RSD
                blogAccount = BlogAccountFromRsdServiceDescription.Create(rsdServiceDescription);
            }

            // if we have an rsd-detected weblog
            if (blogAccount != null)
            {
                // confirm that the credentials are OK
                UpdateProgress(progressHost, 65, Res.Get(StringId.ProgressVerifyingInterface));
                BlogAccountDetector blogAccountDetector = new BlogAccountDetector(
                    blogAccount.ClientType, blogAccount.PostApiUrl, _credentials);

                if (blogAccountDetector.ValidateService())
                {
                    // copy basic account info
                    _providerId  = providerId;
                    _serviceName = blogAccount.ServiceName;
                    _clientType  = blogAccount.ClientType;
                    _hostBlogId  = blogAccount.BlogId;
                    _postApiUrl  = blogAccount.PostApiUrl;

                    // see if we can improve on the blog name guess we already
                    // have from the <title> element of the homepage
                    BlogInfo blogInfo = blogAccountDetector.DetectAccount(_homepageUrl, _hostBlogId);
                    if (blogInfo != null)
                    {
                        _blogName = blogInfo.Name;
                    }
                }
                else
                {
                    // report user-authorization error
                    ReportErrorAndFail(blogAccountDetector.ErrorMessageType, blogAccountDetector.ErrorMessageParams);
                }

                // success!
                return(true);
            }
            else
            {
                // couldn't do it
                return(false);
            }
        }
        protected void AttemptUserBlogDetection()
        {
            BlogAccountDetector blogAccountDetector = new BlogAccountDetector(
                _clientType, _postApiUrl, _credentials);

            if (blogAccountDetector.ValidateService())
            {
                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);
            }
        }
        private bool AttemptRsdBasedDetection(IProgressHost progressHost, RsdServiceDescription rsdServiceDescription)
        {
            // always return alse for null description
            if (rsdServiceDescription == null)
                return false;

            string providerId = String.Empty;
            BlogAccount blogAccount = null;

            // check for a match on rsd engine link
            foreach (IBlogProvider provider in BlogProviderManager.Providers)
            {
                blogAccount = provider.DetectAccountFromRsdHomepageLink(rsdServiceDescription);
                if (blogAccount != null)
                {
                    providerId = provider.Id;
                    break;
                }
            }

            // if none found on engine link, match on engine name
            if (blogAccount == null)
            {
                foreach (IBlogProvider provider in BlogProviderManager.Providers)
                {
                    blogAccount = provider.DetectAccountFromRsdEngineName(rsdServiceDescription);
                    if (blogAccount != null)
                    {
                        providerId = provider.Id;
                        break;
                    }
                }
            }

            // No provider associated with the RSD file, try to gin one up (will only
            // work if the RSD file contains an API for one of our supported client types)
            if (blogAccount == null)
            {
                // try to create one from RSD
                blogAccount = BlogAccountFromRsdServiceDescription.Create(rsdServiceDescription);
            }

            // if we have an rsd-detected weblog
            if (blogAccount != null)
            {
                // confirm that the credentials are OK
                UpdateProgress(progressHost, 65, Res.Get(StringId.ProgressVerifyingInterface));
                BlogAccountDetector blogAccountDetector = new BlogAccountDetector(
                    blogAccount.ClientType, blogAccount.PostApiUrl, _credentials);

                if (blogAccountDetector.ValidateService())
                {
                    // copy basic account info
                    _providerId = providerId;
                    _serviceName = blogAccount.ServiceName;
                    _clientType = blogAccount.ClientType;
                    _hostBlogId = blogAccount.BlogId;
                    _postApiUrl = blogAccount.PostApiUrl;

                    // see if we can improve on the blog name guess we already
                    // have from the <title> element of the homepage
                    BlogInfo blogInfo = blogAccountDetector.DetectAccount(_homepageUrl, _hostBlogId);
                    if (blogInfo != null)
                        _blogName = blogInfo.Name;
                }
                else
                {
                    // report user-authorization error
                    ReportErrorAndFail(blogAccountDetector.ErrorMessageType, blogAccountDetector.ErrorMessageParams);
                }

                // success!
                return true;
            }
            else
            {
                // couldn't do it
                return false;
            }
        }
        /// <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;
            }
        }