Example #1
0
        public ElementType()
        {
            MetaService = LocalUtils.MetaService;

            Model   = LocalUtils.GetModel();
            Project = LocalUtils.GetActiveProjectNode();
        }
Example #2
0
        static AotElementCreate()
        {
            Project = LocalUtils.GetActiveProjectNode();
            ModelInfo model = Project.GetProjectsModelInfo();

            Model = new ModelSaveInfo
            {
                Id    = model.Id,
                Layer = model.Layer,
            };
        }
Example #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);
        }
Example #4
0
        /// <summary>
        /// Get model save info, used when creating an element
        /// </summary>
        /// <returns>save info</returns>
        internal static ModelSaveInfo GetCurrentModelSaveInfo()
        {
            var model = CommonUtil.GetCurrentModel();
            // Prepare information needed for saving
            ModelSaveInfo saveInfo = new ModelSaveInfo
            {
                Id    = model.Id,
                Layer = model.Layer
            };

            return(saveInfo);
        }
Example #5
0
        public static ModelSaveInfo GetModel()
        {
            var modelInfo = LocalUtils.GetActiveProjectNode().GetProjectsModelInfo();

            var model = new ModelSaveInfo
            {
                Id    = modelInfo.Id,
                Layer = modelInfo.Layer
            };

            return(model);
        }
Example #6
0
        /// <summary>
        /// Called when user clicks on the add-in menu
        /// </summary>
        /// <param name="e">The context of the VS tools and metadata</param>
        public override void OnClick(AddinEventArgs e)
        {
            try
            {
                // Find project to work with
                VSProjectNode project = LocalUtils.GetActiveProject();
                // An alternative way is calling ProjectHelper.GetProjectDetails(), but it's not consistent
                // with how projectService.AddElementToActiveProject() determines the active project.
                // ProjectHelper return the startup project, which doens't have to be the active project.

                if (project == null)
                {
                    throw new InvalidOperationException("No project selected.");
                }

                // Create a new class
                AxClass axClass = new AxClass()
                {
                    Name = "MyNewClass",
                    IsAbstract = true // Set a property for demonstration
                };

                // Find metamodel service needed below

                // Find current model
                //ModelInfo model = metaModelService.GetModel(ProjectHelper.GetProjectDetails().Model);
                ModelInfo model = project.GetProjectsModelInfo();

                // Prepare information needed for saving
                ModelSaveInfo saveInfo = new ModelSaveInfo
                {
                    Id = model.Id,
                    Layer = model.Layer
                };

                // Create class in the right model
                var metaModelProviders = ServiceLocator.GetService(typeof(IMetaModelProviders)) as IMetaModelProviders;
                var metaModelService = metaModelProviders.CurrentMetaModelService;
                metaModelService.CreateClass(axClass, saveInfo);

                // Add the class to the active project
                var projectService = ServiceLocator.GetService(typeof(IDynamicsProjectService)) as IDynamicsProjectService;
                projectService.AddElementToActiveProject(axClass);

            }
            catch (Exception ex)
            {
                CoreUtility.HandleExceptionWithErrorMessage(ex);
            }
        }
Example #7
0
        /// <summary>
        /// Called when user clicks on the add-in menu
        /// </summary>
        /// <param name="e">The context of the VS tools and metadata</param>
        public override void OnClick(AddinEventArgs e)
        {
            try
            {
                // Find project to work with
                VSProjectNode project = LocalUtils.GetActiveProject();
                // An alternative way is calling ProjectHelper.GetProjectDetails(), but it's not consistent
                // with how projectService.AddElementToActiveProject() determines the active project.
                // ProjectHelper return the startup project, which doens't have to be the active project.

                if (project == null)
                {
                    throw new InvalidOperationException("No project selected.");
                }

                // Create a new class
                AxClass axClass = new AxClass()
                {
                    Name       = "MyNewClass",
                    IsAbstract = true // Set a property for demonstration
                };

                // Find metamodel service needed below


                // Find current model
                //ModelInfo model = metaModelService.GetModel(ProjectHelper.GetProjectDetails().Model);
                ModelInfo model = project.GetProjectsModelInfo();

                // Prepare information needed for saving
                ModelSaveInfo saveInfo = new ModelSaveInfo
                {
                    Id    = model.Id,
                    Layer = model.Layer
                };

                // Create class in the right model
                var metaModelProviders = ServiceLocator.GetService(typeof(IMetaModelProviders)) as IMetaModelProviders;
                var metaModelService   = metaModelProviders.CurrentMetaModelService;
                metaModelService.CreateClass(axClass, saveInfo);

                // Add the class to the active project
                var projectService = ServiceLocator.GetService(typeof(IDynamicsProjectService)) as IDynamicsProjectService;
                projectService.AddElementToActiveProject(axClass);
            }
            catch (Exception ex)
            {
                CoreUtility.HandleExceptionWithErrorMessage(ex);
            }
        }
Example #8
0
        static AotElementCreate()
        {
            Project = LocalUtils.GetActiveProjectNode();

            if (Project == null)
            {
                throw new InvalidOperationException("No project selected.");
            }

            var model = Project.GetProjectsModelInfo();

            Model = new ModelSaveInfo
            {
                Id    = model.Id,
                Layer = model.Layer
            };
        }