Exemplo n.º 1
0
        private object DetectWeblogSettings(IProgressHost progressHost)
        {
            using (BlogClientUIContextSilentMode uiContextScope = new BlogClientUIContextSilentMode()) //suppress prompting for credentials
            {
                // no-op if we don't have a blog-id to work with
                if (HostBlogId == String.Empty)
                {
                    return(this);
                }

                try
                {
                    // detect settings
                    BlogSettingsDetector blogSettingsDetector = new BlogSettingsDetector(this);
                    blogSettingsDetector.DetectSettings(progressHost);
                }
                catch (OperationCancelledException)
                {
                    // WasCancelled == true
                }
                catch (BlogClientOperationCancelledException)
                {
                    Cancel();
                    // WasCancelled == true
                }
                catch (Exception ex)
                {
                    Trace.Fail("Unexpected error occurred while detecting weblog settings: " + ex.ToString());
                }

                return(this);
            }
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
            }
        }
        private object DetectWeblogSettings(IProgressHost progressHost)
        {
            using (BlogClientUIContextSilentMode uiContextScope = new BlogClientUIContextSilentMode()) //supress prompting for credentials
            {
                // no-op if we don't have a blog-id to work with
                if (HostBlogId == String.Empty)
                    return this;

                try
                {
                    // detect settings
                    BlogSettingsDetector blogSettingsDetector = new BlogSettingsDetector(this);
                    blogSettingsDetector.DetectSettings(progressHost);
                }
                catch (OperationCancelledException)
                {
                    // WasCancelled == true
                }
                catch (BlogClientOperationCancelledException)
                {
                    Cancel();
                    // WasCancelled == true
                }
                catch (Exception ex)
                {
                    Trace.Fail("Unexpected error occurred while detecting weblog settings: " + ex.ToString());
                }

                return this;
            }
        }
        protected override object DetectBlogService(IProgressHost progressHost)
        {
            using (BlogClientUIContextSilentMode uiContextScope = new BlogClientUIContextSilentMode()) //supress 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;
        }
        protected override object DetectBlogService(IProgressHost progressHost)
        {
            using (BlogClientUIContextSilentMode uiContextScope = new BlogClientUIContextSilentMode()) //supress 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;
            }
        }