Пример #1
0
        public static string Convert(this string name)
        {
            Project = LocalUtils.GetActiveProjectNode();
            ProjectParameters.Contruct();
            MetaModelProviders = ServiceLocator.GetService(typeof(IMetaModelProviders)) as IMetaModelProviders;
            MetaModelService   = MetaModelProviders.CurrentMetaModelService;

            var extension = ProjectParameters.Instance.Extension;

            var englishLabelFile =
                MetaModelService.GetLabelFileNames()
                .FirstOrDefault(
                    lableFileName => lableFileName.StartsWith(extension) && lableFileName.Contains("en-US"));

            var lableFile = MetaModelService.GetLabelFile(englishLabelFile);
            var labelKey  = name.Replace(extension, "");

            var lableTxt = Regex.Replace(labelKey, "((?<=[a-z])[A-Z]|[A-Z](?=[a-z]))", " $1").Trim().ToLower().UppercaseFirst();

            LabelControllerFactory factory = new LabelControllerFactory();
            LabelEditorController  labelEditorController = factory.GetOrCreateLabelController(lableFile, LocalUtils.Context);

            //CoreUtility.DisplayInfo(labelKey);

            if (!labelEditorController.Exists(labelKey))
            {
                labelEditorController.Insert(labelKey, lableTxt, string.Empty);
                labelEditorController.Save();
            }

            return($"@{extension}Labels:{labelKey}");
        }
Пример #2
0
        public static string Convert(this string name, string alternative = null)
        {
            Project = GetActiveProjectNode();
            ProjectParameters.Contruct();

            MetaModelProviders = CoreUtility.ServiceProvider.GetService(typeof(IMetaModelProviders)) as IMetaModelProviders;
            if (MetaModelProviders != null)
            {
                MetaModelService = MetaModelProviders.CurrentMetaModelService;
            }

            var extension             = ProjectParameters.Instance.Extension;
            var defaultLablesFileName = ProjectParameters.Instance.DefaultLabelsFileName;

            if (string.IsNullOrEmpty(defaultLablesFileName))
            {
                throw new System.Exception(
                          "Label file name not specified in the Settings: Dynamics 365 > Addins > Ninja DevTools Settings");
            }

            var lableFile = MetaModelService.GetLabelFile(defaultLablesFileName);

            if (lableFile == null)
            {
                throw new Exception("Labels file not found");
            }

            var    labelKey = name.Replace(extension, "");
            string lableTxt;

            if (alternative != null && !alternative.StartsWith("@"))
            {
                lableTxt = alternative;
            }
            else
            {
                lableTxt = Regex.Replace(labelKey, "((?<=[a-z])[A-Z]|[A-Z](?=[a-z]))", " $1").Trim().ToLower().UppercaseFirst();
            }

            LabelControllerFactory factory = new LabelControllerFactory();
            LabelEditorController  labelEditorController = factory.GetOrCreateLabelController(lableFile, LocalUtils.Context);

            if (!labelEditorController.Exists(labelKey))
            {
                labelEditorController.Insert(labelKey, lableTxt, string.Empty);
                labelEditorController.Save();
            }

            return($"@{extension}Labels:{labelKey}");
        }
Пример #3
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(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);
            }
        }
Пример #4
0
        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);
            }
        }