/// <summary>
        /// Perform the full SiteMapTree and register functions
        /// </summary>
        /// <param name="node">SiteMapNode that will registered</param>
        /// <returns>Id the function</returns>
        protected virtual void RegisterFunctions(SiteMapNode node)
        {
            node.ReadOnly = false;
            isRegisterFunctions = true;

            //
            // Check if the function is registered
            //
            var function = new Function();
            string permissionRequiredKey = Resources.PermissionRequiredKey;
            if (!String.IsNullOrEmpty(node[permissionRequiredKey]))
            {
                //
                // Get the full path name
                //
                String title = node.Title;
                SiteMapNode parentNode = node.ParentNode;
                while (parentNode != null && !String.IsNullOrEmpty(parentNode.Title))
                {
                    title = parentNode.Title + " > " + title;
                    parentNode = parentNode.ParentNode;
                }
                title = title.Trim().Trim('>').Trim();


                function = functions.Where(f => f.Name == title).FirstOrDefault() ?? new Function();
                function.Name = title;
                if (function.FunctionId == 0)
                {
                    function.CodeName = node[permissionRequiredKey].Trim();
                    using (var manager = new FunctionManager(null))
                        manager.Insert(function);
                }
                else
                {
                    node.ResourceKey = function.FunctionId.ToString();
                    if (!String.IsNullOrEmpty(function.Description))
                        node.Description = function.Description;


                    if (!String.IsNullOrEmpty(node.ParentNode.ResourceKey))
                        if (function.ParentId.ToString() != node.ParentNode.ResourceKey)
                            using (var manager = new FunctionManager(null))
                            {
                                // Recupera do banco para criar o link e deixar o objeto ativo
                                function = manager.GetFunction(title);
                                function.ParentId = Convert.ToInt32(node.ParentNode.ResourceKey);
                                manager.DbContext.SubmitChanges();
                            }
                }

            }

            var args = new CreatingSiteMapNodeArgs(node, node[permissionRequiredKey], function.FunctionId);
            CreatingSiteMapNodeEventHandler(new object(), args);

            isRegisterFunctions = false;


            //
            // Perfoms the tree
            //
            foreach (SiteMapNode childNode in node.ChildNodes) RegisterFunctions(childNode);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Perform the full SiteMapTree and register functions
        /// </summary>
        /// <param name="node">SiteMapNode that will registered</param>
        /// <returns>Id the function</returns>
        protected virtual void RegisterFunctions(SiteMapNode node)
        {
            node.ReadOnly       = false;
            isRegisterFunctions = true;

            //
            // Check if the function is registered
            //
            var    function = new Function();
            string permissionRequiredKey = Resources.PermissionRequiredKey;

            if (!String.IsNullOrEmpty(node[permissionRequiredKey]))
            {
                //
                // Get the full path name
                //
                String      title      = node.Title;
                SiteMapNode parentNode = node.ParentNode;
                while (parentNode != null && !String.IsNullOrEmpty(parentNode.Title))
                {
                    title      = parentNode.Title + " > " + title;
                    parentNode = parentNode.ParentNode;
                }
                title = title.Trim().Trim('>').Trim();


                function      = functions.Where(f => f.Name == title).FirstOrDefault() ?? new Function();
                function.Name = title;
                if (function.FunctionId == 0)
                {
                    function.CodeName = node[permissionRequiredKey].Trim();
                    using (var manager = new FunctionManager(null))
                        manager.Insert(function);
                }
                else
                {
                    node.ResourceKey = function.FunctionId.ToString();
                    if (!String.IsNullOrEmpty(function.Description))
                    {
                        node.Description = function.Description;
                    }


                    if (!String.IsNullOrEmpty(node.ParentNode.ResourceKey))
                    {
                        if (function.ParentId.ToString() != node.ParentNode.ResourceKey)
                        {
                            using (var manager = new FunctionManager(null))
                            {
                                // Recupera do banco para criar o link e deixar o objeto ativo
                                function          = manager.GetFunction(title);
                                function.ParentId = Convert.ToInt32(node.ParentNode.ResourceKey);
                                manager.DbContext.SubmitChanges();
                            }
                        }
                    }
                }
            }

            var args = new CreatingSiteMapNodeArgs(node, node[permissionRequiredKey], function.FunctionId);

            CreatingSiteMapNodeEventHandler(new object(), args);

            isRegisterFunctions = false;


            //
            // Perfoms the tree
            //
            foreach (SiteMapNode childNode in node.ChildNodes)
            {
                RegisterFunctions(childNode);
            }
        }
 protected virtual void OnCreatingSiteMapNode(object e, CreatingSiteMapNodeArgs args)
 {
 }
Exemplo n.º 4
0
 protected virtual void OnCreatingSiteMapNode(object e, CreatingSiteMapNodeArgs args)
 {
 }