public void ShowPanel(BlogInfo[] blogs, string selectedBlogId)
        {
            listBoxSelectWeblog.Items.Clear();

            // populate the list
            foreach (BlogInfo blog in blogs)
                listBoxSelectWeblog.Items.Add(blog);

            // default selection
            if (selectedBlogId != null)
            {
                foreach (BlogInfo blog in blogs)
                {
                    if (blog.Id == selectedBlogId)
                    {
                        listBoxSelectWeblog.SelectedItem = blog;
                        break;
                    }
                }
            }

            // if we have no default then select the first weblog
            if (listBoxSelectWeblog.SelectedIndex == -1)
                listBoxSelectWeblog.SelectedIndex = 0;
        }
        public void ShowPanel(string defaultServiceName, string homepageUrl, string accountId, IBlogCredentials credentials)
        {
            // save reference to settings
            _homepageUrl = homepageUrl;
            _accountId = accountId;
            _credentials = credentials;

            // find provider and select it (add it to the combo if necessary)
            IBlogProviderDescription provider = BlogProviderManager.FindProviderByName(defaultServiceName);
            if (provider != null)
            {
                BlogProviderDescriptionProxy providerProxy = new BlogProviderDescriptionProxy(provider);

                if (!comboBoxSelectProvider.Items.Contains(providerProxy))
                    comboBoxSelectProvider.Items.Add(providerProxy);

                comboBoxSelectProvider.SelectedItem = providerProxy;
            }
            else
            {
                // add the special 'select provider' entry and select it
                if (!comboBoxSelectProvider.Items.Contains(BlogProviderDescriptionProxy.SelectProvider))
                    comboBoxSelectProvider.Items.Add(BlogProviderDescriptionProxy.SelectProvider);

                comboBoxSelectProvider.SelectedItem = BlogProviderDescriptionProxy.SelectProvider;
            }

            // reset results
            _targetBlog = null;
            _usersBlogs = new BlogInfo[] { };
        }
        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;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public void SetBlogInfo(BlogInfo blogInfo)
        {
            if (blogInfo.Id != _hostBlogId)
            {
                _blogName = blogInfo.Name;
                _hostBlogId = blogInfo.Id;
                _homePageUrl = blogInfo.HomepageUrl;
                if (!UrlHelper.IsUrl(_homePageUrl))
                {
                    Trace.Assert(!string.IsNullOrEmpty(_homePageUrl), "Homepage URL was null or empty");
                    string baseUrl = UrlHelper.GetBaseUrl(_postApiUrl);
                    _homePageUrl = UrlHelper.UrlCombineIfRelative(baseUrl, _homePageUrl);
                }

                // reset categories, authors, and pages
                Categories = new BlogPostCategory[] { };
                Keywords = new BlogPostKeyword[] { };
                Authors = new AuthorInfo[] { };
                Pages = new PageInfo[] { };

                // reset option overrides
                if (OptionOverrides != null)
                    OptionOverrides.Clear();

                if (UserOptionOverrides != null)
                    UserOptionOverrides.Clear();

                if (HomePageOverrides != null)
                    HomePageOverrides.Clear();

                // reset provider buttons
                if (ButtonDescriptions != null)
                    ButtonDescriptions = new IBlogProviderButtonDescription[0];

                // reset template
                TemplateFiles = new BlogEditingTemplateFile[0];
            }
        }
