Пример #1
0
 /// <summary>
 /// Load front matter keys configuration from blog credentials
 /// </summary>
 /// <param name="creds">An IBlogCredentialsAccessor</param>
 public void LoadFromCredentials(IBlogCredentialsAccessor creds)
 {
     if (creds.GetCustomValue(CONFIG_ID_KEY) != string.Empty)
     {
         IdKey = creds.GetCustomValue(CONFIG_ID_KEY);
     }
     if (creds.GetCustomValue(CONFIG_TITLE_KEY) != string.Empty)
     {
         TitleKey = creds.GetCustomValue(CONFIG_TITLE_KEY);
     }
     if (creds.GetCustomValue(CONFIG_DATE_KEY) != string.Empty)
     {
         DateKey = creds.GetCustomValue(CONFIG_DATE_KEY);
     }
     if (creds.GetCustomValue(CONFIG_LAYOUT_KEY) != string.Empty)
     {
         LayoutKey = creds.GetCustomValue(CONFIG_LAYOUT_KEY);
     }
     if (creds.GetCustomValue(CONFIG_TAGS_KEY) != string.Empty)
     {
         TagsKey = creds.GetCustomValue(CONFIG_TAGS_KEY);
     }
     if (creds.GetCustomValue(CONFIG_PARENT_ID_KEY) != string.Empty)
     {
         ParentIdKey = creds.GetCustomValue(CONFIG_PARENT_ID_KEY);
     }
     if (creds.GetCustomValue(CONFIG_PERMALINK_KEY) != string.Empty)
     {
         PermalinkKey = creds.GetCustomValue(CONFIG_PERMALINK_KEY);
     }
 }
Пример #2
0
        /// <summary>
        /// Create a new StaticSiteConfigFrontMatterKeys instance and load configuration from blog credentials
        /// </summary>
        /// <param name="blogCredentials">An IBlogCredentialsAccessor</param>
        public static StaticSiteConfigFrontMatterKeys LoadKeysFromCredentials(IBlogCredentialsAccessor blogCredentials)
        {
            var frontMatterKeys = new StaticSiteConfigFrontMatterKeys();

            frontMatterKeys.LoadFromCredentials(blogCredentials);
            return(frontMatterKeys);
        }
Пример #3
0
        public GoogleBloggerv3Client(Uri postApiUrl, IBlogCredentialsAccessor credentials)
            : base(credentials)
        {
            // configure client options
            BlogClientOptions clientOptions = new BlogClientOptions();

            clientOptions.SupportsCategories         = false;
            clientOptions.SupportsMultipleCategories = false;
            clientOptions.SupportsNewCategories      = false;
            clientOptions.SupportsCustomDate         = true;
            clientOptions.SupportsExcerpt            = false;
            clientOptions.SupportsSlug            = false;
            clientOptions.SupportsFileUpload      = true;
            clientOptions.SupportsKeywords        = true;
            clientOptions.SupportsGetKeywords     = true;
            clientOptions.SupportsPages           = true;
            clientOptions.SupportsExtendedEntries = true;
            _clientOptions = clientOptions;

            _nsMgr = new XmlNamespaceManager(new NameTable());
            _nsMgr.AddNamespace(atomNS.Prefix, atomNS.Uri);
            _nsMgr.AddNamespace(pubNS.Prefix, pubNS.Uri);
            _nsMgr.AddNamespace(AtomClient.xhtmlNS.Prefix, AtomClient.xhtmlNS.Uri);
            _nsMgr.AddNamespace(AtomClient.featuresNS.Prefix, AtomClient.featuresNS.Uri);
            _nsMgr.AddNamespace(AtomClient.mediaNS.Prefix, AtomClient.mediaNS.Uri);
            _nsMgr.AddNamespace(AtomClient.liveNS.Prefix, AtomClient.liveNS.Uri);
        }
Пример #4
0
        /// <summary>
        /// Create a new StaticSiteConfig instance and load site configuration from blog credentials
        /// </summary>
        /// <param name="blogCredentials">An IBlogCredentialsAccessor</param>
        public static StaticSiteConfig LoadConfigFromCredentials(IBlogCredentialsAccessor blogCredentials)
        {
            var config = new StaticSiteConfig();

            config.LoadFromCredentials(blogCredentials);
            return(config);
        }
Пример #5
0
        /// <summary>
        /// Load site configuration from blog credentials
        /// </summary>
        /// <param name="creds">An IBlogCredentialsAccessor</param>
        public void LoadFromCredentials(IBlogCredentialsAccessor creds)
        {
            LocalSitePath = creds.Username;
            PostsPath     = creds.GetCustomValue(CONFIG_POSTS_PATH);

            PagesEnabled = creds.GetCustomValue(CONFIG_PAGES_ENABLED) == "1";
            PagesPath    = creds.GetCustomValue(CONFIG_PAGES_PATH);

            DraftsEnabled = creds.GetCustomValue(CONFIG_DRAFTS_ENABLED) == "1";
            DraftsPath    = creds.GetCustomValue(CONFIG_DRAFTS_PATH);

            ImagesEnabled = creds.GetCustomValue(CONFIG_IMAGES_ENABLED) == "1";
            ImagesPath    = creds.GetCustomValue(CONFIG_IMAGES_PATH);

            BuildingEnabled = creds.GetCustomValue(CONFIG_BUILDING_ENABLED) == "1";
            OutputPath      = creds.GetCustomValue(CONFIG_OUTPUT_PATH);
            BuildCommand    = creds.GetCustomValue(CONFIG_BUILD_COMMAND);

            PublishCommand = creds.GetCustomValue(CONFIG_PUBLISH_COMMAND);

            SiteUrl = creds.GetCustomValue(CONFIG_SITE_URL); // This will be overidden in LoadFromBlogSettings, HomepageUrl is considered a more accurate source of truth

            ShowCmdWindows = creds.GetCustomValue(CONFIG_SHOW_CMD_WINDOWS) == "1";
            if (creds.GetCustomValue(CONFIG_CMD_TIMEOUT_MS) != string.Empty)
            {
                CmdTimeoutMs = int.Parse(creds.GetCustomValue(CONFIG_CMD_TIMEOUT_MS));
            }
            Initialised = creds.GetCustomValue(CONFIG_INITIALISED) == "1";

            // Load FrontMatterKeys
            FrontMatterKeys = StaticSiteConfigFrontMatterKeys.LoadKeysFromCredentials(creds);
        }
Пример #6
0
        public BlogServiceDetectorBase(IBlogClientUIContext uiContext, Control hiddenBrowserParentControl, string localBlogId, string homepageUrl, IBlogCredentialsAccessor credentials)
            : base(uiContext)
        {
            // save references
            _uiContext   = uiContext;
            _localBlogId = localBlogId;
            _homepageUrl = homepageUrl;
            _credentials = credentials;

            // add blog service detection
            AddProgressOperation(
                new ProgressOperation(DetectBlogService),
                35);

            // add settings downloading (note: this operation will be a no-op
            // in the case where we don't successfully detect a weblog)
            AddProgressOperation(
                new ProgressOperation(DetectWeblogSettings),
                new ProgressOperationCompleted(DetectWeblogSettingsCompleted),
                30);

            // add template downloading (note: this operation will be a no-op in the
            // case where we don't successfully detect a weblog)
            _blogEditingTemplateDetector = new BlogEditingTemplateDetector(uiContext, hiddenBrowserParentControl);
            AddProgressOperation(
                new ProgressOperation(_blogEditingTemplateDetector.DetectTemplate),
                35);
        }
Пример #7
0
        /// <summary>
        /// Saves site configuration to blog credentials
        /// </summary>
        public void SaveToCredentials(IBlogCredentialsAccessor creds)
        {
            // Set username to Local Site Path
            creds.Username = LocalSitePath;
            creds.SetCustomValue(CONFIG_POSTS_PATH, PostsPath);

            creds.SetCustomValue(CONFIG_PAGES_ENABLED, PagesEnabled ? "1" : "0");
            creds.SetCustomValue(CONFIG_PAGES_PATH, PagesPath);

            creds.SetCustomValue(CONFIG_DRAFTS_ENABLED, DraftsEnabled ? "1" : "0");
            creds.SetCustomValue(CONFIG_DRAFTS_PATH, DraftsPath);

            creds.SetCustomValue(CONFIG_IMAGES_ENABLED, ImagesEnabled ? "1" : "0");
            creds.SetCustomValue(CONFIG_IMAGES_PATH, ImagesPath);

            creds.SetCustomValue(CONFIG_BUILDING_ENABLED, BuildingEnabled ? "1" : "0");
            creds.SetCustomValue(CONFIG_OUTPUT_PATH, OutputPath);
            creds.SetCustomValue(CONFIG_BUILD_COMMAND, BuildCommand);

            creds.SetCustomValue(CONFIG_PUBLISH_COMMAND, PublishCommand);
            creds.SetCustomValue(CONFIG_SITE_URL, SiteUrl);

            creds.SetCustomValue(CONFIG_SHOW_CMD_WINDOWS, ShowCmdWindows ? "1" : "0");
            creds.SetCustomValue(CONFIG_CMD_TIMEOUT_MS, CmdTimeoutMs.ToString());
            creds.SetCustomValue(CONFIG_INITIALISED, Initialised ? "1" : "0");

            // Save FrontMatterKeys
            FrontMatterKeys.SaveToCredentials(creds);
        }
Пример #8
0
 public BlogPostRegionLocatorStrategy(IBlogClient blogClient, BlogAccount blogAccount, IBlogCredentialsAccessor credentials, string blogHomepageUrl, PageDownloader pageDownloader)
 {
     _blogClient      = blogClient;
     _blogAccount     = blogAccount;
     _credentials     = credentials;
     _blogHomepageUrl = blogHomepageUrl;
     _pageDownloader  = pageDownloader;
 }
 public BlogPostRegionLocatorStrategy(IBlogClient blogClient, BlogAccount blogAccount, IBlogCredentialsAccessor credentials, string blogHomepageUrl, PageDownloader pageDownloader)
 {
     _blogClient = blogClient;
     _blogAccount = blogAccount;
     _credentials = credentials;
     _blogHomepageUrl = blogHomepageUrl;
     _pageDownloader = pageDownloader;
 }
Пример #10
0
 /// <summary>
 /// Save front matter keys configuration to blog credentials
 /// </summary>
 /// <param name="creds">An IBlogCredentialsAccessor</param>
 public void SaveToCredentials(IBlogCredentialsAccessor creds)
 {
     creds.SetCustomValue(CONFIG_ID_KEY, IdKey);
     creds.SetCustomValue(CONFIG_TITLE_KEY, TitleKey);
     creds.SetCustomValue(CONFIG_DATE_KEY, DateKey);
     creds.SetCustomValue(CONFIG_LAYOUT_KEY, LayoutKey);
     creds.SetCustomValue(CONFIG_TAGS_KEY, TagsKey);
     creds.SetCustomValue(CONFIG_PARENT_ID_KEY, ParentIdKey);
     creds.SetCustomValue(CONFIG_PERMALINK_KEY, PermalinkKey);
 }
Пример #11
0
        public XmlRpcBlogClient(Uri postApiUrl, IBlogCredentialsAccessor credentials)
            : base(credentials)
        {
            _postApiUrl = UrlHelper.SafeToAbsoluteUri(postApiUrl);

            // configure client options
            BlogClientOptions clientOptions = new BlogClientOptions();

            ConfigureClientOptions(clientOptions);
            _clientOptions = clientOptions;
        }
        public XmlRpcBlogClient(Uri postApiUrl, IBlogCredentialsAccessor credentials)
            : base(credentials)
        {
            _postApiUrl = UrlHelper.SafeToAbsoluteUri(postApiUrl);

            // configure client options
            BlogClientOptions clientOptions = new BlogClientOptions();
            ConfigureClientOptions(clientOptions);
            _clientOptions = clientOptions;

        }
Пример #13
0
        public StaticSiteClient(Uri postApiUrl, IBlogCredentialsAccessor credentials)
            : base(credentials)
        {
            Config = StaticSiteConfig.LoadConfigFromCredentials(credentials);

            // Set the client options
            var options = new BlogClientOptions();

            ConfigureClientOptions(options);
            Options = options;
        }
Пример #14
0
            public HttpCredentialsProvider(string postApiUrl, IBlogCredentialsAccessor blogCredentials, string username, string password)
            {
                _postApiUrl      = postApiUrl;
                _blogCredentials = blogCredentials;

                string baseUrl = UrlHelper.GetBaseUrl(_postApiUrl);

                if ((username != null && username != String.Empty) || (password != null && password != String.Empty))
                {
                    _credentials = HttpRequestHelper.CreateHttpCredentials(username, password, baseUrl);
                }
            }
        /// <summary>
        /// SetContext using a weblog account
        /// </summary>
        public void SetContext(BlogAccount blogAccount, IBlogCredentialsAccessor credentials, string blogHomepageUrl, string blogTemplateDir, WriterEditingManifestDownloadInfo manifestDownloadInfo, bool probeForManifest, string providerId, IDictionary optionOverrides, IDictionary userOptionOverrides, IDictionary homepageOptionOverrides)
        {
            // note context set
            _contextSet = true;

            // create a blog client
            _blogAccount = blogAccount;
            _credentials = credentials;
            _blogClient  = BlogClientManager.CreateClient(blogAccount.ClientType, blogAccount.PostApiUrl, credentials, providerId, optionOverrides, userOptionOverrides, homepageOptionOverrides);

            // set other context that we've got
            _blogHomepageUrl      = blogHomepageUrl;
            _blogTemplateDir      = blogTemplateDir;
            _manifestDownloadInfo = manifestDownloadInfo;
            _probeForManifest     = probeForManifest;
        }
        public static IBlogClient CreateClient(string clientType, string postApiUrl, IBlogCredentialsAccessor credentials)
        {
            Debug.Assert(clientType != "WindowsLiveSpaces", "Use of WindowsLiveSpaces client is deprecated");

            // scan for a client type with a matching name
            string clientTypeUpper = clientType.ToUpperInvariant();
            foreach (ClientTypeDefinition clientTypeDefinition in ClientTypes)
            {
                if (clientTypeDefinition.Name.ToUpperInvariant() == clientTypeUpper)
                {
                    return (IBlogClient)clientTypeDefinition.Constructor.Invoke(new object[] {
                        new Uri(postApiUrl), credentials  });
                }
            }

            // didn't find a match!
            throw new ArgumentException(
                String.Format(CultureInfo.CurrentCulture, "Client type {0} not found.", clientType));
        }
        public static IBlogClient CreateClient(string clientType, string postApiUrl, IBlogCredentialsAccessor credentials, string providerId, IDictionary optionOverrides, IDictionary userOptionOverrides, IDictionary homepageOptionOverrides)
        {
            // create blog client reflecting the settings
            IBlogClient blogClient = CreateClient(clientType, postApiUrl, credentials);

            // if there is a provider associated with the client then use it to override options
            // as necessary for this provider
            IBlogProvider provider = BlogProviderManager.FindProvider(providerId);

            if (provider != null)
            {
                IBlogClientOptions providerOptions = provider.ConstructBlogOptions(blogClient.Options);
                blogClient.OverrideOptions(providerOptions);
            }

            if (homepageOptionOverrides != null)
            {
                OptionOverrideReader homepageOptionsReader = new OptionOverrideReader(homepageOptionOverrides);
                IBlogClientOptions   homepageOptions       = BlogClientOptions.ApplyOptionOverrides(new OptionReader(homepageOptionsReader.Read), blogClient.Options, true);
                blogClient.OverrideOptions(homepageOptions);
            }

            // if there are manifest overrides then apply them
            if (optionOverrides != null)
            {
                OptionOverrideReader manifestOptionsReader = new OptionOverrideReader(optionOverrides);
                IBlogClientOptions   manifestOptions       = BlogClientOptions.ApplyOptionOverrides(new OptionReader(manifestOptionsReader.Read), blogClient.Options, true);
                blogClient.OverrideOptions(manifestOptions);
            }

            // if there are user overrides then apply them
            if (userOptionOverrides != null)
            {
                OptionOverrideReader userOptionsReader = new OptionOverrideReader(userOptionOverrides);
                IBlogClientOptions   userOptions       = BlogClientOptions.ApplyOptionOverrides(new OptionReader(userOptionsReader.Read), blogClient.Options, true);
                blogClient.OverrideOptions(userOptions);
            }



            // return the blog client
            return(blogClient);
        }
        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;
        }
