示例#1
0
        public static LabelContent FindLabelGlobally_OLD(string labelIdText)
        {
            //string labelId = String.Empty;
            LabelContent labelContent = new LabelContent()
            {
                LabelIdForProperty = labelIdText
            };

            if (labelIdText.StartsWith("@") == false)
            {
                return(labelContent);
            }

            //var labelFileId
            labelContent.LabelFileId = LabelHelper.GetLabelFileId(labelIdText);
            labelContent.LabelId     = labelContent.LabelIdForProperty.Substring(labelContent.LabelIdForProperty.IndexOf(":") + 1);

            // Get the label factory
            LabelControllerFactory factory = new LabelControllerFactory();

            // Get the label edit controller
            AxLabelFile labelFile = null;

            if (String.IsNullOrEmpty(labelContent.LabelFileId) == false)
            {
                // Issue with finding label file (as it seems its searching for the label file in the current model)
                labelFile = Common.CommonUtil.GetModelSaveService().GetLabelFile(labelContent.LabelFileId);
                if (labelFile == null)
                {
                    var fileName = Common.CommonUtil.GetModelSaveService().GetLabelFileNames()
                                   .Where(l => l.StartsWith(labelContent.LabelFileId) && l.Contains("en-")).FirstOrDefault();
                    labelFile = Common.CommonUtil.GetModelSaveService().GetLabelFile(fileName);
                }
            }
            else
            {
                var labelFiles = LabelHelper.GetLabelFiles();

                labelFile = labelFiles
                            .Where(l => l.LabelFileId.Equals(labelContent.LabelFileId, StringComparison.InvariantCultureIgnoreCase))
                            .First();
            }
            if (labelFile != null)
            {
                LabelEditorController labelController = factory.GetOrCreateLabelController(labelFile, Common.CommonUtil.GetVSApplicationContext());
                labelController.LabelSearchOption = SearchOption.MatchExactly;
                labelController.IsMatchExactly    = true;

                var test  = labelController.Labels.ToList();
                var label = labelController.Labels.Where(l => l.ID.Equals(labelContent.LabelId, StringComparison.InvariantCultureIgnoreCase))
                            .FirstOrDefault();
                if (label != null)
                {
                    labelContent.LabelDescription = label.Description;
                    labelContent.LabelText        = label.Text;
                }
            }
            return(labelContent);
        }
示例#2
0
        public string GetLabel(string label)
        {
            string labelId = LabelHelper.FindOrCreateLabel(label);

            if (labelId.Equals(label) == false)
            {
                return(labelId);
            }

            return(label);
        }
示例#3
0
        public static IList <AxLabelFile> GetLabelFilesSettings()
        {
            List <AxLabelFile> labelFilesToUpdate = new List <AxLabelFile>();

            Settings.FetchSettings.FindOrCreateSettings().LabelsToUpdate.ForEach(
                labelFileName =>
            {
                var axLabelFile = Common.CommonUtil.GetModelSaveService().GetLabelFile(labelFileName);
                labelFilesToUpdate.Add(axLabelFile);
            });

            if (labelFilesToUpdate.Count == 0)
            {
                return(LabelHelper.GetLabelFiles());
            }

            return(labelFilesToUpdate);
        }
示例#4
0
        public static LabelContent FindLabel(string labelIdText)
        {
            //string labelId = String.Empty;
            LabelContent labelContent = new LabelContent()
            {
                LabelIdForProperty = labelIdText
            };

            if (labelIdText.StartsWith("@") == false)
            {
                return(labelContent);
            }

            //var labelFileId
            labelContent.LabelFileId = LabelHelper.GetLabelFileId(labelIdText);
            labelContent.LabelId     = labelContent.LabelIdForProperty.Substring(labelContent.LabelIdForProperty.IndexOf(":") + 1);

            // Get the label factory
            LabelControllerFactory factory = new LabelControllerFactory();

            // Get the label edit controller
            var labelFiles = LabelHelper.GetLabelFiles();

            var labelFile = labelFiles
                            .Where(l => l.LabelFileId.Equals(labelContent.LabelFileId, StringComparison.InvariantCultureIgnoreCase))
                            .First();

            if (labelFile != null)
            {
                LabelEditorController labelController = factory.GetOrCreateLabelController(labelFile, Common.CommonUtil.GetVSApplicationContext());
                labelController.LabelSearchOption = SearchOption.MatchExactly;
                labelController.IsMatchExactly    = true;


                var label = labelController.Labels.Where(l => l.ID.Equals(labelContent.LabelId, StringComparison.InvariantCultureIgnoreCase))
                            .First();
                //if (label != null)
                {
                    labelContent.LabelDescription = label.Description;
                    labelContent.LabelText        = label.Text;
                }
            }
            return(labelContent);
        }
示例#5
0
        public static string FindOrCreateLabel(string labelText)
        {
            string newLabelId = String.Empty;

            //Is the labeltext Already a label?
            if (labelText.StartsWith("@"))
            {
                return(labelText);
            }

            // Don't bother if the string is empty
            if (String.IsNullOrEmpty(labelText) == false)
            {
                // Construct a label id that will be unique
                //string labelId = $"{elementName}{propertyName}";

                string labelId = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(labelText)
                                 .Replace(" ", "")                 // remove spaces
                                 .Replace("%", "P")                // Replace %1 with P1 or %2 with P2 etc
                                 .Replace("_", "");
                if (Regex.IsMatch(labelId.Substring(0, 1), @"\d")) // label id cannot start with a number
                {
                    labelId = "Label" + labelId;
                }
                labelId = Regex.Replace(labelId, "[^a-zA-Z0-9]", ""); // no special chars in the label id
                // Get the label factory
                LabelControllerFactory factory = new LabelControllerFactory();

                // Get the label edit controller
                var labelFiles = LabelHelper.GetLabelFiles();

                var labelFile = labelFiles.First();

                LabelEditorController labelController = factory.GetOrCreateLabelController(labelFile, Common.CommonUtil.GetVSApplicationContext());
                labelController.LabelSearchOption = SearchOption.MatchExactly;
                labelController.IsMatchExactly    = true;

                // Make sure the label doesn't exist.
                // What will you do if it does?
                //var labelsx = labelController.Labels.ToList();
                if (labelController.Exists(labelId) == false &&
                    labelController.Exists(labelText) == false)    // the label text may be an Id by itself
                {
                    labelController.Insert(labelId, labelText, null);
                    labelController.Save();
                    Common.CommonUtil.AddElementToProject(labelFile);

                    // Construct a label reference to go into the label property
                    // newLabelId = $"@{labelFile.LabelFileId}:{labelId}";

                    //Create this label in the other languages as well.
                    foreach (var labelFileToAdd in labelFiles)
                    {
                        if (labelFileToAdd.LabelFileId == labelFile.LabelFileId &&
                            !labelFileToAdd.Language.Equals(labelFile.Language))
                        {
                            LabelEditorController labelControllerToAdd = factory.GetOrCreateLabelController(labelFileToAdd, Common.CommonUtil.GetVSApplicationContext());
                            labelControllerToAdd.Insert(labelId, labelText, null);
                            labelControllerToAdd.Save();
                            Common.CommonUtil.AddElementToProject(labelFileToAdd);
                        }
                    }
                }
                newLabelId = $"@{labelFile.LabelFileId}:{labelId}";
            }

            return(newLabelId);
        }
 protected void createLabelsTable(ITable table)
 {
     table.Label = LabelHelper.FindOrCreateLabel(table.Label);
     table.DeveloperDocumentation = LabelHelper.FindOrCreateLabel(table.DeveloperDocumentation);
 }