Esempio n. 1
0
        internal override void ProcessMenuAttribute(List <MenuAttribute> menus)
        {
            UIApplication appCommand;
            List <ApplicationMenusActionMenu> actionMenus = new List <ApplicationMenusActionMenu>();

            menus.Sort();


            foreach (var menu in menus)
            {
                if (!string.IsNullOrEmpty(menu.i18n))
                {
                    menu.String = i18NService.GetLocalizedString(menu.i18n);
                }

                if (application.Menus.Exists(menu.UniqueID) &&
                    RemoveIfNotEqual(menu))
                {
                    continue;
                }

                if (!string.IsNullOrEmpty(menu.ValidateMethod) && menu.OriginalType != null &&
                    NotAuthorized(menu))
                {
                    continue;
                }

                var actionMenu = new ApplicationMenusActionMenu();

                Logger.Debug(String.Format(Messages.MenuProcess, menu.String, menu.UniqueID));

                actionMenu.Checked   = menu.Return(x => x.Checked, "0");
                actionMenu.Enabled   = menu.Return(x => x.Enabled, "1");
                actionMenu.FatherUID = menu.FatherUID;
                if (!string.IsNullOrWhiteSpace(menu.Image))
                {
                    actionMenu.Image = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, menu.Image);
                }
                actionMenu.String   = menu.String;
                actionMenu.Type     = ((int)menu.Type).ToString();
                actionMenu.UniqueID = menu.UniqueID;
                if (menu.Position > 0)
                {
                    actionMenu.Position = menu.Position.ToString();
                }
                actionMenus.Add(actionMenu);
            }
            appCommand = new UIApplication()
            {
                Menus = new ApplicationMenus[] {
                    new ApplicationMenus()
                    {
                        action = new ApplicationMenusAction[] {
                            new ApplicationMenusAction()
                            {
                                type = "add",
                                Menu = actionMenus.ToArray()
                            }
                        }
                    }
                }
            };

            string xml = appCommand.Serialize();

            Logger.Debug(DebugString.Format(Messages.MenuStart, xml));
            try
            {
                application.LoadBatchActions(ref xml);
            }
            catch (Exception e)
            {
                Logger.Error(String.Format(Messages.MenuError, e.Message), e);
                throw e;
            }
            ParseBatchResult(application.GetLastBatchResults());

            Logger.Debug(Messages.MenuEnd);
        }