Пример #19
0
        public AtomClient(AtomProtocolVersion atomVer, Uri postApiUrl, IBlogCredentialsAccessor credentials)
            : base(credentials)
        {
            _feedServiceUrl = postApiUrl;

            // configure client options
            BlogClientOptions clientOptions = new BlogClientOptions();
            ConfigureClientOptions(clientOptions);
            _clientOptions = clientOptions;

            _atomVer = atomVer;
            _atomNS = new Namespace(atomVer.NamespaceUri, "atom");
            _pubNS = new Namespace(atomVer.PubNamespaceUri, "app");
            _nsMgr = new XmlNamespaceManager(new NameTable());
            _nsMgr.AddNamespace(_atomNS.Prefix, _atomNS.Uri);
            _nsMgr.AddNamespace(_pubNS.Prefix, _pubNS.Uri);
            _nsMgr.AddNamespace(xhtmlNS.Prefix, xhtmlNS.Uri);
            _nsMgr.AddNamespace(featuresNS.Prefix, featuresNS.Uri);
            _nsMgr.AddNamespace(mediaNS.Prefix, mediaNS.Uri);
            _nsMgr.AddNamespace(liveNS.Prefix, liveNS.Uri);
        }
        public static IBlogClient CreateClient(string clientType, string postApiUrl, IBlogCredentialsAccessor credentials)
        {
            Debug.Assert(clientType != "WindowsLiveSpaces", "Use of WindowsLiveSpaces client is deprecated");

            // scan for a client type with a matching name
            string clientTypeUpper = clientType.ToUpperInvariant();

            foreach (ClientTypeDefinition clientTypeDefinition in ClientTypes)
            {
                if (clientTypeDefinition.Name.ToUpperInvariant() == clientTypeUpper)
                {
                    return((IBlogClient)clientTypeDefinition.Constructor.Invoke(new object[] {
                        new Uri(postApiUrl), credentials
                    }));
                }
            }

            // didn't find a match!
            throw new ArgumentException(
                      String.Format(CultureInfo.CurrentCulture, "Client type {0} not found.", clientType));
        }
        public static IBlogClient CreateClient(string clientType, string postApiUrl, IBlogCredentialsAccessor credentials, string providerId, IDictionary optionOverrides, IDictionary userOptionOverrides, IDictionary homepageOptionOverrides)
        {
            // create blog client reflecting the settings
            IBlogClient blogClient = CreateClient(clientType, postApiUrl, credentials);

            // if there is a provider associated with the client then use it to override options
            // as necessary for this provider
            IBlogProvider provider = BlogProviderManager.FindProvider(providerId);
            if (provider != null)
            {
                IBlogClientOptions providerOptions = provider.ConstructBlogOptions(blogClient.Options);
                blogClient.OverrideOptions(providerOptions);
            }

            if (homepageOptionOverrides != null)
            {
                OptionOverrideReader homepageOptionsReader = new OptionOverrideReader(homepageOptionOverrides);
                IBlogClientOptions homepageOptions = BlogClientOptions.ApplyOptionOverrides(new OptionReader(homepageOptionsReader.Read), blogClient.Options, true);
                blogClient.OverrideOptions(homepageOptions);
            }

            // if there are manifest overrides then apply them
            if (optionOverrides != null)
            {
                OptionOverrideReader manifestOptionsReader = new OptionOverrideReader(optionOverrides);
                IBlogClientOptions manifestOptions = BlogClientOptions.ApplyOptionOverrides(new OptionReader(manifestOptionsReader.Read), blogClient.Options, true);
                blogClient.OverrideOptions(manifestOptions);
            }

            // if there are user overrides then apply them
            if (userOptionOverrides != null)
            {
                OptionOverrideReader userOptionsReader = new OptionOverrideReader(userOptionOverrides);
                IBlogClientOptions userOptions = BlogClientOptions.ApplyOptionOverrides(new OptionReader(userOptionsReader.Read), blogClient.Options, true);
                blogClient.OverrideOptions(userOptions);
            }

            // return the blog client
            return blogClient;
        }
Пример #22
0
        public AtomClient(AtomProtocolVersion atomVer, Uri postApiUrl, IBlogCredentialsAccessor credentials)
            : base(credentials)
        {
            _feedServiceUrl = postApiUrl;

            // configure client options
            BlogClientOptions clientOptions = new BlogClientOptions();

            ConfigureClientOptions(clientOptions);
            _clientOptions = clientOptions;

            _atomVer = atomVer;
            _atomNS  = new Namespace(atomVer.NamespaceUri, "atom");
            _pubNS   = new Namespace(atomVer.PubNamespaceUri, "app");
            _nsMgr   = new XmlNamespaceManager(new NameTable());
            _nsMgr.AddNamespace(_atomNS.Prefix, _atomNS.Uri);
            _nsMgr.AddNamespace(_pubNS.Prefix, _pubNS.Uri);
            _nsMgr.AddNamespace(xhtmlNS.Prefix, xhtmlNS.Uri);
            _nsMgr.AddNamespace(featuresNS.Prefix, featuresNS.Uri);
            _nsMgr.AddNamespace(mediaNS.Prefix, mediaNS.Uri);
            _nsMgr.AddNamespace(liveNS.Prefix, liveNS.Uri);
        }
Пример #23
0
        private WriterEditingManifest SafeDownloadEditingManifest()
        {
            WriterEditingManifest editingManifest = null;

            try
            {
                // create a blog client
                IBlogClient blogClient = CreateBlogClient();

                // can we get one based on cached download info
                IBlogCredentialsAccessor credentialsToUse = (IncludeInsecureOperations || blogClient.IsSecure) ? _context.Credentials : null;
                if (_context.ManifestDownloadInfo != null)
                {
                    string manifestUrl = _context.ManifestDownloadInfo.SourceUrl;
                    if (UseManifestCache)
                    {
                        editingManifest = WriterEditingManifest.FromDownloadInfo(_context.ManifestDownloadInfo, blogClient, credentialsToUse, true);
                    }
                    else
                    {
                        editingManifest = WriterEditingManifest.FromUrl(new Uri(manifestUrl), blogClient, credentialsToUse, true);
                    }
                }

                // if we don't have one yet then probe for one
                if (editingManifest == null)
                {
                    editingManifest = WriterEditingManifest.FromHomepage(_homepageAccessor, new Uri(_context.HomepageUrl), blogClient, credentialsToUse);
                }
            }
            catch (Exception ex)
            {
                ReportException("attempting to download editing manifest", ex);
            }

            // return whatever we found
            return(editingManifest);
        }
            public HttpCredentialsProvider(string postApiUrl, IBlogCredentialsAccessor blogCredentials, string username, string password)
            {
                _postApiUrl = postApiUrl;
                _blogCredentials = blogCredentials;

                string baseUrl = UrlHelper.GetBaseUrl(_postApiUrl);
                if ((username != null && username != String.Empty) || (password != null && password != String.Empty))
                {
                    _credentials = HttpRequestHelper.CreateHttpCredentials(username, password, baseUrl);
                }
            }
