Beispiel #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);
            }
        }
        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;
                    }
                }
            }
        }
        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);
            }
        }
Beispiel #4
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);
            }
        }
        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;
            }
        }