/// <summary> /// Get the root node for an application with multiple trees /// </summary> /// <param name="configTree"></param> /// <param name="queryStrings"></param> /// <returns></returns> private async Task<TreeNode> GetRootForMultipleAppTree(ApplicationTree configTree, FormDataCollection queryStrings) { if (configTree == null) throw new ArgumentNullException("configTree"); var byControllerAttempt = await configTree.TryGetRootNodeFromControllerTree(queryStrings, ControllerContext); if (byControllerAttempt.Success) { return byControllerAttempt.Result; } var legacyAttempt = configTree.TryGetRootNodeFromLegacyTree(queryStrings, Url, configTree.ApplicationAlias); if (legacyAttempt.Success) { return legacyAttempt.Result; } throw new ApplicationException("Could not get root node for tree type " + configTree.Alias); }
static void ApplicationTreeService_Deleted(ApplicationTree sender, EventArgs e) { DistributedCache.Instance.RefreshAllApplicationTreeCache(); }
static void ApplicationTreeDeleted(ApplicationTree sender, System.EventArgs e) { DistributedCache.Instance.RefreshAllApplicationTreeCache(); }
private static void OnUpdated(ApplicationTree app, EventArgs args) { if (Updated != null) { Updated(app, args); } }
private static void OnNew(ApplicationTree app, EventArgs args) { if (New != null) { New(app, args); } }
private static void OnDeleted(ApplicationTree app, EventArgs args) { if (Deleted != null) { Deleted(app, args); } }
/// <summary> /// Deletes this instance. /// </summary> public void DeleteTree(ApplicationTree tree) { LoadXml(doc => { doc.Root.Elements("add").Where(x => x.Attribute("application") != null && x.Attribute("application").Value == tree.ApplicationAlias && x.Attribute("alias") != null && x.Attribute("alias").Value == tree.Alias).Remove(); }, true); OnDeleted(tree, new EventArgs()); }
/// <summary> /// Saves this instance. /// </summary> public void SaveTree(ApplicationTree tree) { LoadXml(doc => { var el = doc.Root.Elements("add").SingleOrDefault(x => x.Attribute("alias").Value == tree.Alias && x.Attribute("application").Value == tree.ApplicationAlias); if (el != null) { el.RemoveAttributes(); el.Add(new XAttribute("initialize", tree.Initialize)); el.Add(new XAttribute("sortOrder", tree.SortOrder)); el.Add(new XAttribute("alias", tree.Alias)); el.Add(new XAttribute("application", tree.ApplicationAlias)); el.Add(new XAttribute("title", tree.Title)); el.Add(new XAttribute("iconClosed", tree.IconClosed)); el.Add(new XAttribute("iconOpen", tree.IconOpened)); el.Add(new XAttribute("type", tree.Type)); } }, true); OnUpdated(tree, new EventArgs()); }
/// <summary> /// Get the root node for an application with one tree /// </summary> /// <param name="configTree"></param> /// <param name="id"></param> /// <param name="queryStrings"></param> /// <returns></returns> private async Task<SectionRootNode> GetRootForSingleAppTree(ApplicationTree configTree, string id, FormDataCollection queryStrings, string application) { var rootId = Constants.System.Root.ToString(CultureInfo.InvariantCulture); if (configTree == null) throw new ArgumentNullException("configTree"); var byControllerAttempt = configTree.TryLoadFromControllerTree(id, queryStrings, ControllerContext); if (byControllerAttempt.Success) { var rootNode = await configTree.TryGetRootNodeFromControllerTree(queryStrings, ControllerContext); if (rootNode.Success == false) { //This should really never happen if we've successfully got the children above. throw new InvalidOperationException("Could not create root node for tree " + configTree.Alias); } var sectionRoot = SectionRootNode.CreateSingleTreeSectionRoot( rootId, rootNode.Result.ChildNodesUrl, rootNode.Result.MenuUrl, rootNode.Result.Name, byControllerAttempt.Result); foreach (var d in rootNode.Result.AdditionalData) { sectionRoot.AdditionalData[d.Key] = d.Value; } return sectionRoot; } var legacyAttempt = configTree.TryLoadFromLegacyTree(id, queryStrings, Url, configTree.ApplicationAlias); if (legacyAttempt.Success) { var sectionRoot = SectionRootNode.CreateSingleTreeSectionRoot( rootId, "", //TODO: I think we'll need this in this situation! Url.GetUmbracoApiService<LegacyTreeController>("GetMenu", rootId) + "&parentId=" + rootId + "&treeType=" + application + "§ion=" + application, "", //TODO: I think we'll need this in this situation! legacyAttempt.Result); sectionRoot.AdditionalData.Add("treeAlias", configTree.Alias); return sectionRoot; } throw new ApplicationException("Could not render a tree for type " + configTree.Alias); }