Пример #25
0
 public BlogClientBase(IBlogCredentialsAccessor credentials)
 {
     _credentials = credentials;
 }
Пример #26
0
 public BloggerAtomClient(Uri postApiUrl, IBlogCredentialsAccessor credentials)
     : base(AtomProtocolVersion.V10DraftBlogger, postApiUrl, credentials)
 {
 }
Пример #27
0
        public static WinInetCredentialsContext GetCredentialsContext(IBlogClient blogClient, IBlogCredentialsAccessor credentials, string url)
        {
            // determine cookies and/or network credentials
            CookieString      cookieString = null;
            NetworkCredential credential   = null;

            if (credentials != null && credentials.Username != String.Empty)
            {
                credential = new NetworkCredential(credentials.Username, credentials.Password);
            }

            if (cookieString != null || credential != null)
            {
                return(new WinInetCredentialsContext(credential, cookieString));
            }
            else
            {
                return(null);
            }
        }
 public static IBlogClient CreateClient(BlogAccount blogAccount, IBlogCredentialsAccessor credentials)
 {
     return CreateClient(blogAccount.ClientType, blogAccount.PostApiUrl, credentials);
 }
 public TemporaryPostRegionLocatorStrategy(IBlogClient blogClient, BlogAccount blogAccount,
     IBlogCredentialsAccessor credentials, string blogHomepageUrl, PageDownloader pageDownloader, BlogPostRegionLocatorBooleanCallback promptForTempPost)
     : base(blogClient, blogAccount, credentials, blogHomepageUrl, pageDownloader)
 {
     this.containsBlogPosts = promptForTempPost;
 }
 /// <summary>
 /// Detect a specific BlogAccount (or list of blog accounts if a single account could not
 /// be identified).
 /// </summary>
 /// <param name="homepageUrl">Hint to the detector that if there is a list of blogs then the one with this homepageUrl is the one we are seeking</param>
 /// <param name="clientType">Client API type</param>
 /// <param name="postApiUrl">Post API URL</param>
 /// <param name="credential">Credentials</param>
 public BlogAccountDetector(string clientType, string postApiUrl, IBlogCredentialsAccessor credentials)
 {
     _clientType = clientType;
     _postApiUrl = postApiUrl;
     _credentials = credentials;
 }
Пример #31
0
        /*private string DiscoverPostApiUrl(string baseUrl, string blogPath)
         * {
         *
         * }*/

        /// <summary>
        /// Verifies the user credentials and determines whether SharePoint is configure to use HTTP or MetaWeblog authentication
        /// </summary>
        /// <param name="postApiUrl"></param>
        /// <param name="blogCredentials"></param>
        /// <param name="credentials"></param>
        /// <returns></returns>
        private static bool VerifyCredentialsAndDetectAuthScheme(string postApiUrl, IBlogCredentials blogCredentials, IBlogCredentialsAccessor credentials)
        {
            BlogClientAttribute blogClientAttr = (BlogClientAttribute)typeof(SharePointClient).GetCustomAttributes(typeof(BlogClientAttribute), false)[0];
            SharePointClient    client         = (SharePointClient)BlogClientManager.CreateClient(blogClientAttr.TypeName, postApiUrl, credentials);

            return(SharePointClient.VerifyCredentialsAndDetectAuthScheme(blogCredentials, client));
        }
Пример #32
0
 public SharePointBlogDetector(IBlogClientUIContext uiContext, Control hiddenBrowserParentControl, string localBlogId, string homepageUrl, IBlogCredentialsAccessor credentials, IBlogCredentials blogCredentials)
     : base(uiContext, hiddenBrowserParentControl, localBlogId, homepageUrl, credentials)
 {
     _blogCredentials = blogCredentials;
 }
        public BlogServiceDetectorBase(IBlogClientUIContext uiContext, Control hiddenBrowserParentControl, string localBlogId, string homepageUrl, IBlogCredentialsAccessor credentials)
            : base(uiContext)
        {
            // save references
            _uiContext = uiContext;
            _localBlogId = localBlogId;
            _homepageUrl = homepageUrl;
            _credentials = credentials;

            // add blog service detection
            AddProgressOperation(
                new ProgressOperation(DetectBlogService),
                35);

            // add settings downloading (note: this operation will be a no-op
            // in the case where we don't succesfully detect a weblog)
            AddProgressOperation(
                new ProgressOperation(DetectWeblogSettings),
                new ProgressOperationCompleted(DetectWeblogSettingsCompleted),
                30);

            // add template downloading (note: this operation will be a no-op in the
            // case where we don't successfully detect a weblog)
            _blogEditingTemplateDetector = new BlogEditingTemplateDetector(uiContext, hiddenBrowserParentControl);
            AddProgressOperation(
                new ProgressOperation(_blogEditingTemplateDetector.DetectTemplate),
                35);
        }
        /*private string DiscoverPostApiUrl(string baseUrl, string blogPath)
        {

        }*/

        /// <summary>
        /// Verifies the user credentials and determines whether SharePoint is configure to use HTTP or MetaWeblog authentication
        /// </summary>
        /// <param name="postApiUrl"></param>
        /// <param name="blogCredentials"></param>
        /// <param name="credentials"></param>
        /// <returns></returns>
        private static bool VerifyCredentialsAndDetectAuthScheme(string postApiUrl, IBlogCredentials blogCredentials, IBlogCredentialsAccessor credentials)
        {
            BlogClientAttribute blogClientAttr = (BlogClientAttribute)typeof(SharePointClient).GetCustomAttributes(typeof(BlogClientAttribute), false)[0];
            SharePointClient client = (SharePointClient)BlogClientManager.CreateClient(blogClientAttr.TypeName, postApiUrl, credentials);

            return SharePointClient.VerifyCredentialsAndDetectAuthScheme(blogCredentials, client);
        }
 public SharePointBlogDetector(IBlogClientUIContext uiContext, Control hiddenBrowserParentControl, string localBlogId, string homepageUrl, IBlogCredentialsAccessor credentials, IBlogCredentials blogCredentials)
     : base(uiContext, hiddenBrowserParentControl, localBlogId, homepageUrl, credentials)
 {
     _blogCredentials = blogCredentials;
 }
 public BlogServiceDetector(IBlogClientUIContext uiContext, Control hiddenBrowserParentControl, IBlogSettingsAccessor blogSettings, IBlogCredentialsAccessor credentials)
     : base(uiContext, hiddenBrowserParentControl, blogSettings.Id, blogSettings.HomepageUrl, credentials)
 {
     _blogSettings = blogSettings;
 }
