private bool ValidateNoParameters(TextBox textBoxEntry)
        {
            // pick out the <param> values in the server url string
            string parameters = BlogProviderParameters.ExtractParameterList(textBoxEntry.Text.Trim());

            // if there are values then tell the user they must fill them in
            if (parameters.Length > 0)
            {
                DisplayMessage.Show(MessageId.ServerParameterNotSpecified, textBoxEntry.FindForm(), parameters.ToString());
                textBoxEntry.Focus();
                return(false);
            }
            else
            {
                return(true);
            }
        }
コード例 #2
0
        protected override object DetectBlogService(IProgressHost progressHost)
        {
            using (BlogClientUIContextSilentMode uiContextScope = new BlogClientUIContextSilentMode()) //suppress prompting for credentials
            {
                try
                {
                    // get the weblog homepage and rsd service description if available
                    IHTMLDocument2 weblogDOM = GetWeblogHomepageDOM(progressHost);

                    // while we have the DOM available, scan for a writer manifest url
                    if (_manifestDownloadInfo == null)
                    {
                        string manifestUrl = WriterEditingManifest.DiscoverUrl(_homepageUrl, weblogDOM);
                        if (manifestUrl != String.Empty)
                        {
                            _manifestDownloadInfo = new WriterEditingManifestDownloadInfo(manifestUrl);
                        }
                    }

                    string html = weblogDOM != null?HTMLDocumentHelper.HTMLDocToString(weblogDOM) : null;

                    bool detectionSucceeded = false;

                    if (!detectionSucceeded)
                    {
                        detectionSucceeded = AttemptGenericAtomLinkDetection(_homepageUrl, html, !ApplicationDiagnostics.PreferAtom);
                    }

                    if (!detectionSucceeded && _blogSettings.IsGoogleBloggerBlog)
                    {
                        detectionSucceeded = AttemptBloggerDetection(_homepageUrl, html);
                    }

                    if (!detectionSucceeded)
                    {
                        RsdServiceDescription rsdServiceDescription = GetRsdServiceDescription(progressHost, weblogDOM);

                        // if there was no rsd service description or we fail to auto-configure from the
                        // rsd description then move on to other auto-detection techniques
                        if (!(detectionSucceeded = AttemptRsdBasedDetection(progressHost, rsdServiceDescription)))
                        {
                            // try detection by analyzing the homepage url and contents
                            UpdateProgress(progressHost, 75, Res.Get(StringId.ProgressAnalyzingHomepage));
                            if (weblogDOM != null)
                            {
                                detectionSucceeded = AttemptHomepageBasedDetection(_homepageUrl, html);
                            }
                            else
                            {
                                detectionSucceeded = AttemptUrlBasedDetection(_homepageUrl);
                            }

                            // if we successfully detected then see if we can narrow down
                            // to a specific weblog
                            if (detectionSucceeded)
                            {
                                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();
                                }
                            }
                        }
                    }

                    if (!detectionSucceeded && html != null)
                    {
                        AttemptGenericAtomLinkDetection(_homepageUrl, html, false);
                    }

                    // finished
                    UpdateProgress(progressHost, 100, String.Empty);
                }
                catch (OperationCancelledException)
                {
                    // WasCancelled == true
                }
                catch (BlogClientOperationCancelledException)
                {
                    Cancel();
                    // WasCancelled == true
                }
                catch (BlogAccountDetectorException ex)
                {
                    if (ApplicationDiagnostics.AutomationMode)
                    {
                        Trace.WriteLine(ex.ToString());
                    }
                    else
                    {
                        Trace.Fail(ex.ToString());
                    }
                    // ErrorOccurred == true
                }
                catch (Exception ex)
                {
                    // ErrorOccurred == true
                    Trace.Fail(ex.Message, ex.ToString());
                    ReportError(MessageId.WeblogDetectionUnexpectedError, ex.Message);
                }

                return(this);
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        public override async Task <object> DetectBlogService(IProgressHost progressHost, IEnumerable <IBlogProvider> availableProviders)
        {
            //using ( BlogClientUIContextSilentMode uiContextScope = new BlogClientUIContextSilentMode() ) //supress prompting for credentials
            //{
            try
            {
                // get the weblog homepage and rsd service description if available
                var weblogDOM = await GetWeblogHomepageDOM(progressHost);

                // while we have the DOM available, scan for a writer manifest url
                //if ( _manifestDownloadInfo == null )
                //{
                //	string manifestUrl = WriterEditingManifest.DiscoverUrl(_homepageUrl, weblogDOM) ;
                //	if ( manifestUrl != String.Empty )
                //		_manifestDownloadInfo = new WriterEditingManifestDownloadInfo(manifestUrl);
                //}

                string html = weblogDOM?.Body;

                bool detectionSucceeded = false;

                if (!detectionSucceeded)
                {
                    detectionSucceeded = AttemptGenericAtomLinkDetection(_homepageUrl, html, !ApplicationDiagnostics.PreferAtom);
                }

                if (!detectionSucceeded)
                {
                    detectionSucceeded = await AttemptBloggerDetection(_homepageUrl, html);
                }

                if (!detectionSucceeded)
                {
                    RsdServiceDescription rsdServiceDescription = await GetRsdServiceDescription(progressHost, weblogDOM);

                    // if there was no rsd service description or we fail to auto-configure from the
                    // rsd description then move on to other auto-detection techniques
                    detectionSucceeded = await AttemptRsdBasedDetection(progressHost, rsdServiceDescription, availableProviders);

                    if (!detectionSucceeded)
                    {
                        // try detection by analyzing the homepage url and contents
                        UpdateProgress(progressHost, 75, "Analysing homepage...");
                        if (weblogDOM != null)
                        {
                            detectionSucceeded = AttemptHomepageBasedDetection(_homepageUrl, html, availableProviders);
                        }
                        else
                        {
                            detectionSucceeded = AttemptUrlBasedDetection(_homepageUrl, availableProviders);
                        }

                        // if we successfully detected then see if we can narrow down
                        // to a specific weblog
                        if (detectionSucceeded)
                        {
                            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, "Analysing weblog list");
                                await AttemptUserBlogDetectionAsync();
                            }
                        }
                    }
                }

                if (!detectionSucceeded && html != null)
                {
                    AttemptGenericAtomLinkDetection(_homepageUrl, html, false);
                }

                // finished
                UpdateProgress(progressHost, 100, String.Empty);
            }
            //catch( OperationCancelledException )
            //{
            //	// WasCancelled == true
            //}
            //catch ( BlogClientOperationCancelledException )
            //{
            //	Cancel();
            //	// WasCancelled == true
            //}
            catch (BlogAccountDetectorException ex)
            {
                //if (ApplicationDiagnostics.AutomationMode)
                //    Trace.WriteLine(ex.ToString());
                //else
                //    Trace.Fail(ex.ToString());
                //ErrorOccurred = true;
            }
            catch (Exception ex)
            {
                // ErrorOccurred == true
                //Trace.Fail(ex.Message, ex.ToString());
                ReportError(MessageId.WeblogDetectionUnexpectedError, ex.Message);
            }

            return(this);
            //}
        }