コード例 #1
0
        public BlogSettingsDetector(IBlogSettingsDetectionContext context)
        {
            // save the context
            _context = context;

            _homepageAccessor = new LazyHomepageDownloader(_context.HomepageUrl, new HttpRequestHandler(ExecuteHttpRequest));
        }
コード例 #2
0
        public BlogSettingsDetector(IBlogSettingsDetectionContext context)
        {
            // save the context
            _context = context;

            _homepageAccessor = new LazyHomepageDownloader(_context.HomepageUrl, new HttpRequestHandler(ExecuteHttpRequest));
        }
コード例 #3
0
        public static WriterEditingManifest FromHomepage(LazyHomepageDownloader homepageDownloader, Uri homepageUri, IBlogClient blogClient, IBlogCredentialsAccessor credentials)
        {
            if (homepageUri == null)
            {
                return(null);
            }

            WriterEditingManifest editingManifest = null;

            try
            {
                // compute the "by-convention" url for the manifest
                string homepageUrl = UrlHelper.InsureTrailingSlash(UrlHelper.SafeToAbsoluteUri(homepageUri));
                string manifestUrl = UrlHelper.UrlCombine(homepageUrl, "wlwmanifest.xml");

                // test to see whether this url exists and has a valid manifest
                editingManifest = FromUrl(new Uri(manifestUrl), blogClient, credentials, false);

                // if we still don't have one then scan homepage contents for a link tag
                if (editingManifest == null)
                {
                    string manifestLinkTagUrl = ScanHomepageContentsForManifestLink(homepageUri, homepageDownloader);
                    if (manifestLinkTagUrl != null)
                    {
                        // test to see whether this url exists and has a valid manifest
                        try
                        {
                            editingManifest = FromUrl(new Uri(manifestLinkTagUrl), blogClient, credentials, true);
                        }
                        catch (Exception ex)
                        {
                            Trace.WriteLine("Error attempting to download manifest from " + manifestLinkTagUrl + ": " + ex.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Unexpected exception attempting to discover manifest from " + UrlHelper.SafeToAbsoluteUri(homepageUri) + ": " + ex.ToString());
            }

            // return whatever editing manifest we found
            return(editingManifest);
        }
コード例 #4
0
        private static string ScanHomepageContentsForManifestLink(Uri homepageUri, LazyHomepageDownloader homepageDownloader)
        {
            if (homepageDownloader.HtmlDocument != null)
            {
                LightWeightTag[] linkTags = homepageDownloader.HtmlDocument.GetTagsByName(HTMLTokens.Link);
                foreach (LightWeightTag linkTag in linkTags)
                {
                    string rel  = linkTag.BeginTag.GetAttributeValue("rel");
                    string href = linkTag.BeginTag.GetAttributeValue("href");

                    if (rel != null && (rel.Trim().ToUpperInvariant().Equals("WLWMANIFEST") && href != null))
                    {
                        return(UrlHelper.UrlCombineIfRelative(UrlHelper.SafeToAbsoluteUri(homepageUri), href));
                    }
                }
            }

            // didn't find it
            return(null);
        }
コード例 #5
0
        public static WriterEditingManifest FromHomepage(LazyHomepageDownloader homepageDownloader, Uri homepageUri, IBlogClient blogClient, IBlogCredentialsAccessor credentials)
        {
            if (homepageUri == null)
                return null;

            WriterEditingManifest editingManifest = null;
            try
            {
                // compute the "by-convention" url for the manifest
                string homepageUrl = UrlHelper.InsureTrailingSlash(UrlHelper.SafeToAbsoluteUri(homepageUri));
                string manifestUrl = UrlHelper.UrlCombine(homepageUrl, "wlwmanifest.xml");

                // test to see whether this url exists and has a valid manifest
                editingManifest = FromUrl(new Uri(manifestUrl), blogClient, credentials, false);

                // if we still don't have one then scan homepage contents for a link tag
                if (editingManifest == null)
                {
                    string manifestLinkTagUrl = ScanHomepageContentsForManifestLink(homepageUri, homepageDownloader);
                    if (manifestLinkTagUrl != null)
                    {
                        // test to see whether this url exists and has a valid manifest
                        try
                        {
                            editingManifest = FromUrl(new Uri(manifestLinkTagUrl), blogClient, credentials, true);
                        }
                        catch (Exception ex)
                        {
                            Trace.WriteLine("Error attempting to download manifest from " + manifestLinkTagUrl + ": " + ex.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Unexpected exception attempting to discover manifest from " + UrlHelper.SafeToAbsoluteUri(homepageUri) + ": " + ex.ToString());
            }

            // return whatever editing manifest we found
            return editingManifest;
        }
コード例 #6
0
        private static string ScanHomepageContentsForManifestLink(Uri homepageUri, LazyHomepageDownloader homepageDownloader)
        {
            if (homepageDownloader.HtmlDocument != null)
            {
                LightWeightTag[] linkTags = homepageDownloader.HtmlDocument.GetTagsByName(HTMLTokens.Link);
                foreach (LightWeightTag linkTag in linkTags)
                {
                    string rel = linkTag.BeginTag.GetAttributeValue("rel");
                    string href = linkTag.BeginTag.GetAttributeValue("href");

                    if (rel != null && (rel.Trim().ToUpperInvariant().Equals("WLWMANIFEST") && href != null))
                    {
                        return UrlHelper.UrlCombineIfRelative(UrlHelper.SafeToAbsoluteUri(homepageUri), href);
                    }
                }
            }

            // didn't find it
            return null;
        }