Пример #37
0
 public RecentPostRegionLocatorStrategy(IBlogClient blogClient, BlogAccount blogAccount,
                                        IBlogCredentialsAccessor credentials, string blogHomepageUrl, PageDownloader pageDownloader)
     : base(blogClient, blogAccount, credentials, blogHomepageUrl, pageDownloader)
 {
 }
Пример #38
0
 public WordPressClient(Uri postApiUrl, IBlogCredentialsAccessor credentials)
     : base(postApiUrl, credentials)
 {
 }
Пример #39
0
 public TemporaryPostRegionLocatorStrategy(IBlogClient blogClient, BlogAccount blogAccount,
                                           IBlogCredentialsAccessor credentials, string blogHomepageUrl, PageDownloader pageDownloader, BlogPostRegionLocatorBooleanCallback promptForTempPost)
     : base(blogClient, blogAccount, credentials, blogHomepageUrl, pageDownloader)
 {
     this.containsBlogPosts = promptForTempPost;
 }
        /// <summary>
        /// SetContext using a weblog account
        /// </summary>
        public void SetContext(BlogAccount blogAccount, IBlogCredentialsAccessor credentials, string blogHomepageUrl, string blogTemplateDir, WriterEditingManifestDownloadInfo manifestDownloadInfo, bool probeForManifest, string providerId, IDictionary optionOverrides, IDictionary userOptionOverrides, IDictionary homepageOptionOverrides)
        {
            // note context set
            _contextSet = true;

            // create a blog client
            _blogAccount = blogAccount;
            _credentials = credentials;
            _blogClient = BlogClientManager.CreateClient(blogAccount.ClientType, blogAccount.PostApiUrl, credentials, providerId, optionOverrides, userOptionOverrides, homepageOptionOverrides);

            // set other context that we've got
            _blogHomepageUrl = blogHomepageUrl;
            _blogTemplateDir = blogTemplateDir;
            _manifestDownloadInfo = manifestDownloadInfo;
            _probeForManifest = probeForManifest;
        }
Пример #41
0
 public BlogClientBase(IBlogCredentialsAccessor credentials)
 {
     _credentials = credentials;
 }
 public static WriterEditingManifest FromUrl(Uri manifestUri, IBlogClient blogClient, IBlogCredentialsAccessor credentials, bool expectedAvailable)
 {
     return FromDownloadInfo(new WriterEditingManifestDownloadInfo(UrlHelper.SafeToAbsoluteUri(manifestUri)), blogClient, credentials, expectedAvailable);
 }
Пример #43
0
 public MovableTypeClient(Uri postApiUrl, IBlogCredentialsAccessor credentials)
     : base(postApiUrl, credentials)
 {
 }
