コード例 #1
0
        public override void Initialize(string name, NameValueCollection attributes)
        {
            base.Initialize(name, attributes);
            CreatingSiteMapNodeEventHandler += OnCreatingSiteMapNode;

            using (var manager = new FunctionManager(null))
                functions = manager.GetAllFunctions().ToList();

            RegisterFunctions(RootNode);
        }
コード例 #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);
            }
        }