using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; using System.Xml.Linq; using AutoMapper; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.IO; using Umbraco.Core.Events; using Umbraco.Core.IO; using Umbraco.Core.Services; using umbraco.DataLayer; namespace umbraco.BusinessLogic { /// /// umbraco.BusinessLogic.ApplicationTree provides access to the application tree structure in umbraco. /// An application tree is a collection of nodes belonging to one or more application(s). /// Through this class new application trees can be created, modified and deleted. /// [Obsolete("This has been superceded by ApplicationContext.Current.ApplicationTreeService")] public class ApplicationTree { /// /// Gets or sets a value indicating whether this is silent. /// /// true if silent; otherwise, false. public bool Silent { get; set; } /// /// Gets or sets a value indicating whether this should initialize. /// /// true if initialize; otherwise, false. public bool Initialize { get; set; } /// /// Gets or sets the sort order. /// /// The sort order. public byte SortOrder { get; set; } /// /// Gets the application alias. /// /// The application alias. public string ApplicationAlias { get; private set; } /// /// Gets the tree alias. /// /// The alias. public string Alias { get; private set; } /// /// Gets or sets the tree title. /// /// The title. public string Title { get; set; } /// /// Gets or sets the icon closed. /// /// The icon closed. public string IconClosed { get; set; } /// /// Gets or sets the icon opened. /// /// The icon opened. public string IconOpened { get; set; } /// /// Gets or sets the name of the assembly. /// /// The name of the assembly. public string AssemblyName { get; set; } /// /// Gets or sets the tree type. /// /// The type. public string Type { get; set; } private Type _runtimeType; /// /// Returns the CLR type based on it's assembly name stored in the config /// /// internal Type GetRuntimeType() { return _runtimeType ?? (_runtimeType = System.Type.GetType(Type)); } /// /// Gets or sets the default tree action. /// /// The action. public string Action { get; set; } /// /// Initializes a new instance of the class. /// public ApplicationTree() { } /// /// Initializes a new instance of the class. /// /// if set to true [silent]. /// if set to true [initialize]. /// The sort order. /// The application alias. /// The tree alias. /// The tree title. /// The icon closed. /// The icon opened. /// Name of the assembly. /// The tree type. /// The default tree action. public ApplicationTree(bool silent, bool initialize, byte sortOrder, string applicationAlias, string alias, string title, string iconClosed, string iconOpened, string assemblyName, string type, string action) { this.Silent = silent; this.Initialize = initialize; this.SortOrder = sortOrder; this.ApplicationAlias = applicationAlias; this.Alias = alias; this.Title = title; this.IconClosed = iconClosed; this.IconOpened = iconOpened; this.AssemblyName = assemblyName; this.Type = type; this.Action = action; } /// /// Creates a new application tree. /// /// if set to true [silent]. /// if set to true [initialize]. /// The sort order. /// The application alias. /// The alias. /// The title. /// The icon closed. /// The icon opened. /// Name of the assembly. /// The type. /// The action. public static void MakeNew(bool silent, bool initialize, byte sortOrder, string applicationAlias, string alias, string title, string iconClosed, string iconOpened, string assemblyName, string type, string action) { ApplicationContext.Current.Services.ApplicationTreeService.MakeNew(initialize, sortOrder, applicationAlias, alias, title, iconClosed, iconOpened, assemblyName.IsNullOrWhiteSpace() ? type : string.Format("{0}.{1},{0}", assemblyName, type)); } /// /// Saves this instance. /// public void Save() { ApplicationContext.Current.Services.ApplicationTreeService.SaveTree( Mapper.Map(this)); } /// /// Deletes this instance. /// public void Delete() { ApplicationContext.Current.Services.ApplicationTreeService.DeleteTree( Mapper.Map(this)); } /// /// Gets an ApplicationTree by it's tree alias. /// /// The tree alias. /// An ApplicationTree instance public static ApplicationTree getByAlias(string treeAlias) { return Mapper.Map( ApplicationContext.Current.Services.ApplicationTreeService.GetByAlias(treeAlias)); } /// /// Gets all applicationTrees registered in umbraco from the umbracoAppTree table.. /// /// Returns a ApplicationTree Array public static ApplicationTree[] getAll() { return ApplicationContext.Current.Services.ApplicationTreeService.GetAll() .Select(Mapper.Map) .ToArray(); } /// /// Gets the application tree for the applcation with the specified alias /// /// The application alias. /// Returns a ApplicationTree Array public static ApplicationTree[] getApplicationTree(string applicationAlias) { return ApplicationContext.Current.Services.ApplicationTreeService.GetApplicationTrees(applicationAlias) .Select(Mapper.Map) .ToArray(); } /// /// Gets the application tree for the applcation with the specified alias /// /// The application alias. /// /// Returns a ApplicationTree Array public static ApplicationTree[] getApplicationTree(string applicationAlias, bool onlyInitializedApplications) { return ApplicationContext.Current.Services.ApplicationTreeService.GetApplicationTrees(applicationAlias, onlyInitializedApplications) .Select(Mapper.Map) .ToArray(); } } }