Ejemplo n.º 5
0
        public void CopyFrom(TemporaryBlogSettings sourceSettings)
        {
            // simple members
            _id = sourceSettings._id;
            _switchToWeblog = sourceSettings._switchToWeblog;
            _isNewWeblog = sourceSettings._isNewWeblog;
            _savePassword = sourceSettings._savePassword;
            _isSpacesBlog = sourceSettings._isSpacesBlog;
            _isSharePointBlog = sourceSettings._isSharePointBlog;
            _hostBlogId = sourceSettings._hostBlogId;
            _blogName = sourceSettings._blogName;
            _homePageUrl = sourceSettings._homePageUrl;
            _manifestDownloadInfo = sourceSettings._manifestDownloadInfo;
            _providerId = sourceSettings._providerId;
            _serviceName = sourceSettings._serviceName;
            _clientType = sourceSettings._clientType;
            _postApiUrl = sourceSettings._postApiUrl;
            _lastPublishFailed = sourceSettings._lastPublishFailed;
            _fileUploadSupport = sourceSettings._fileUploadSupport;
            _instrumentationOptIn = sourceSettings._instrumentationOptIn;

            if (sourceSettings._availableImageEndpoints == null)
            {
                _availableImageEndpoints = null;
            }
            else
            {
                // Good thing BlogInfo is immutable!
                _availableImageEndpoints = (BlogInfo[])sourceSettings._availableImageEndpoints.Clone();
            }

            // credentials
            BlogCredentialsHelper.Copy(sourceSettings._credentials, _credentials);

            // template files
            _templateFiles = new BlogEditingTemplateFile[sourceSettings._templateFiles.Length];
            for (int i = 0; i < sourceSettings._templateFiles.Length; i++)
            {
                BlogEditingTemplateFile sourceFile = sourceSettings._templateFiles[i];
                _templateFiles[i] = new BlogEditingTemplateFile(sourceFile.TemplateType, sourceFile.TemplateFile);
            }

            // option overrides
            if (sourceSettings._optionOverrides != null)
            {
                _optionOverrides.Clear();
                foreach (DictionaryEntry entry in sourceSettings._optionOverrides)
                    _optionOverrides.Add(entry.Key, entry.Value);
            }

            // user option overrides
            if (sourceSettings._userOptionOverrides != null)
            {
                _userOptionOverrides.Clear();
                foreach (DictionaryEntry entry in sourceSettings._userOptionOverrides)
                    _userOptionOverrides.Add(entry.Key, entry.Value);
            }

            // homepage overrides
            if (sourceSettings._homepageOptionOverrides != null)
            {
                _homepageOptionOverrides.Clear();
                foreach (DictionaryEntry entry in sourceSettings._homepageOptionOverrides)
                    _homepageOptionOverrides.Add(entry.Key, entry.Value);
            }

            // categories
            if (sourceSettings._categories != null)
            {
                _categories = new BlogPostCategory[sourceSettings._categories.Length];
                for (int i = 0; i < sourceSettings._categories.Length; i++)
                {
                    BlogPostCategory sourceCategory = sourceSettings._categories[i];
                    _categories[i] = sourceCategory.Clone() as BlogPostCategory;
                }
            }
            else
            {
                _categories = null;
            }

            if (sourceSettings._keywords != null)
            {
                _keywords = new BlogPostKeyword[sourceSettings._keywords.Length];
                for (int i = 0; i < sourceSettings._keywords.Length; i++)
                {
                    BlogPostKeyword sourceKeyword = sourceSettings._keywords[i];
                    _keywords[i] = sourceKeyword.Clone() as BlogPostKeyword;
                }
            }
            else
            {
                _keywords = null;
            }

            // authors and pages
            _authors = sourceSettings._authors.Clone() as AuthorInfo[];
            _pages = sourceSettings._pages.Clone() as PageInfo[];

            // buttons
            if (sourceSettings._buttonDescriptions != null)
            {
                _buttonDescriptions = new BlogProviderButtonDescription[sourceSettings._buttonDescriptions.Length];
                for (int i = 0; i < sourceSettings._buttonDescriptions.Length; i++)
                    _buttonDescriptions[i] = sourceSettings._buttonDescriptions[i].Clone() as BlogProviderButtonDescription;
            }
            else
            {
                _buttonDescriptions = null;
            }

            // favicon
            _favIcon = sourceSettings._favIcon;

            // images
            _image = sourceSettings._image;
            _watermarkImage = sourceSettings._watermarkImage;

            // host blogs
            _hostBlogs = new BlogInfo[sourceSettings._hostBlogs.Length];
            for (int i = 0; i < sourceSettings._hostBlogs.Length; i++)
            {
                BlogInfo sourceBlog = sourceSettings._hostBlogs[i];
                _hostBlogs[i] = new BlogInfo(sourceBlog.Id, sourceBlog.Name, sourceBlog.HomepageUrl);
            }

            // file upload settings
            _fileUploadSettings = sourceSettings._fileUploadSettings.Clone() as TemporaryFileUploadSettings;

            _pluginSettings = new SettingsPersisterHelper(new MemorySettingsPersister());
            _pluginSettings.CopyFrom(sourceSettings._pluginSettings, true, true);
        }