Пример #44
0
 public BloggerAtomClient(Uri postApiUrl, IBlogCredentialsAccessor credentials)
     : base(AtomProtocolVersion.V10DraftBlogger, postApiUrl, credentials)
 {
 }
        public GoogleBloggerv3Client(Uri postApiUrl, IBlogCredentialsAccessor credentials)
            : base(credentials)
        {
            // configure client options
            BlogClientOptions clientOptions = new BlogClientOptions();
            clientOptions.SupportsCategories = false;
            clientOptions.SupportsMultipleCategories = false;
            clientOptions.SupportsNewCategories = false;
            clientOptions.SupportsCustomDate = true;
            clientOptions.SupportsExcerpt = false;
            clientOptions.SupportsSlug = false;
            clientOptions.SupportsFileUpload = true;
            clientOptions.SupportsKeywords = true;
            clientOptions.SupportsGetKeywords = true;
            clientOptions.SupportsPages = true;
            clientOptions.SupportsExtendedEntries = true;
            _clientOptions = clientOptions;

            _nsMgr = new XmlNamespaceManager(new NameTable());
            _nsMgr.AddNamespace(atomNS.Prefix, atomNS.Uri);
            _nsMgr.AddNamespace(pubNS.Prefix, pubNS.Uri);
            _nsMgr.AddNamespace(AtomClient.xhtmlNS.Prefix, AtomClient.xhtmlNS.Uri);
            _nsMgr.AddNamespace(AtomClient.featuresNS.Prefix, AtomClient.featuresNS.Uri);
            _nsMgr.AddNamespace(AtomClient.mediaNS.Prefix, AtomClient.mediaNS.Uri);
            _nsMgr.AddNamespace(AtomClient.liveNS.Prefix, AtomClient.liveNS.Uri);
        }
        public static WriterEditingManifest FromDownloadInfo(WriterEditingManifestDownloadInfo downloadInfo, IBlogClient blogClient, IBlogCredentialsAccessor credentials, bool expectedAvailable)
        {
            if (downloadInfo == null)
                return null;

            try
            {
                // if the manifest is not yet expired then don't try a download at all
                if (downloadInfo.Expires > DateTimeHelper.UtcNow)
                    return new WriterEditingManifest(downloadInfo);

                // execute the download
                HttpWebResponse response = null;
                try
                {
                    if (credentials != null)
                        response = blogClient.SendAuthenticatedHttpRequest(downloadInfo.SourceUrl, REQUEST_TIMEOUT, new HttpRequestFilter(new EditingManifestFilter(downloadInfo).Filter));
                    else
                        response = HttpRequestHelper.SendRequest(downloadInfo.SourceUrl, new HttpRequestFilter(new EditingManifestFilter(downloadInfo).Filter));
                }
                catch (WebException ex)
                {
                    // Not modified -- return ONLY an updated downloadInfo (not a document)
                    HttpWebResponse errorResponse = ex.Response as HttpWebResponse;
                    if (errorResponse != null && errorResponse.StatusCode == HttpStatusCode.NotModified)
                    {
                        return new WriterEditingManifest(
                            new WriterEditingManifestDownloadInfo(
                                downloadInfo.SourceUrl,
                                HttpRequestHelper.GetExpiresHeader(errorResponse),
                                downloadInfo.LastModified,
                                HttpRequestHelper.GetETagHeader(errorResponse)));
                    }
                    else
                        throw;
                }

                // read headers
                DateTime expires = HttpRequestHelper.GetExpiresHeader(response);
                DateTime lastModified = response.LastModified;
                string eTag = HttpRequestHelper.GetETagHeader(response);

                // read document
                using (Stream stream = response.GetResponseStream())
                {
                    XmlDocument manifestXmlDocument = new XmlDocument();
                    manifestXmlDocument.Load(stream);

                    // return the manifest
                    return new WriterEditingManifest(
                        new WriterEditingManifestDownloadInfo(downloadInfo.SourceUrl, expires, lastModified, eTag),
                        manifestXmlDocument,
                        blogClient,
                        credentials);
                }
            }
            catch (Exception ex)
            {
                if (expectedAvailable)
                {
                    Trace.WriteLine("Error attempting to download manifest from " + downloadInfo.SourceUrl + ": " + ex.ToString());
                }
                return null;
            }
        }
 public MetaweblogClient(Uri postApiUrl, IBlogCredentialsAccessor credentials)
     : base(postApiUrl, credentials)
 {
 }
 public SharePointClient(Uri postApiUrl, IBlogCredentialsAccessor credentials)
     : base(postApiUrl, credentials)
 {
     _postApiUrl = postApiUrl;
 }
Пример #49
0
 public SharePointClient(Uri postApiUrl, IBlogCredentialsAccessor credentials)
     : base(postApiUrl, credentials)
 {
     _postApiUrl = postApiUrl;
 }
 public MovableTypeClient(Uri postApiUrl, IBlogCredentialsAccessor credentials)
     : base(postApiUrl, credentials)
 {
 }
 public static IBlogClient CreateClient(BlogAccount blogAccount, IBlogCredentialsAccessor credentials)
 {
     return(CreateClient(blogAccount.ClientType, blogAccount.PostApiUrl, credentials));
 }
 public BloggerCompatibleClient(Uri postApiUrl, IBlogCredentialsAccessor credentials)
     : base(postApiUrl, credentials)
 {
 }
 public RecentPostRegionLocatorStrategy(IBlogClient blogClient, BlogAccount blogAccount,
     IBlogCredentialsAccessor credentials, string blogHomepageUrl, PageDownloader pageDownloader)
     : base(blogClient, blogAccount, credentials, blogHomepageUrl, pageDownloader)
 {
 }
        public static WinInetCredentialsContext GetCredentialsContext(IBlogClient blogClient, IBlogCredentialsAccessor credentials, string url)
        {
            // determine cookies and/or network credentials
            CookieString cookieString = null;
            NetworkCredential credential = null;

            if (credentials != null && credentials.Username != String.Empty)
            {
                credential = new NetworkCredential(credentials.Username, credentials.Password);
            }

            if (cookieString != null || credential != null)
                return new WinInetCredentialsContext(credential, cookieString);
            else
                return null;
        }
 public GenericAtomClient(Uri postApiUrl, IBlogCredentialsAccessor credentials) : base(AtomProtocolVersion.V10, postApiUrl, credentials)
 {
 }
