void DoPrivilegeCreate()
        {
            AxSecurityPrivilege privilege;

            privilege = _axHelper.MetadataProvider.SecurityPrivileges.Read(ObjectName);
            if (privilege != null)
            {
                throw new Exception($"Privilege {ObjectName} already exists");
            }
            privilege = new AxSecurityPrivilege();
            AxSecurityEntryPointReference entryPoint = new AxSecurityEntryPointReference();

            entryPoint.Name       = MenuItemName;
            entryPoint.Grant      = GetGrant();
            entryPoint.ObjectName = MenuItemName;
            entryPoint.ObjectType = MenuItemType;

            privilege.Name = ObjectName;
            privilege.EntryPoints.Add(entryPoint);
            privilege.Label = FormLabel;

            _axHelper.MetaModelService.CreateSecurityPrivilege(privilege, _axHelper.ModelSaveInfo);
            _axHelper.AppendToActiveProject(privilege);

            AddLog($"Privilege: {privilege.Name}; ");
        }
Exemplo n.º 2
0
        void DoPrivilegeCreateSingle(string privilegeName, string privilegeLabel, AccessGrant accessGrant)
        {
            if (String.IsNullOrWhiteSpace(privilegeLabel))
            {
                return;
            }

            AxSecurityPrivilege privilege;

            privilege = _axHelper.MetadataProvider.SecurityPrivileges.Read(privilegeName);
            if (privilege != null)
            {
                return;
            }
            privilege = new AxSecurityPrivilege();
            AxSecurityEntryPointReference entryPoint = new AxSecurityEntryPointReference();

            entryPoint.Name       = FormName;
            entryPoint.Grant      = accessGrant;
            entryPoint.ObjectName = FormName;
            entryPoint.ObjectType = EntryPointType.MenuItemDisplay;

            privilege.Name = privilegeName;
            privilege.EntryPoints.Add(entryPoint);
            privilege.Label = privilegeLabel;

            _axHelper.MetaModelService.CreateSecurityPrivilege(privilege, _axHelper.ModelSaveInfo);
            _axHelper.AppendToActiveProject(privilege);

            AddLog($"Privilege: {privilege.Name}; ");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates privilege in AOT
        /// </summary>
        /// <param name="name">Privilege's name</param>
        /// <param name="grant">User chosen privilege access level</param>
        /// <remarks>This method could be improved. Most probably are better ways to achieve this goal.</remarks>
        protected void create(string name, AccessGrant grant)
        {
            AxSecurityPrivilege           privilege  = new AxSecurityPrivilege();
            AxSecurityEntryPointReference entryPoint = new AxSecurityEntryPointReference();
            ModelInfo     modelInfo;
            ModelSaveInfo modelSaveInfo = new ModelSaveInfo();
            VSProjectNode project       = Utils.LocalUtils.GetActiveProject();

            #region Create entry point
            entryPoint.Name       = this.menuItem.Name;
            entryPoint.Grant      = grant;
            entryPoint.ObjectName = this.menuItem.Name;

            switch (this.menuItem.ObjectType)
            {
            case MenuItemObjectType.Form:
                entryPoint.ObjectType = EntryPointType.MenuItemDisplay;
                break;

            case MenuItemObjectType.Class:
                entryPoint.ObjectType = EntryPointType.MenuItemAction;
                break;

            case MenuItemObjectType.SSRSReport:
                entryPoint.ObjectType = EntryPointType.MenuItemOutput;
                break;

            default:
                throw new NotImplementedException($"Menuitem object type {this.menuItem.ObjectType} is not implemented.");
            }

            #endregion

            #region Create privilege
            privilege.Name = name;
            privilege.EntryPoints.Add(entryPoint);
            privilege.Label = this.menuItem.Label;
            #endregion

            // Most probably there is a better way to do this part.
            #region Add to AOT
            modelInfo = project.GetProjectsModelInfo();

            modelSaveInfo.Id    = modelInfo.Id;
            modelSaveInfo.Layer = modelInfo.Layer;

            var metaModelProviders = ServiceLocator.GetService(typeof(IMetaModelProviders)) as IMetaModelProviders;
            var metaModelService   = metaModelProviders.CurrentMetaModelService;

            metaModelService.CreateSecurityPrivilege(privilege, modelSaveInfo);
            #endregion

            this.appendToProject(privilege);
        }