Exemplo n.º 1
0
 private static void OnNew(ApplicationTree app, EventArgs args)
 {
     if (New != null)
     {
         New(app, args);
     }
 }
        private Attempt<TreeNodeCollection> TryLoadFromLegacyTree(ApplicationTree appTree, string id, FormDataCollection formCollection)
        {
            //This is how the legacy trees worked....
            var treeDef = TreeDefinitionCollection.Instance.FindTree(appTree.Alias);
            if (treeDef == null)
            {
                return new Attempt<TreeNodeCollection>(new InstanceNotFoundException("Could not find tree of type " + appTree.Alias));
            }

            var bTree = treeDef.CreateInstance();
            var treeParams = new TreeParams();

            //we currently only support an integer id or a string id, we'll refactor how this works
            //later but we'll get this working first
            int startId;
            if (int.TryParse(id, out startId))
            {
                treeParams.StartNodeID = startId;
            }
            else
            {
                treeParams.NodeKey = id;
            }
            var xTree = new XmlTree();
            bTree.SetTreeParameters(treeParams);
            bTree.Render(ref xTree);

            return new Attempt<TreeNodeCollection>(true, LegacyTreeDataAdapter.ConvertFromLegacy(xTree));
        }
Exemplo n.º 3
0
 private static void OnUpdated(ApplicationTree app, EventArgs args)
 {
     if (Updated != null)
     {
         Updated(app, args);
     }
 }
