public ElementType() { MetaService = LocalUtils.MetaService; Model = LocalUtils.GetModel(); Project = LocalUtils.GetActiveProjectNode(); }
public void AppendToActiveProject(INamedObject edt) { VSProjectNode activeProjectNode = GetActiveProjectNode(); activeProjectNode.AddModelElementsToProject(new List <MetadataReference> { new MetadataReference(edt.Name, edt.GetType()) }); }
/// <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); }
/// <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); } }
/// <summary> /// Append createds privilege to active project /// </summary> /// <param name="privilege">Recently created privilege</param> /// <remarks>This method could be improved. Most probably are better ways to achieve this goal.</remarks> protected void appendToProject(AxSecurityPrivilege privilege) { DTE dte = CoreUtility.ServiceProvider.GetService(typeof(DTE)) as DTE; if (dte == null) { throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "No service for DTE found. The DTE must be registered as a service for using this API.", new object[0])); } VSProjectNode activeProjectNode = PrivilegeEngine.GetActiveProjectNode(dte); activeProjectNode.AddModelElementsToProject(new List <MetadataReference> { new MetadataReference(privilege.Name, privilege.GetType()) }); //var projectService = ServiceLocator.GetService(typeof(IDynamicsProjectService)) as IDynamicsProjectService; //projectService.AddElementToActiveProject(privilege); }