public ICategorySelectorControl GetControl(BlogPostCategory category, bool multiSelect) { if (multiSelect) return new CategoryCheckSelectorControl(category); else return new CategoryRadioSelectorControl(category); }
public static bool Equals(BlogPostCategory x, BlogPostCategory y, bool lenientNameComparison) { if (y == null) return false; if (!x.IsCookedUpId && !y.IsCookedUpId) return x.Id == y.Id; // WordPress uses the string "0" to indicate no parent. // It's hard to tell by looking at this, but the fact that // HasParent takes this into account means we get the // correct behavior. if ((x.HasParent || y.HasParent) && x.Parent != y.Parent) return false; string selfNameUpper = x.Name.ToUpperInvariant(); string otherNameUpper = y.Name.ToUpperInvariant(); if (selfNameUpper == otherNameUpper) return true; if (lenientNameComparison && HtmlUtils.UnEscapeEntities(selfNameUpper, HtmlUtils.UnEscapeMode.Default) == HtmlUtils.UnEscapeEntities(otherNameUpper, HtmlUtils.UnEscapeMode.Default)) { return true; } return false; }
protected internal override void PreparePost(Blog blog, IBlogClient blogClient, OpenLiveWriter.Extensibility.BlogClient.BlogPost blogPost, ref bool? publish) { BlogPostCategory[] categories = blogClient.GetCategories(blog.BlogId); if (categories.Length < 2) throw new InvalidOperationException("Blog " + blog.HomepageUrl + " does not have enough categories for the SupportsMultipleCategories test to be performed"); BlogPostCategory[] newCategories = new BlogPostCategory[2]; newCategories[0] = categories[0]; newCategories[1] = categories[1]; blogPost.Categories = newCategories; }
public CategoryContext() { _selectedCategories = new BlogPostCategory[0]; SetBlogCategories(new BlogPostCategory[0]); SetNewCategories(new BlogPostCategory[0]); _selectionMode = SelectionModes.MultiSelect; _supportsAddingCategories = false; _supportsHeirarchicalCategories = false; }
private static void AreEqual(BlogPostCategory a, BlogPostCategory b) { Assert.AreEqual(a, b); Assert.AreEqual(b, a); Assert.AreEqual(a.GetHashCode(), b.GetHashCode()); Assert.IsTrue(BlogPostCategory.Equals(a, b, true)); Assert.IsTrue(BlogPostCategory.Equals(a, b, false)); Assert.IsTrue(BlogPostCategory.Equals(b, a, true)); Assert.IsTrue(BlogPostCategory.Equals(b, a, false)); }
void IBlogPostEditor.Initialize(IBlogPostEditingContext editingContext, IBlogClientOptions clientOptions) { // categories from blog CategoryContext.SetBlogCategories(_targetBlog.Categories); // pickup new categories from the blog-post CategoryContext.SetNewCategories(editingContext.BlogPost.NewCategories); // combine all post categories before settting ArrayList selectedCategories = new ArrayList(); selectedCategories.AddRange(editingContext.BlogPost.NewCategories); selectedCategories.AddRange(editingContext.BlogPost.Categories); _lastSelectedCategories = new BlogPostCategory[0]; CategoryContext.SelectedCategories = selectedCategories.ToArray(typeof(BlogPostCategory)) as BlogPostCategory[]; toolTipCategories.SetToolTip(this, CategoryContext.FormattedCategoryList); _isDirty = false; }
public ParentCategoryComboItem(ComboBox parentCombo, BlogPostCategory category, int indentLevel) { _parentCombo = parentCombo ; _category = category ; _indentLevel = indentLevel ; }
private ICategorySelectorControl GetCategorySelectorControl(BlogPostCategory category) { // scan for control foreach (ICategorySelectorControl selectorControl in _categoryControls) { if ( selectorControl.Category.Id.ToLower(CultureInfo.CurrentCulture) == category.Id.ToLower(CultureInfo.CurrentCulture) || selectorControl.Category.Name.ToLower(CultureInfo.CurrentCulture) == category.Name.ToLower(CultureInfo.CurrentCulture) ) { return selectorControl ; } } // didn't find it return null ; }
private void UpdateSelectedCategories(BlogPostCategory[] selectedCategories) { bool focused = false; foreach (ICategorySelectorControl sc in _categoryControls) { if (!focused) { sc.Control.Focus(); focused = true; } sc.Selected = false; } if (selectedCategories.Length > 0) { foreach (BlogPostCategory c in selectedCategories) foreach (ICategorySelectorControl sc in _categoryControls) { if (c.Id.ToLower(CultureInfo.CurrentCulture) == sc.Category.Id.ToLower(CultureInfo.CurrentCulture) || c.Name.ToLower(CultureInfo.CurrentCulture) == sc.Category.Name.ToLower(CultureInfo.CurrentCulture) ) { sc.Selected = true; break; } } } else { // scan for special "None" category and select it foreach (ICategorySelectorControl sc in _categoryControls) { if (BlogPostCategoryNone.IsCategoryNone((sc.Category))) { sc.Selected = true; break; } } } }
private void AppendCategories(BlogPostCategory[] categories, StringBuilder settingsContents) { settingsContents.Append(GetCategoriesContents(categories)); }
private XmlRpcArray GenerateNewCategoriesForPost(BlogPostCategory[] newCategories) { ArrayList categoryValues = new ArrayList(); foreach (BlogPostCategory category in newCategories) { // create the struct for the category XmlRpcStruct categoryStruct = new XmlRpcStruct(new XmlRpcMember[] { new XmlRpcMember( "description", category.Name ), new XmlRpcMember( "parent", category.Parent) }); // add it to the list categoryValues.Add(categoryStruct); } // return the array return new XmlRpcArray((XmlRpcValue[])categoryValues.ToArray(typeof(XmlRpcValue))); }
public void NewCategoryAdded(BlogPostCategory category) { controller.NewCategoryAdded(category); }
private bool AddCategoriesIfNecessary(string blogId, BlogPost post, INewCategoryContext newCategoryContext) { // this blog doesn't support adding categories if (!Options.SupportsNewCategories) return false; // no new categories to add if (post.NewCategories.Length == 0) return false; // we support inline category addition and we don't require a special // api for heirarchical categories (inline api can't handle parent specification) if (Options.SupportsNewCategoriesInline && !Options.SupportsHierarchicalCategories) return false; // add the categories and update their ids ArrayList newCategories = new ArrayList(); foreach (BlogPostCategory category in post.NewCategories) { string categoryId = AddCategory(blogId, category); BlogPostCategory newCategory = new BlogPostCategory(categoryId, category.Name, category.Parent); newCategories.Add(newCategory); newCategoryContext.NewCategoryAdded(newCategory); } post.NewCategories = newCategories.ToArray(typeof(BlogPostCategory)) as BlogPostCategory[]; return true; }
void INewCategoryContext.NewCategoryAdded(BlogPostCategory newCategory) { (_postPropertyEditor as INewCategoryContext).NewCategoryAdded(newCategory); }
public CategoryRadioSelectorControl(BlogPostCategory category) : base() { FlatStyle = FlatStyle.System; _category = category; }
public void SelectCategory(BlogPostCategory category) { foreach (RadioButton radio in Controls) { if (category.Equals(radio.Tag)) { radio.Checked = true; return; } } }
void IBlogCategorySettings.UpdateCategories(BlogPostCategory[] categories) { using ( BlogSettings blogSettings = BlogSettings.ForBlogId(_targetBlog.Id) ) blogSettings.Categories = categories ; }
private string GetCategoriesContents(BlogPostCategory[] categories) { StringBuilder categoriesBuilder = new StringBuilder(); if (categories != null) { Array.Sort(categories, new SortCategoriesComparer()); foreach (BlogPostCategory category in categories) categoriesBuilder.AppendFormat("Category:{0}/{1}/{2}", category.Id, category.Name, category.Parent); } return categoriesBuilder.ToString(); }
private static void AreNotEqual(BlogPostCategory a, BlogPostCategory b) { Assert.AreNotEqual(a, b); Assert.AreNotEqual(b, a); Assert.IsFalse(BlogPostCategory.Equals(a, b, true)); Assert.IsFalse(BlogPostCategory.Equals(a, b, false)); Assert.IsFalse(BlogPostCategory.Equals(b, a, true)); Assert.IsFalse(BlogPostCategory.Equals(b, a, false)); }
private XmlRpcArray GetCategoriesArray(BlogPostCategory[] categories) { ArrayList categoryValues = new ArrayList(); foreach (BlogPostCategory category in categories) { // create the struct for the category XmlRpcStruct categoryStruct = new XmlRpcStruct( new XmlRpcMember[] { new XmlRpcMember("categoryId", category.Id) }); // add it to the list categoryValues.Add(categoryStruct); } // return the array return new XmlRpcArray((XmlRpcValue[])categoryValues.ToArray(typeof(XmlRpcValue))); }
void INewCategoryContext.NewCategoryAdded(BlogPostCategory category) { // commit new category to blog post BlogPost.CommitNewCategory(category); // see if any of our blog post editors are new category contexts, if so // then notify them of the new category being added. Note that this // callback occurs during publishing so we don't want UI-layer errors // to halt publishing -- catch and log them instead. try { foreach (IBlogPostEditor postEditor in _postEditors) if (postEditor is INewCategoryContext) (postEditor as INewCategoryContext).NewCategoryAdded(category); } catch (Exception ex) { Trace.Fail("Unexpected exception during call to NewCategoryAdded: " + ex.ToString()); } }
public void NewCategoryAdded(BlogPostCategory category) { ((INewCategoryContext)categoryDropDown).NewCategoryAdded(category); }
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]; } }
public BlogPostCategory[] GetCategories(string blogId) { var categories = new BlogPostCategory[0]; var blog = GetService().Blogs.Get(blogId).Execute(); if (blog != null) { var categoriesUrl = string.Concat(blog.Url, CategoriesEndPoint); var response = SendAuthenticatedHttpRequest(categoriesUrl, 30, CreateAuthorizationFilter()); if (response != null) { using (var reader = new StreamReader(response.GetResponseStream())) { var json = reader.ReadToEnd(); var item = JsonConvert.DeserializeObject<CategoryResponse>(json); var cats = item?.Feed?.CategoryArray.Select(x => new BlogPostCategory(x.Term)); categories = cats?.ToArray() ?? new BlogPostCategory[0]; } } } return categories; }
private void MovableTypeSetPostCategories(string postId, BlogPostCategory[] categories) { // call method XmlNode result = CallMethod("mt.setPostCategories", new XmlRpcString(postId), new XmlRpcString(Username), new XmlRpcString(Password, true), GetCategoriesArray(categories)); // confirm we had a successful return value Trace.Assert(result.InnerText == "1", "Unexpected error return value from mt.setPostCategories"); }
public void SelectCategory(BlogPostCategory category) { WalkNodes(treeView.Nodes, delegate (TreeNode n) { if (category.Equals(((TreeNode)n.Tag).Tag)) { if (!n.Checked) n.Checked = true; treeView.SelectedNode = n; n.EnsureVisible(); } }); }
public override string AddCategory(string blogId, BlogPostCategory category) { // call the method XmlNode result = CallMethod("wp.newCategory", new XmlRpcString(blogId), new XmlRpcString(Username), new XmlRpcString(Password, true), new XmlRpcStruct(new XmlRpcMember[] { new XmlRpcMember("name", category.Name), new XmlRpcMember("parent_id", ParseCategoryParent(category.Parent) ), }) ); // return the category id return result.InnerText; }
public static TreeNode[] CategoriesToNodes(BlogPostCategory[] categories) { Array.Sort(categories); Dictionary<string, TreeNode> catToNode = new Dictionary<string, TreeNode>(); TreeNode[] allNodes = new TreeNode[categories.Length]; for (int i = 0; i < categories.Length; i++) { // TODO: This will need to be rewritten to deal with the fact that // ID doesn't work effectively in the face of hierarchy and new categories allNodes[i] = new TreeNode(HtmlUtils.UnEscapeEntities(categories[i].Name, HtmlUtils.UnEscapeMode.Default)); allNodes[i].Tag = categories[i]; // TODO: // This is necessary due to bug in categories, where multiple // new categories with the same name (but different parents) // have the same ID. When that bug is fixed this check should be // replaced with an assertion. if (!catToNode.ContainsKey(categories[i].Id)) catToNode.Add(categories[i].Id, allNodes[i]); } for (int i = 0; i < allNodes.Length; i++) { TreeNode node = allNodes[i]; string parent = ((BlogPostCategory)node.Tag).Parent; if (!string.IsNullOrEmpty(parent) && catToNode.ContainsKey(parent)) { catToNode[parent].Nodes.Add(node); allNodes[i] = null; } } return (TreeNode[])ArrayHelper.Compact(allNodes); }
public virtual string AddCategory(string blogId, BlogPostCategory category) { throw new BlogClientMethodUnsupportedException("AddCategory"); }
public void CommitNewCategory(BlogPostCategory newCategory) { // revised category list ArrayList categories = new ArrayList(Categories); categories.Add(newCategory); Categories = categories.ToArray(typeof(BlogPostCategory)) as BlogPostCategory[]; // revised new category list ArrayList newCategories = new ArrayList(); foreach (BlogPostCategory category in NewCategories) if (!category.Name.Equals(newCategory.Name)) newCategories.Add(category); NewCategories = newCategories.ToArray(typeof(BlogPostCategory)) as BlogPostCategory[]; }