Exemplo n.º 4
0
 private static void OnDeleted(ApplicationTree app, EventArgs args)
 {
     if (Deleted != null)
     {
         Deleted(app, args);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Deletes this instance.
        /// </summary>
        public void Delete()
        {
            //delete the assigned applications
            SqlHelper.ExecuteNonQuery("delete from umbracoUser2App where app = @appAlias", SqlHelper.CreateParameter("@appAlias", this.alias));

            //delete the assigned trees
            var trees = ApplicationTree.getApplicationTree(this.alias);

            foreach (var t in trees)
            {
                t.Delete();
            }

            SqlHelper.ExecuteNonQuery("delete from umbracoApp where appAlias = @appAlias",
                                      SqlHelper.CreateParameter("@appAlias", this._alias));

            ReCache();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Deletes this instance.
        /// </summary>
        public void Delete()
        {
            //delete the assigned applications
            SqlHelper.ExecuteNonQuery("delete from umbracoUser2App where app = @appAlias", SqlHelper.CreateParameter("@appAlias", this.alias));

            //delete the assigned trees
            var trees = ApplicationTree.getApplicationTree(this.alias);

            foreach (var t in trees)
            {
                t.Delete();
            }

            LoadXml(doc =>
            {
                doc.Root.Elements("add").Where(x => x.Attribute("alias") != null && x.Attribute("alias").Value == this.alias).Remove();
            }, true);
        }
        private Attempt<TreeNodeCollection> TryLoadFromControllerTree(ApplicationTree appTree, string id, FormDataCollection formCollection)
        {
            //get reference to all TreeApiControllers
            var controllerTrees = UmbracoApiControllerResolver.Current.RegisteredUmbracoApiControllers
                                                              .Where(TypeHelper.IsTypeAssignableFrom<TreeApiController>)
                                                              .ToArray();

            //find the one we're looking for
            var foundControllerTree = controllerTrees.FirstOrDefault(x => x.GetFullNameWithAssembly() == appTree.Type);
            if (foundControllerTree == null)
            {
                return new Attempt<TreeNodeCollection>(new InstanceNotFoundException("Could not find tree of type " + appTree.Type + " in any loaded DLLs"));
            }

            //instantiate it, since we are proxying, we need to setup the instance with our current context
            var instance = (TreeApiController)DependencyResolver.Current.GetService(foundControllerTree);
            instance.ControllerContext = ControllerContext;
            instance.Request = Request;

            //return it's data
            return new Attempt<TreeNodeCollection>(true, instance.GetNodes(id, formCollection));
        }
Exemplo n.º 8
0
        public ApplicationTreeRegistrar()
        {
            //don't do anything if the application or database is not configured!
            if (ApplicationContext.Current == null ||
                !ApplicationContext.Current.IsConfigured ||
                !ApplicationContext.Current.DatabaseContext.IsDatabaseConfigured)
            {
                return;
            }

            // Load all Trees by attribute and add them to the XML config
            var types = PluginManager.Current.ResolveAttributedTrees();

            var items = types
                        .Select(x =>
                                new Tuple <Type, TreeAttribute>(x, x.GetCustomAttributes <TreeAttribute>(false).Single()))
                        .Where(x => ApplicationTree.getByAlias(x.Item2.Alias) == null);

            var allAliases = ApplicationTree.getAll().Select(x => x.Alias).Concat(items.Select(x => x.Item2.Alias));
            var inString   = "'" + string.Join("','", allAliases) + "'";

            ApplicationTree.LoadXml(doc =>
            {
                foreach (var tuple in items)
                {
                    var type = tuple.Item1;
                    var attr = tuple.Item2;

                    //Add the new tree that doesn't exist in the config that was found by type finding

                    doc.Root.Add(new XElement("add",
                                              new XAttribute("silent", attr.Silent),
                                              new XAttribute("initialize", attr.Initialize),
                                              new XAttribute("sortOrder", attr.SortOrder),
                                              new XAttribute("alias", attr.Alias),
                                              new XAttribute("application", attr.ApplicationAlias),
                                              new XAttribute("title", attr.Title),
                                              new XAttribute("iconClosed", attr.IconClosed),
                                              new XAttribute("iconOpen", attr.IconOpen),
                                              // don't add the assembly, we don't need this:
                                              //	http://issues.umbraco.org/issue/U4-1360
                                              //new XAttribute("assembly", assemblyName),
                                              //new XAttribute("type", typeName),
                                              // instead, store the assembly type name
                                              new XAttribute("type", type.GetFullNameWithAssembly()),
                                              new XAttribute("action", attr.Action)));
                }

                //add any trees that were found in the database that don't exist in the config

                var db    = ApplicationContext.Current.DatabaseContext.Database;
                var exist = db.TableExist("umbracoAppTree");
                if (exist)
                {
                    var appTrees = db.Fetch <AppTreeDto>("WHERE treeAlias NOT IN (" + inString + ")");
                    foreach (var appTree in appTrees)
                    {
                        var action = appTree.Action;

                        doc.Root.Add(new XElement("add",
                                                  new XAttribute("silent", appTree.Silent),
                                                  new XAttribute("initialize", appTree.Initialize),
                                                  new XAttribute("sortOrder", appTree.SortOrder),
                                                  new XAttribute("alias", appTree.Alias),
                                                  new XAttribute("application", appTree.AppAlias),
                                                  new XAttribute("title", appTree.Title),
                                                  new XAttribute("iconClosed", appTree.IconClosed),
                                                  new XAttribute("iconOpen", appTree.IconOpen),
                                                  new XAttribute("assembly", appTree.HandlerAssembly),
                                                  new XAttribute("type", appTree.HandlerType),
                                                  new XAttribute("action", string.IsNullOrEmpty(action) ? "" : action)));
                    }
                }
            }, true);
        }
Exemplo n.º 9
0
        public ApplicationTreeRegistrar()
        {
            //don't do anything if the application is not configured!
            if (!ApplicationContext.Current.IsConfigured)
            {
                return;
            }

            // Load all Trees by attribute and add them to the XML config
            var types = PluginManager.Current.ResolveAttributedTrees();

            var items = types
                        .Select(x =>
                                new Tuple <Type, TreeAttribute>(x, x.GetCustomAttributes <TreeAttribute>(false).Single()))
                        .Where(x => ApplicationTree.getByAlias(x.Item2.Alias) == null);

            var allAliases = ApplicationTree.getAll().Select(x => x.Alias).Concat(items.Select(x => x.Item2.Alias));
            var inString   = "'" + string.Join("','", allAliases) + "'";

            ApplicationTree.LoadXml(doc =>
            {
                foreach (var tuple in items)
                {
                    var type = tuple.Item1;
                    var attr = tuple.Item2;

                    var typeParts    = type.AssemblyQualifiedName.Split(',');
                    var assemblyName = typeParts[1].Trim();
                    var typeName     = typeParts[0].Substring(assemblyName.Length + 1).Trim();

                    doc.Root.Add(new XElement("add",
                                              new XAttribute("silent", attr.Silent),
                                              new XAttribute("initialize", attr.Initialize),
                                              new XAttribute("sortOrder", attr.SortOrder),
                                              new XAttribute("alias", attr.Alias),
                                              new XAttribute("application", attr.ApplicationAlias),
                                              new XAttribute("title", attr.Title),
                                              new XAttribute("iconClosed", attr.IconClosed),
                                              new XAttribute("iconOpen", attr.IconOpen),
                                              new XAttribute("assembly", assemblyName),
                                              new XAttribute("type", typeName),
                                              new XAttribute("action", attr.Action)));
                }

                var dbTrees = SqlHelper.ExecuteReader("SELECT * FROM umbracoAppTree WHERE treeAlias NOT IN (" + inString + ")");
                while (dbTrees.Read())
                {
                    var action = dbTrees.GetString("action");

                    doc.Root.Add(new XElement("add",
                                              new XAttribute("silent", dbTrees.GetBoolean("treeSilent")),
                                              new XAttribute("initialize", dbTrees.GetBoolean("treeInitialize")),
                                              new XAttribute("sortOrder", dbTrees.GetByte("treeSortOrder")),
                                              new XAttribute("alias", dbTrees.GetString("treeAlias")),
                                              new XAttribute("application", dbTrees.GetString("appAlias")),
                                              new XAttribute("title", dbTrees.GetString("treeTitle")),
                                              new XAttribute("iconClosed", dbTrees.GetString("treeIconClosed")),
                                              new XAttribute("iconOpen", dbTrees.GetString("treeIconOpen")),
                                              new XAttribute("assembly", dbTrees.GetString("treeHandlerAssembly")),
                                              new XAttribute("type", dbTrees.GetString("treeHandlerType")),
                                              new XAttribute("action", string.IsNullOrEmpty(action) ? "" : action)));
                }
            }, true);

            //SqlHelper.ExecuteNonQuery("DELETE FROM umbracoAppTree");
        }
Exemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TreeDefinition"/> class.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="tree">The tree.</param>
 /// <param name="app">The app.</param>
 public TreeDefinition(Type type, ApplicationTree tree, Application app)
 {
     m_treeType = type;
     m_tree = tree;
     m_app = app;
 }
Exemplo n.º 11
0
 private static void OnUpdated(ApplicationTree app, EventArgs args)
 {
     if (Updated != null)
     {
         Updated(app, args);
     }
 }
Exemplo n.º 12
0
 private static void OnNew(ApplicationTree app, EventArgs args)
 {
     if (New != null)
     {
         New(app, args);
     }
 }
Exemplo n.º 13
0
 private static void OnDeleted(ApplicationTree app, EventArgs args)
 {
     if (Deleted != null)
     {
         Deleted(app, args);
     }
 }