Ejemplo n.º 6
0
        protected BlogInfo[] GetUsersBlogsInternal()
        {
            Uri serviceUri = FeedServiceUrl;
            XmlDocument xmlDoc = xmlRestRequestHelper.Get(ref serviceUri, RequestFilter);

            // Either the FeedServiceUrl points to a service document OR a feed.

            if (xmlDoc.SelectSingleNode("/app:service", _nsMgr) != null)
            {
                ArrayList blogInfos = new ArrayList();
                foreach (XmlElement coll in xmlDoc.SelectNodes("/app:service/app:workspace/app:collection", _nsMgr))
                {
                    bool promote = ShouldPromote(coll);

                    // does this collection accept entries?
                    XmlNodeList acceptNodes = coll.SelectNodes("app:accept", _nsMgr);
                    bool acceptsEntries = false;
                    if (acceptNodes.Count == 0)
                    {
                        acceptsEntries = true;
                    }
                    else
                    {
                        foreach (XmlElement acceptNode in acceptNodes)
                        {
                            if (AcceptsEntry(acceptNode.InnerText))
                            {
                                acceptsEntries = true;
                                break;
                            }
                        }
                    }

                    if (acceptsEntries)
                    {
                        string feedUrl = XmlHelper.GetUrl(coll, "@href", serviceUri);
                        if (feedUrl == null || feedUrl.Length == 0)
                            continue;

                        // form title
                        StringBuilder titleBuilder = new StringBuilder();
                        foreach (XmlElement titleContainerNode in new XmlElement[] { coll.ParentNode as XmlElement, coll })
                        {
                            Debug.Assert(titleContainerNode != null);
                            if (titleContainerNode != null)
                            {
                                XmlElement titleNode = titleContainerNode.SelectSingleNode("atom:title", _nsMgr) as XmlElement;
                                if (titleNode != null)
                                {
                                    string titlePart = _atomVer.TextNodeToPlaintext(titleNode);
                                    if (titlePart.Length != 0)
                                    {
                                        Res.LOCME("loc the separator between parts of the blog name");
                                        if (titleBuilder.Length != 0)
                                            titleBuilder.Append(" - ");
                                        titleBuilder.Append(titlePart);
                                    }
                                }
                            }
                        }

                        // get homepage URL
                        string homepageUrl = "";
                        string dummy = "";
                        Uri tempFeedUrl = new Uri(feedUrl);
                        XmlDocument feedDoc = xmlRestRequestHelper.Get(ref tempFeedUrl, RequestFilter);
                        ParseFeedDoc(feedDoc, tempFeedUrl, false, ref homepageUrl, ref dummy);

                        // TODO: Sniff out the homepage URL
                        BlogInfo blogInfo = new BlogInfo(feedUrl, titleBuilder.ToString().Trim(), homepageUrl);
                        if (promote)
                            blogInfos.Insert(0, blogInfo);
                        else
                            blogInfos.Add(blogInfo);
                    }
                }

                return (BlogInfo[])blogInfos.ToArray(typeof(BlogInfo));
            }
            else
            {
                string title = string.Empty;
                string homepageUrl = string.Empty;

                ParseFeedDoc(xmlDoc, serviceUri, true, ref homepageUrl, ref title);

                return new BlogInfo[] { new BlogInfo(UrlHelper.SafeToAbsoluteUri(FeedServiceUrl), title, homepageUrl) };
            }
        }