public static void TreeId_equality() { var treeId1 = new TreeId(Sha1.Hash("abc")); var treeId2 = new TreeId(Sha1.Hash("abc")); var treeId3 = new TreeId(Sha1.Hash("def")); Assert.True(treeId1 == treeId2); Assert.False(treeId1 != treeId2); Assert.True(treeId1.Equals((object)treeId2)); Assert.Equal(treeId1.Sha1.ToString(), treeId1.ToString()); Assert.Equal(treeId2.Sha1.ToString(), treeId2.ToString()); Assert.Equal(treeId3.Sha1.ToString(), treeId3.ToString()); Assert.Equal(treeId1, treeId2); Assert.Equal(treeId1.GetHashCode(), treeId2.GetHashCode()); Assert.Equal(treeId1.ToString(), treeId2.ToString()); Assert.NotEqual(TreeId.Empty, treeId1); Assert.NotEqual(TreeId.Empty.GetHashCode(), treeId1.GetHashCode()); Assert.NotEqual(TreeId.Empty.ToString(), treeId1.ToString()); Assert.NotEqual(treeId3, treeId1); Assert.NotEqual(treeId3.GetHashCode(), treeId1.GetHashCode()); Assert.NotEqual(treeId3.ToString(), treeId1.ToString()); }
/// <summary> /// Helper method to create a root model for a tree /// </summary> /// <returns></returns> protected virtual TreeNode CreateRootNode(FormCollection queryStrings) { var jsonUrl = Url.GetTreeUrl(GetType(), RootNodeId, queryStrings); var isDialog = queryStrings.GetValue <bool>(TreeQueryStringParameters.DialogMode); var node = new TreeNode(RootNodeId, BackOfficeRequestContext.RegisteredComponents.MenuItems, jsonUrl) { HasChildren = true, EditorUrl = queryStrings.HasKey(TreeQueryStringParameters.OnNodeClick) //has a node click handler? ? queryStrings.Get(TreeQueryStringParameters.OnNodeClick) //return node click handler : isDialog //is in dialog mode without a click handler ? ? "#" //return empty string, otherwise, return an editor URL: : Url.GetCurrentDashboardUrl(), Title = NodeDisplayName }; //add the tree id to the root node.AdditionalData.Add("treeId", TreeId.ToString("N")); //add the tree-root css class node.Style.AddCustom("tree-root"); //node.AdditionalData.Add("id", node.HiveId.ToString()); //node.AdditionalData.Add("title", node.Title); AddQueryStringsToAdditionalData(node, queryStrings); //check if the tree is searchable and add that to the meta data as well if (this is ISearchableTree) { node.AdditionalData.Add("searchable", "true"); } return(node); }
//#region ISearchableTree Members //public virtual TreeSearchJsonResult Search(string searchText) //{ // //TODO: do the searching! // //for now, i'm just going to return dummy data that i know is in demo data just to get the ui working // var result = new TreeSearchJsonResult(new[] // { // new SearchResultItem { Id = new HiveId(1050).ToString(), Rank = 0, Title = "Go further", Description="this is a node" }, // new SearchResultItem { Id = new HiveId(1060).ToString(), Rank = 0, Title = "Functionality", Description="this is a node" } // }); // return result; //} //#endregion /// <summary> /// Customize the root node /// </summary> /// <param name="queryStrings"></param> /// <returns></returns> protected override TreeNode CreateRootNode(FormCollection queryStrings) { if (RootNodeId == ActualRootNodeId) { var n = base.CreateRootNode(queryStrings); AddMenuItemsToRootNode(n, queryStrings); return(n); } else { var hiveProvider = GetHiveProvider(RootNodeId, queryStrings); using (var securityUow = hiveProvider.CreateReadonly <ISecurityStore>()) using (var uow = hiveProvider.CreateReadonly <IContentStore>()) { //Get the items and ensure Browse permissions are applied var childIds = new[] { RootNodeId }; using (DisposableTimer.TraceDuration <ContentTreeController>("FilterWithPermissions", "FilterWithPermissions")) { childIds = childIds.FilterWithPermissions( BackOfficeRequestContext.Application.Security, ((UmbracoBackOfficeIdentity)User.Identity).Id, uow, securityUow, new ViewPermission().Id ).ToArray(); } if (childIds.Length == 1) { var node = uow.Repositories.Get <TypedEntity>(childIds[0]); var treeNode = ConvertEntityToTreeNode(node, RootNodeId, queryStrings, uow); //add the tree id to the root treeNode.AdditionalData.Add("treeId", TreeId.ToString("N")); treeNode.HasChildren = true; // Force true so that recycle bin is displayed //add the tree-root css class treeNode.Style.AddCustom("tree-root"); //node.AdditionalData.Add("id", node.HiveId.ToString()); //node.AdditionalData.Add("title", node.Title); //check if the tree is searchable and add that to the meta data as well if (this is ISearchableTree) { treeNode.AdditionalData.Add("searchable", "true"); } AddMenuItemsToNode(treeNode, queryStrings); return(treeNode); } } } return(null); }
/// <summary> /// Return a serialized string of values for the pre value editor model /// </summary> /// <returns></returns> public override string GetSerializedValue() { var xml = new XElement("preValues", new XElement("preValue", new XAttribute("name", "TreeId"), new XCData(TreeId.ToString("N"))), new XElement("preValue", new XAttribute("name", "IsRequired"), new XCData(IsRequired.ToString()))); return(xml.ToString()); }