Пример #56
0
 public WordPressClient(Uri postApiUrl, IBlogCredentialsAccessor credentials)
     : base(postApiUrl, credentials)
 {
 }
 public LiveJournalClient(Uri postApiUrl, IBlogCredentialsAccessor credentials)
     : base(postApiUrl, credentials)
 {
 }
        private WriterEditingManifest(WriterEditingManifestDownloadInfo downloadInfo, XmlDocument xmlDocument, IBlogClient blogClient, IBlogCredentialsAccessor credentials)
        {
            // record blog client and credentials
            _blogClient = blogClient;
            _credentials = credentials;

            // record download info
            if (UrlHelper.IsUrl(downloadInfo.SourceUrl))
                _downloadInfo = downloadInfo;

            // only process an xml document if we got one
            if (xmlDocument == null)
                return;

            // create namespace manager
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDocument.NameTable);
            nsmgr.AddNamespace("m", "http://schemas.microsoft.com/wlw/manifest/weblog");

            // throw if the root element is not manifest
            if (xmlDocument.DocumentElement.LocalName.ToUpperInvariant() != "MANIFEST")
                throw new ArgumentException("Not a valid writer editing manifest");

            // get button descriptions
            _buttonDescriptions = new IBlogProviderButtonDescription[] { };
            XmlNode buttonsNode = xmlDocument.SelectSingleNode("//m:buttons", nsmgr);
            if (buttonsNode != null)
            {
                ArrayList buttons = new ArrayList();

                foreach (XmlNode buttonNode in buttonsNode.SelectNodes("m:button", nsmgr))
                {
                    try
                    {
                        // id
                        string id = XmlHelper.NodeText(buttonNode.SelectSingleNode("m:id", nsmgr));
                        if (id == String.Empty)
                            throw new ArgumentException("Missing id field");

                        // title
                        string description = XmlHelper.NodeText(buttonNode.SelectSingleNode("m:text", nsmgr));
                        if (description == String.Empty)
                            throw new ArgumentException("Missing text field");

                        // imageUrl
                        string imageUrl = XmlHelper.NodeText(buttonNode.SelectSingleNode("m:imageUrl", nsmgr));
                        if (imageUrl == String.Empty)
                            throw new ArgumentException("Missing imageUrl field");

                        // download the image
                        Bitmap image = DownloadImage(imageUrl, downloadInfo.SourceUrl);

                        // clickUrl
                        string clickUrl = BlogClientHelper.GetAbsoluteUrl(XmlHelper.NodeText(buttonNode.SelectSingleNode("m:clickUrl", nsmgr)), downloadInfo.SourceUrl);

                        // contentUrl
                        string contentUrl = BlogClientHelper.GetAbsoluteUrl(XmlHelper.NodeText(buttonNode.SelectSingleNode("m:contentUrl", nsmgr)), downloadInfo.SourceUrl);

                        // contentDisplaySize
                        Size contentDisplaySize = XmlHelper.NodeSize(buttonNode.SelectSingleNode("m:contentDisplaySize", nsmgr), Size.Empty);

                        // button must have either clickUrl or hasContent
                        if (clickUrl == String.Empty && contentUrl == String.Empty)
                            throw new ArgumentException("Must either specify a clickUrl or contentUrl");

                        // notificationUrl
                        string notificationUrl = BlogClientHelper.GetAbsoluteUrl(XmlHelper.NodeText(buttonNode.SelectSingleNode("m:notificationUrl", nsmgr)), downloadInfo.SourceUrl);

                        // add the button
                        buttons.Add(new BlogProviderButtonDescription(id, imageUrl, image, description, clickUrl, contentUrl, contentDisplaySize, notificationUrl));
                    }
                    catch (Exception ex)
                    {
                        // buttons fail silently and are not "all or nothing"
                        Trace.WriteLine("Error occurred reading custom button description: " + ex.Message);
                    }
                }

                _buttonDescriptions = buttons.ToArray(typeof(IBlogProviderButtonDescription)) as IBlogProviderButtonDescription[];
            }

            // get options
            _optionOverrides = new Hashtable();
            AddOptionsFromNode(xmlDocument.SelectSingleNode("//m:weblog", nsmgr), _optionOverrides);
            AddOptionsFromNode(xmlDocument.SelectSingleNode("//m:options", nsmgr), _optionOverrides);
            AddOptionsFromNode(xmlDocument.SelectSingleNode("//m:apiOptions[@name='" + _blogClient.ProtocolName + "']", nsmgr), _optionOverrides);
            XmlNode defaultViewNode = xmlDocument.SelectSingleNode("//m:views/m:default", nsmgr);
            if (defaultViewNode != null)
                _optionOverrides["defaultView"] = XmlHelper.NodeText(defaultViewNode);

            // separate out client type
            const string CLIENT_TYPE = "clientType";
            if (_optionOverrides.Contains(CLIENT_TYPE))
            {
                string type = _optionOverrides[CLIENT_TYPE].ToString();
                if (ValidateClientType(type))
                    _clientType = type;
                _optionOverrides.Remove(CLIENT_TYPE);
            }

            // separate out image
            const string IMAGE_URL = "imageUrl";
            _image = GetImageBytes(IMAGE_URL, _optionOverrides, downloadInfo.SourceUrl, new Size(16, 16));
            _optionOverrides.Remove(IMAGE_URL);

            // separate out watermark image
            const string WATERMARK_IMAGE_URL = "watermarkImageUrl";
            _watermark = GetImageBytes(WATERMARK_IMAGE_URL, _optionOverrides, downloadInfo.SourceUrl, new Size(84, 84));
            _optionOverrides.Remove(WATERMARK_IMAGE_URL);

            // get templates
            XmlNode webLayoutUrlNode = xmlDocument.SelectSingleNode("//m:views/m:view[@type='WebLayout']/@src", nsmgr);
            if (webLayoutUrlNode != null)
            {
                string webLayoutUrl = XmlHelper.NodeText(webLayoutUrlNode);
                if (webLayoutUrl != String.Empty)
                    _webLayoutUrl = BlogClientHelper.GetAbsoluteUrl(webLayoutUrl, downloadInfo.SourceUrl);
            }
            XmlNode webPreviewUrlNode = xmlDocument.SelectSingleNode("//m:views/m:view[@type='WebPreview']/@src", nsmgr);
            if (webPreviewUrlNode != null)
            {
                string webPreviewUrl = XmlHelper.NodeText(webPreviewUrlNode);
                if (webPreviewUrl != String.Empty)
                    _webPreviewUrl = BlogClientHelper.GetAbsoluteUrl(webPreviewUrl, downloadInfo.SourceUrl);
            }
        }
 /// <summary>
 /// Detect a specific BlogAccount (or list of blog accounts if a single account could not
 /// be identified).
 /// </summary>
 /// <param name="homepageUrl">Hint to the detector that if there is a list of blogs then the one with this homepageUrl is the one we are seeking</param>
 /// <param name="clientType">Client API type</param>
 /// <param name="postApiUrl">Post API URL</param>
 /// <param name="credential">Credentials</param>
 public BlogAccountDetector(string clientType, string postApiUrl, IBlogCredentialsAccessor credentials)
 {
     _clientType  = clientType;
     _postApiUrl  = postApiUrl;
     _credentials = credentials;
 }
 public BloggerCompatibleClient(Uri postApiUrl, IBlogCredentialsAccessor credentials)
     : base(postApiUrl, credentials)
 {
 }