/// <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(AddinDesignerEventArgs e) { try { StringBuilder messages = new StringBuilder(); // SelectedElements is a collection of objects; you can iterate it as such foreach (object o in e.SelectedElements) { // Here you would do something } // It's better to use a more specific type, such as NamedElement. // This add-in accepts both classes and methods and this block // will handle both. foreach (NamedElement el in e.SelectedElements.OfType<NamedElement>()) { messages.AppendLine($"You selected {el.GetType().Name} named {el.Name}."); } // You can also select only elements of a specific type - class methods in this case. var onlyMethods = e.SelectedElements.OfType<IMethod>(); messages.AppendLine($"You selected {onlyMethods.Count()} method(s)."); // Show messages in a dialog box. CoreUtility.DisplayInfo(messages.ToString()); } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
/// <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(AddinDesignerEventArgs e) { try { StringBuilder messages = new StringBuilder(); // Get the selected element as a base type "NamedElement". Maybe you don't need to know the specific // type, because you just want to dump element names, for example. You still can check the type later // and run any type-specific logic. NamedElement namedElement = e.SelectedElement as NamedElement; if (namedElement != null) { messages.AppendLine($"You selected {namedElement.GetType().Name} named {namedElement.Name}."); } // If you're looking for a specific type, try to cast the selected item directly to the type. ClassItem c = e.SelectedElement as ClassItem; if (c != null) { int methodCount = c.Methods.Cast<IMethod>().Count(); // Calculating number of methods messages.AppendLine($"The class has {methodCount} method(s)."); } // Show messages in a dialog box. CoreUtility.DisplayInfo(messages.ToString()); } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
/// <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(AddinDesignerEventArgs e) { try { // we will create Extension class here var selectedElement = e.SelectedElement as Microsoft.Dynamics.Framework.Tools.MetaModel.Automation.IRootElement; if (selectedElement != null) { // Find current model var modelSaveInfo = Common.CommonUtil.GetCurrentModelSaveInfo(); var metaModelService = Common.CommonUtil.GetModelSaveService(); // Create a class with the same name + _Extension and add it to the project string className = Common.CommonUtil.GetNextClassExtensionName(selectedElement.Name); string intrinsicStr = String.Empty; if (selectedElement is ITable || selectedElement is IDataEntityView) { intrinsicStr = "tableStr"; } else if (selectedElement is IClassItem) { intrinsicStr = "classStr"; } else if (selectedElement is IForm) { intrinsicStr = "formStr"; } Microsoft.Dynamics.AX.Metadata.MetaModel.AxClass extensionClass; string extensionOfStr = $"ExtensionOf({intrinsicStr}({selectedElement.Name}))"; // Find an existing class where the extension is already used extensionClass = ClassHelper.GetExistingExtensionClass(selectedElement.Name, extensionOfStr); if (extensionClass == null) { extensionClass = new AxClass() { Name = className }; extensionClass.SourceCode.Declaration = $"[{extensionOfStr}]\npublic final class {className}\n{{\n\n}}"; } metaModelService.CreateClass(extensionClass, modelSaveInfo); Common.CommonUtil.AddElementToProject(extensionClass); } else if (e.SelectedElement is IFormDataSource) { this.createFormDSExtension(e.SelectedElement as IFormDataSource); } } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
/// <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(AddinDesignerEventArgs e) { try { // we will create Extension class here var selectedElement = e.SelectedElement as Microsoft.Dynamics.Framework.Tools.MetaModel.Automation.IRootElement; if (selectedElement != null) { // Find current model var modelSaveInfo = Common.CommonUtil.GetCurrentModelSaveInfo(); var metaModelService = Common.CommonUtil.GetModelSaveService(); var metadataType = selectedElement.GetMetadataType(); // Create a class with the same name + _Extension and add it to the project // ClassName string baseClassName = selectedElement.Name + "_Extension"; string className = baseClassName; int numClassesFound = 0; while (metaModelService.GetClass(className) != null) { numClassesFound++; className = baseClassName + numClassesFound.ToString(); } string intrinsicStr = String.Empty; if (selectedElement is ITable || selectedElement is IDataEntityView) { intrinsicStr = "tableStr"; } else if (selectedElement is IClassItem) { intrinsicStr = "classStr"; } else if (selectedElement is IForm) { intrinsicStr = "formStr"; } Microsoft.Dynamics.AX.Metadata.MetaModel.AxClass extensionClass = new AxClass() { Name = className }; extensionClass.SourceCode.Declaration = $"[ExtensionOf({intrinsicStr}({selectedElement.Name}))]\npublic final class {className}\n{{\n\n}}"; metaModelService.CreateClass(extensionClass, modelSaveInfo); Common.CommonUtil.AddElementToProject(extensionClass); } } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
/// <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(AddinDesignerEventArgs e) { //Microsoft.Dynamics.AX.Metadata.Core.MetaModel.EntryPointType entryPointType; try { //var modelSettings = Settings.FetchSettings.FindOrCreateSettings(); var selectedItem = e.SelectedElement as INamedElement; if (selectedItem != null) { //var metadataType = selectedItem.GetMetadataType(); EdtLabelInfo edtLabelInfo = new EdtLabelInfo(); if (selectedItem is IEdtBase) { var axEdt = Common.CommonUtil.GetModelSaveService().GetExtendedDataType(selectedItem.Name); edtLabelInfo = this.getEdtBaseLabel(axEdt, edtLabelInfo); } else if (selectedItem is BaseField) { var axBaseField = selectedItem as BaseField; edtLabelInfo = this.getTableFieldLabel(axBaseField, edtLabelInfo); } else if (selectedItem is IDataEntityViewField) { var axEntityField = selectedItem as IDataEntityViewField; edtLabelInfo = this.getDataEntityFieldLabel(axEntityField, edtLabelInfo); } else if (selectedItem is IDataEntityView) { var dataEntity = selectedItem as IDataEntityView; if (String.IsNullOrEmpty(edtLabelInfo.Label) == true && String.IsNullOrEmpty(dataEntity.Label) == false) { // find the label here edtLabelInfo.Label = dataEntity.Label; } if (String.IsNullOrEmpty(edtLabelInfo.HelpLabel) == true && String.IsNullOrEmpty(dataEntity.DeveloperDocumentation) == false) { // find the help label here edtLabelInfo.HelpLabel = dataEntity.DeveloperDocumentation; } } edtLabelInfo.DecypherLabels(); System.Windows.Forms.MessageBox.Show("Label: " + edtLabelInfo.Label + Environment.NewLine + "Help: " + edtLabelInfo.HelpLabel); } } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
/// <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(AddinDesignerEventArgs e) { try { ClassItem classItem = e.SelectedElement as ClassItem; Building.ClassDevDocEngine engine = new Building.ClassDevDocEngine(classItem); engine.run(); } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
/// <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(AddinDesignerEventArgs e) { try { INamedElement namedElement = e.SelectedElement as INamedElement; if (namedElement != null) { //Common.CommonUtil.AddElementToProject(namedObject); AddToProjectMenuAddIn.AddExistingElementToProject(namedElement); } } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
/// <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(AddinDesignerEventArgs e) { try { if (e.SelectedElement is IMethodBase) { var methodBase = (IMethodBase)e.SelectedElement; string methodTxt = new CopyExtensionMethodParams().CreateMethod(methodBase); Clipboard.SetText(methodTxt); } } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
public override void OnClick(AddinDesignerEventArgs e) { try { ClassItem c = e.SelectedElement as ClassItem; if (c != null) { AddMethodToFile(c); //CallAddMethodCommand(c); } } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
/// <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(AddinDesignerEventArgs e) { //Microsoft.Dynamics.AX.Metadata.Core.MetaModel.EntryPointType entryPointType; try { // we will create 2 security privileges for the menu item with the same name + Maintain, +View var selectedElement = e.SelectedElement as IBaseField; if (selectedElement != null) { this.CreateEDT(selectedElement); } } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
/// <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(AddinDesignerEventArgs e) { try { MenuItem menuItem = e.SelectedElement as MenuItem; if (menuItem != null) { Building.PrivilegeEngine engine = new Building.PrivilegeEngine(menuItem); engine.run(); } } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
/// <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(AddinDesignerEventArgs e) { try { var selectedMenuItem = e.SelectedElement as Microsoft.Dynamics.Framework.Tools.MetaModel.Automation.Forms.IForm; if (selectedMenuItem != null) { //var metadataType = selectedMenuItem.GetMetadataType(); var metaModelService = Common.CommonUtil.GetModelSaveService(); AxForm axForm = metaModelService.GetForm(selectedMenuItem.Name); this.CheckPattern(axForm); } } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
/// <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(AddinDesignerEventArgs e) { try { NamedElement element = e.SelectedElement as NamedElement; FormController controller = new FormController(); if (controller.prompt()) { Building.NewFieldEngine engine = new Building.NewFieldEngine(controller, element); engine.run(); } } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
/// <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(AddinDesignerEventArgs e) { Microsoft.Dynamics.AX.Metadata.Core.MetaModel.EntryPointType entryPointType; try { // we will create 2 security privileges for the menu item with the same name + Maintain, +View var selectedMenuItem = e.SelectedElement as IMenuItem; if (selectedMenuItem != null) { var metadataType = selectedMenuItem.GetMetadataType(); if (selectedMenuItem is IMenuItemAction) { entryPointType = Microsoft.Dynamics.AX.Metadata.Core.MetaModel.EntryPointType.MenuItemAction; } else if (selectedMenuItem is IMenuItemDisplay) { entryPointType = Microsoft.Dynamics.AX.Metadata.Core.MetaModel.EntryPointType.MenuItemDisplay; } else if (selectedMenuItem is IMenuItemOutput) { entryPointType = Microsoft.Dynamics.AX.Metadata.Core.MetaModel.EntryPointType.MenuItemOutput; } else { return; } this.createSecurityElement_FromMenuItem(selectedMenuItem, entryPointType, "Maintain"); this.createSecurityElement_FromMenuItem(selectedMenuItem, entryPointType, "View"); } else if (e.SelectedElement is IDataEntityView) { IDataEntityView selectedElementDataEntity = e.SelectedElement as IDataEntityView; this.createSecurityElement_FromDataEntity(selectedElementDataEntity, "Maintain"); this.createSecurityElement_FromDataEntity(selectedElementDataEntity, "View"); } } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
public override void OnClick(AddinDesignerEventArgs e) { try { if (e.SelectedElement != null) { MenuItemBuilderDialog dialog = new MenuItemBuilderDialog(); MenuItemBuilderParms parms = new MenuItemBuilderParms(); parms.InitFromSelectedElement(e.SelectedElement); dialog.SetParameters(parms); dialog.ShowDialog(); } } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
public override void OnClick(AddinDesignerEventArgs e) { try { if (e.SelectedElement != null) { AddTableFindMethodDialog dialog = new AddTableFindMethodDialog(); AddTableFindMethodParms parms = new AddTableFindMethodParms(); parms.InitFromSelectedElement(e); dialog.SetParameters(parms); dialog.ShowDialog(); } } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
/// <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(AddinDesignerEventArgs e) { try { IElement element = Element.construct(e.SelectedElement as NamedElement); BPCheck bpCheck = new BPCheck(); Build build = new Build(); Sync sync = new Sync(); element.accept(bpCheck); element.accept(build); element.accept(sync); } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
/// <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(AddinDesignerEventArgs e) { //Microsoft.Dynamics.AX.Metadata.Core.MetaModel.EntryPointType entryPointType; try { var selectedItem = e.SelectedElement as Microsoft.Dynamics.Framework.Tools.MetaModel.Automation.IRootElement; if (selectedItem != null) { var metadataType = selectedItem.GetMetadataType(); LabelFactory labelFactory = LabelFactory.construct(selectedItem); labelFactory.ApplyLabel(); } } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
/// <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(AddinDesignerEventArgs e) { try { //var selectedItem = e.SelectedElement as ISecurityPrivilege; if (e.SelectedElement is ISecurityPrivilege) { //var metadataType = selectedItem.GetMetadataType(); SecurityDutyCreator.CreateDuty_fromSecPriv(e.SelectedElement as ISecurityPrivilege, Common.Constants.MAINTAIN); //this.createSecurityElement_FromMenuItem(selectedItem, entryPointType, "Maintain"); //this.createSecurityElement_FromMenuItem(selectedItem, entryPointType, "View"); } } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
/// <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(AddinDesignerEventArgs e) { ProjectParameters.Contruct(); try { var metaModelProviders = ServiceLocator.GetService(typeof(IMetaModelProviders)) as IMetaModelProviders; var metaModelService = metaModelProviders?.CurrentMetaModelService; var table = (ITable)e.SelectedElement; var axTable = (AxTable)table.GetMetadataType(); var extension = ProjectParameters.Instance?.Extension; if (string.IsNullOrWhiteSpace(extension)) { throw new Exception("Please specify the prefix in the setting"); } foreach (var axTableField in axTable.Fields) { int index = axTableField.Name.IndexOf(extension, StringComparison.Ordinal); string cleanPath = index < 0 ? axTableField.Name : axTableField.Name.Remove(index, extension.Length); axTableField.Name = cleanPath; } var model = DesignMetaModelService.Instance .CurrentMetadataProvider.Tables .GetModelInfo(axTable.Name) .FirstOrDefault(); metaModelService.UpdateTable(axTable, new ModelSaveInfo(model)); } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
public override void OnClick(AddinDesignerEventArgs e) { try { ITable t = e.SelectedElement as ITable; if (t != null) { if (t.CanExecute(CommandType.TableBrowse)) // Check if the command can be executed { t.Execute(CommandType.TableBrowse); } // For more commands, look at avaiable values of CommandType enum } } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
public override void OnClick(AddinDesignerEventArgs e) { try { NamedElement element = e.SelectedElement as NamedElement; if (element != null) { TableFieldsBuilderDialog dialog = new TableFieldsBuilderDialog(); TableFieldsBuilderParms parms = new TableFieldsBuilderParms(); parms.TableName = element.Name; dialog.SetParameters(parms); dialog.Show(); } } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
public override void OnClick(AddinDesignerEventArgs e) { try { if (e.SelectedElement is EdtBase) { var form = (EdtBase)e.SelectedElement; TableBuilderDialog dialog = new TableBuilderDialog(); TableBuilderParms parms = new TableBuilderParms(); parms.PrimaryKeyEdtName = form.Name; dialog.SetParameters(parms); DialogResult formRes = dialog.ShowDialog(); } } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
public override void OnClick(AddinDesignerEventArgs e) { try { NamedElement element = e.SelectedElement as NamedElement; if (element != null) { FormBuilderDialog dialog = new FormBuilderDialog(); FormBuilderParms parms = new FormBuilderParms(); parms.TableName = element.Name; parms.InitFromTable(); dialog.SetParameters(parms); DialogResult formRes = dialog.ShowDialog(); } } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
public void InitFromSelectedElement(AddinDesignerEventArgs e) { if (_axHelper == null) { _axHelper = new AxHelper(); } BaseField baseField = e.SelectedElements.OfType <BaseField>().First(); SelectedField = baseField.Name; TableName = baseField.Table != null?baseField.Table.GetMetadataType().Name : baseField.TableExtension?.GetMetadataType().Name; NewFieldEngine newFieldEngine = new NewFieldEngine(); newFieldEngine.GetSetHelper = _axHelper; if (TableName.Contains(".") == false) { _axTable = _axHelper.MetadataProvider.Tables.Read(TableName); AxTableField axTableField = _axTable.Fields[baseField.Name]; TableRelationForeignKey = newFieldEngine.AddTableRelation(axTableField, _axTable.Relations); } else { _axTableExtension = _axHelper.MetadataProvider.TableExtensions.Read(TableName); AxTableField axTableField = _axTableExtension.Fields[baseField.Name]; TableRelationForeignKey = newFieldEngine.AddTableRelation(axTableField, _axTableExtension.Relations); } if (TableRelationForeignKey == null) { throw new System.Exception($"Field {baseField.Name} doesn't have an EDT relation"); } RelationName = TableRelationForeignKey.Name; }
/// <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(AddinDesignerEventArgs e) { try { string logging = string.Empty; foreach (NamedElement element in e.SelectedElements) { Building.CreateLabels labels = Building.CreateLabels.construct(element); labels.run(); logging += labels.getLoggingMessage(); logging += "\n"; } CoreUtility.DisplayInfo(logging); } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
/// <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(AddinDesignerEventArgs e) { try { StringBuilder result; INamedElement namedElement = e.SelectedElement as INamedElement; if (namedElement is Tables.ITable) { result = this.GenerateFromTable(namedElement as Tables.ITable, true); } else if (namedElement is Tables.ITableExtension) { result = this.GenerateFromTableExtension(namedElement as Tables.ITableExtension, true); } else if (namedElement is Tables.IRelation) { result = this.GenerateFromTableRelations(e.SelectedElements.OfType <Tables.IRelation>()); var selectedRelations = e.SelectedElements.OfType <Tables.IRelation>(); if (selectedRelations.Any()) { result = this.GenerateFromTableRelations(selectedRelations); } } else if (namedElement is DataEntities.IDataEntityView) { result = this.GenerateFromDataEntity(namedElement as DataEntities.IDataEntityView, true); } else { throw new NotImplementedException($"Element {e.SelectedElement.ToString()} is not supported."); } if (result != null) { string message = string.Empty; int counter = 0; message += $"Counting for " + tableName; message += "\n\n"; using (SqlConnection conn = new SqlConnection(BusinessDatabaseConnectionString)) { var query = result.ToString(); query = query.Replace("\n", " "); query = query.Replace("\r", " "); query = query.Replace(" GO ", ""); conn.Open(); using (SqlCommand command = new SqlCommand(query, conn)) { using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { if (reader.FieldCount == 1) { string counterLocStr = reader["COUNTER"].ToString(); counter += int.Parse(counterLocStr); } else { string dataAreaId = reader["DATAAREAID"].ToString(); string counterLocStr = reader["COUNTER"].ToString(); message += $"{dataAreaId.ToUpper()}: {int.Parse(counterLocStr)}"; counter += int.Parse(counterLocStr); } } } } conn.Close(); } message += "\n\n"; message += $"Total: {counter}"; message += "\n\n"; message += "================== USED QUERY ===================\n"; message += result.ToString(); message += "==============================================="; message += "\n\n"; message += "Do you want to open this query in MSSQL Management Studio?"; if (CoreUtility.PromptYesNo(message, "Counting records")) { // Save the SQL file and open it in SQL management studio. string temporaryFileName = Path.GetTempFileName(); // Rename and move var sqlFileName = temporaryFileName.Replace(".tmp", ".sql"); File.Move(temporaryFileName, sqlFileName); // Store the script in the file File.AppendAllText(sqlFileName, result.ToString()); //var dte = CoreUtility.ServiceProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE; //dte.ExecuteCommand("File.OpenFile", sqlFileName); Process sqlManagementStudio = new Process(); sqlManagementStudio.StartInfo.FileName = sqlFileName; sqlManagementStudio.StartInfo.UseShellExecute = true; sqlManagementStudio.StartInfo.WindowStyle = ProcessWindowStyle.Normal; sqlManagementStudio.Start(); } } } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
/// <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(AddinDesignerEventArgs e) { try { var field = (BaseField)e.SelectedElement; var dialog = new CreateIndex(); dialog.CreateIndexVm.IndexName = field.Name + "_Idx"; dialog.ShowDialog(); var axTable = (AxTable)field.Table.GetMetadataType(); var index = new AxTableIndex(); index.Name = dialog.CreateIndexVm.IndexName; index.AllowDuplicates = dialog.CreateIndexVm.AllowDuplicates ? NoYes.Yes : NoYes.No; index.AlternateKey = dialog.CreateIndexVm.AlternativeKey ? NoYes.Yes : NoYes.No; e.SelectedElements.OfType <BaseField>() .ToList().ForEach(f => { var fieldIndex = new AxTableIndexField { DataField = f.Name, Name = f.Name }; index.AddField(fieldIndex); }); // Add the method to the class axTable.AddIndex(index); var fieldNameCamelCase = field.Name.ToCamelCase(); var tableNameCamelCase = axTable.Name.ToCamelCase(); var source = $@"public static {axTable.Name} findBy{field.Name} ({field.ExtendedDataType} _{fieldNameCamelCase}, boolean _forUpdate = false) {{ {axTable.Name} {tableNameCamelCase}; {tableNameCamelCase}.selectForUpdate(_forUpdate); if(_{fieldNameCamelCase}) select firstonly {tableNameCamelCase} where {tableNameCamelCase}.{field .Name} == _{fieldNameCamelCase}; return {tableNameCamelCase}; }}"; axTable.AddMethod(BuildMethod(field.Name, source)); var metaModelProviders = ServiceLocator.GetService(typeof(IMetaModelProviders)) as IMetaModelProviders; var metaModelService = metaModelProviders.CurrentMetaModelService; var model = DesignMetaModelService.Instance.CurrentMetadataProvider.Tables.GetModelInfo(axTable.Name) .FirstOrDefault(); // Update the file metaModelService.UpdateTable(axTable, new ModelSaveInfo(model)); } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
public override void OnClick(AddinDesignerEventArgs e) { if (ProjectParameters.Instance == null) { ProjectParameters.Contruct(); } try { if (e.SelectedElement is ITable) { var table = e.SelectedElement as ITable; table.Label = table.Name.Convert(table.Label); } if (e.SelectedElement is IForm) { var form = e.SelectedElement as IForm; form.FormDesign.Caption = form.Name.Convert(); } if (e.SelectedElement is IBaseEnum) { var @enum = e.SelectedElement as IBaseEnum; @enum.Label = @enum.Name.Convert(); } if (e.SelectedElement is IEdtBase) { var edt = e.SelectedElement as IEdtBase; edt.Label = edt.Name.Convert(); } if (e.SelectedElement is IBaseField) { var edt = e.SelectedElement as IBaseField; edt.Label = edt.Name.Convert(); } if (e.SelectedElement is Menu.IMenuItemDisplay) { var menu = e.SelectedElement as Menu.IMenuItemDisplay; menu.Label = menu.Name.Convert(); } if (e.SelectedElement is Menu.IMenuItemOutput) { var menu = e.SelectedElement as Menu.IMenuItemOutput; menu.Label = menu.Name.Convert(); } if (e.SelectedElement is Menu.IMenu) { var menu = e.SelectedElement as Menu.IMenu; menu.Label = menu.Name.Convert(); } if (e.SelectedElement is IBaseEnumValue) { var menu = e.SelectedElement as IBaseEnumValue; menu.Label = menu.Name.Convert(); } } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
/// <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(AddinDesignerEventArgs e) { try { StringBuilder result = null; TablesAutomation.ITable selectedTable; if ((selectedTable = e.SelectedElement as TablesAutomation.ITable) != null) { result = this.GenerateFromTable(selectedTable); } if (result == null) { ViewsAutomation.IView selectedView; if ((selectedView = e.SelectedElement as ViewsAutomation.IView) != null) { result = this.GenerateFromView(selectedView); } } if (result == null) { TablesAutomation.ITableExtension selectedTableExtension; if ((selectedTableExtension = e.SelectedElement as TablesAutomation.ITableExtension) != null) { result = this.GenerateFromTableExtension(selectedTableExtension); } } // Individually selected table fields. if (result == null) { var selectedFields = e.SelectedElements.OfType <TablesAutomation.IBaseField>(); if (selectedFields.Any()) { result = this.GenerateFromTableFieldListWithWhere(selectedFields); } } // Individually selected view fields. if (result == null) { var selectedFields = e.SelectedElements.OfType <ViewsAutomation.IViewBaseField>(); if (selectedFields.Any()) { result = this.GenerateFromViewFieldList(selectedFields); } } // Table field groups if (result == null) { var selectedFieldsGroups = e.SelectedElements.OfType <TablesAutomation.IFieldGroup>(); if (selectedFieldsGroups.Any()) { result = this.GenerateFromTableFieldGroups(selectedFieldsGroups); } } // View field groups if (result == null) { var selectedFieldsGroups = e.SelectedElements.OfType <ViewsAutomation.IFieldGroup>(); if (selectedFieldsGroups.Any()) { result = this.GenerateFromViewFieldGroups(selectedFieldsGroups); } } // Table relations if (result == null) { var selectedRelations = e.SelectedElements.OfType <TablesAutomation.IRelation>(); if (selectedRelations.Any()) { result = this.GenerateFromTableRelations(selectedRelations); } } if (result != null) { // Save the SQL file and open it in SQL management studio. string temporaryFileName = Path.GetTempFileName(); // Rename and move var sqlFileName = temporaryFileName.Replace(".tmp", ".sql"); File.Move(temporaryFileName, sqlFileName); // Store the script in the file File.AppendAllText(sqlFileName, result.ToString()); //var dte = CoreUtility.ServiceProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE; //dte.ExecuteCommand("File.OpenFile", sqlFileName); Process sqlManagementStudio = new Process(); sqlManagementStudio.StartInfo.FileName = sqlFileName; sqlManagementStudio.StartInfo.UseShellExecute = true; sqlManagementStudio.StartInfo.WindowStyle = ProcessWindowStyle.Normal; sqlManagementStudio.Start(); } } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
/// <summary> /// /Handle the click event in the OnClick method. Here we will test the selected object, get the object’s model and label file, and create the label. /// </summary> /// <param name="e">The context of the VS tools and metadata</param> public override void OnClick(AddinDesignerEventArgs e) { // Dont display Already exists message helper.PromptOnDuplicate = false; try { // Get the metamodelService IMetaModelService metaModelService = helper.MetaModelService; // Is the selected element a table? if (e.SelectedElement is ITable) { ITable table = e.SelectedElement as ITable; helper.setModelAndLabelFile(metaModelService.GetTableModelInfo(table.Name)); helper.createPropertyLabels(table, table.Name); // Loop through each BaseField. Similar logic coulde be added for FieldGroups Ect. foreach (IBaseField baseField in table.BaseFields) { var labelPrefix = String.Format("{0}_{1}", baseField.Table.Name, baseField.Name); helper.createPropertyLabels(baseField, labelPrefix); } } if (e.SelectedElement is IView) { IView view = e.SelectedElement as IView; helper.setModelAndLabelFile(metaModelService.GetViewModelInfo(view.Name)); helper.createPropertyLabels(view, view.Name); // Loop through each BaseField. Similar logic coulde be added for FieldGroups Ect. foreach (IViewBaseField baseField in view.ViewBaseFields) { var labelPrefix = String.Format("{0}_{1}", baseField.View.Name, baseField.Name); helper.createPropertyLabels(baseField, labelPrefix); } } // Is this a Form Design Element? else if (e.SelectedElement is IFormDesign) { IFormDesign formDesign = e.SelectedElement as IFormDesign; var form = formDesign.Form; helper.setModelAndLabelFile(metaModelService.GetFormModelInfo(form.Name)); helper.createPropertyLabels(formDesign, formDesign.Form.Name); // Loop through all children FormControls. this.crawlDesignControls(formDesign.VisualChildren, form.Name); } else if (e.SelectedElement is IBaseEnum) { IBaseEnum axEnum = e.SelectedElement as IBaseEnum; helper.setModelAndLabelFile(metaModelService.GetEnumModelInfo(axEnum.Name)); var labelPrefix = String.Format("{0}_{1}", Tags.EnumTag, axEnum.Name); helper.createPropertyLabels(axEnum, labelPrefix); // Was unable to locate a way of finding the parent enum of a enumValue. No model could be found without it. // Loop through all values foreach (IBaseEnumValue enumValue in axEnum.BaseEnumValues) { var enumValueLabelPrefix = String.Format("{0}_{1}_{2}", Tags.EnumTag, axEnum.Name, enumValue.Name); helper.createPropertyLabels(enumValue, enumValueLabelPrefix); } } else if (e.SelectedElement is IReport) { IReport Report = e.SelectedElement as IReport; helper.setModelAndLabelFile(metaModelService.GetReportModelInfo(Report.Name)); foreach (IReportDataSet dataSet in Report.DataSets) { foreach (IReportDataSetField dataField in dataSet.Fields) { var labelPrefix = String.Format("{0}_{1}_{2}", dataSet.Report.Name, dataSet.Name, dataField.Name); helper.createPropertyLabels(dataField, labelPrefix); } } } else if (e.SelectedElement is IReportDataSet) { IReportDataSet dataSet = e.SelectedElement as IReportDataSet; helper.setModelAndLabelFile(metaModelService.GetReportModelInfo(dataSet.Report.Name)); foreach (IReportDataSetField dataField in dataSet.Fields) { var labelPrefix = String.Format("{0}_{1}_{2}", dataSet.Report.Name, dataSet.Name, dataField.Name); helper.createPropertyLabels(dataField, labelPrefix); } } } catch (Exception ex) { Microsoft.Dynamics.Framework.Tools.MetaModel.Core.CoreUtility.HandleExceptionWithErrorMessage(ex); } }
/// <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(AddinDesignerEventArgs e) { try { StringBuilder result; INamedElement namedElement = e.SelectedElement as INamedElement; if (namedElement is TablesAutomation.ITable) { result = this.GenerateFromTable(namedElement as TablesAutomation.ITable, true); } else if (namedElement is TablesAutomation.ITableExtension) { result = this.GenerateFromTableExtension(namedElement as TablesAutomation.ITableExtension, true); } else if (namedElement is TablesAutomation.IRelation) { result = this.GenerateFromTableRelations(e.SelectedElements.OfType <TablesAutomation.IRelation>()); var selectedRelations = e.SelectedElements.OfType <TablesAutomation.IRelation>(); if (selectedRelations.Any()) { result = this.GenerateFromTableRelations(selectedRelations); } } else { throw new NotImplementedException($"Element {e.SelectedElement.ToString()} is not supported."); } if (result != null) { string message = string.Empty; int counter = 0; message += $"Counting for " + tableName; message += "\n\n"; using (SqlConnection conn = new SqlConnection(BusinessDatabaseConnectionString)) { var query = result.ToString(); query = query.Replace("\n", " "); query = query.Replace("\r", " "); query = query.Replace(" GO ", ""); conn.Open(); using (SqlCommand command = new SqlCommand(query, conn)) { using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { if (reader.FieldCount == 1) { string counterLocStr = reader["COUNTER"].ToString(); counter += int.Parse(counterLocStr); } else { string dataAreaId = reader["DATAAREAID"].ToString(); string counterLocStr = reader["COUNTER"].ToString(); message += $"{dataAreaId.ToUpper()}: {int.Parse(counterLocStr)}"; counter += int.Parse(counterLocStr); } } } } conn.Close(); } message += "\n\n"; message += $"Total: {counter}"; message += "\n\n"; message += "================== USED QUERY ===================\n"; message += result.ToString(); message += "==============================================="; CoreUtility.DisplayInfo(message); } } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }