コード例 #1
0
ファイル: TagDataVisitor.cs プロジェクト: XUzxc/Sdl-Community
        private static string GetHexCode(KeyValuePair <string, IFormattingItem> formatingProperty)
        {
            try
            {
                var color  = formatingProperty.Value.StringValue;
                var colors = color.Split(',');

                if (colors.Length.Equals(1))
                {
                    var htmlColor = ColorTranslator.FromHtml(color);
                    return(ColorPickerHelper.GetHexCode(htmlColor.R, htmlColor.G, htmlColor.B));
                }

                if (colors.Length.Equals(4))
                {
                    return(ColorPickerHelper.GetHexCode(byte.Parse(colors[1]), byte.Parse(colors[2]), byte.Parse(colors[3])));
                }

                if (colors.Length.Equals(3))
                {
                    return(ColorPickerHelper.GetHexCode(byte.Parse(colors[0]), byte.Parse(colors[1]), byte.Parse(colors[2])));
                }
            }
            catch
            {
                // catch all; ignore
            }

            return(null);
        }
コード例 #2
0
        private static string GetHexCode(KeyValuePair <string, IFormattingItem> formatingProperty)
        {
            var color  = formatingProperty.Value.StringValue;
            var colors = color.Split(',');
            var red    = string.Empty;
            var green  = string.Empty;
            var blue   = string.Empty;

            //for files which color code is like this "0,12,12,12"
            if (colors.Length.Equals(4))
            {
                red   = colors[1];
                green = colors[2];
                blue  = colors[3];
            }

            //"0,12,12,12"
            if (colors.Length.Equals(3))
            {
                red   = colors[0];
                green = colors[1];
                blue  = colors[2];
            }

            var hexCode = ColorPickerHelper.GetHexCode(byte.Parse(red), byte.Parse(green), byte.Parse(blue));

            return(hexCode);
        }
コード例 #3
0
        public void VisitTagPair(ITagPair tagPair)
        {
            if (tagPair.StartTagProperties.Formatting != null)
            {
                foreach (var formatingProperty in tagPair.StartTagProperties.Formatting)
                {
                    try
                    {
                        var key = formatingProperty.Key;
                        if (!key.Equals("TextColor"))
                        {
                            continue;
                        }
                        var color  = formatingProperty.Value.StringValue;
                        var colors = color.Split(',');
                        var red    = string.Empty;
                        var green  = string.Empty;
                        var blue   = string.Empty;
                        //for  files which color code is like this "0,12,12,12"
                        if (colors.Count().Equals(4))
                        {
                            red   = colors[1];
                            green = colors[2];
                            blue  = colors[3];
                        }
                        //"0,12,12,12"
                        if (colors.Count().Equals(3))
                        {
                            red   = colors[0];
                            green = colors[1];
                            blue  = colors[2];
                        }

                        var hexCode = ColorPickerHelper.GetHexCode(byte.Parse(red), byte.Parse(green), byte.Parse(blue));
                        if (!_colorCodeList.Contains(hexCode))
                        {
                            _colorCodeList.Add(hexCode);
                        }
                    }
                    catch (Exception e)
                    {
                    }
                }
            }
            VisitChildren(tagPair);
        }
コード例 #4
0
        public static bool Filter(CustomFilterSettings customSettings, DisplayFilterRowInfo rowInfo, bool success, Document activeDocument)
        {
            var rowId = rowInfo.SegmentPair.Properties.Id.Id;

            if (success && customSettings.EvenNo)
            {
                success = SegmentNumbersHelper.IsEven(rowId);
            }
            if (success && customSettings.OddsNo)
            {
                success = SegmentNumbersHelper.IsOdd(rowId);
            }
            if (success && customSettings.SplitSegments)
            {
                success = SegmentNumbersHelper.IsSplitSegment(rowId, activeDocument);
            }
            if (success && (customSettings.MergedSegments || customSettings.MergedAcross))
            {
                success = SegmentNumbersHelper.IsMergedSegment(rowId, activeDocument, customSettings.MergedAcross);
            }

            if (success && customSettings.SourceEqualsTarget)
            {
                success = SegmentNumbersHelper.IsSourceEqualsToTarget(rowInfo.SegmentPair, customSettings.IsEqualsCaseSensitive);
            }
            if (success && customSettings.Grouped && !string.IsNullOrWhiteSpace(customSettings.GroupedList))
            {
                success = SegmentNumbersHelper.IdInRange(rowId, customSettings.GroupedList);
            }
            if (success && customSettings.UseRegexCommentSearch &&
                !string.IsNullOrWhiteSpace(customSettings.CommentRegex))
            {
                //create a list with source and target comments
                var commentsList = rowInfo.SegmentPair.Source.GetComments();
                commentsList.AddRange(rowInfo.SegmentPair.Target.GetComments());

                success = CommentsHelper.IsCommentTextFoundWithRegex(commentsList, customSettings.CommentRegex);
            }
            if (success && customSettings.Colors.Count > 0)
            {
                try
                {
                    success = ColorPickerHelper.ContainsColor(rowInfo, customSettings.Colors);
                }
                catch (Exception e) { }
            }

            //fuzzy
            if (success && !string.IsNullOrWhiteSpace(customSettings.FuzzyMin) &&
                !string.IsNullOrWhiteSpace(customSettings.FuzzyMax))
            {
                success = FuzzyHelper.IsInFuzzyRange(rowInfo, customSettings.FuzzyMin, customSettings.FuzzyMax);
            }
            if (success && customSettings.ContainsTags)
            {
                var containsTagVisitor = new TagVisitor();
                success = containsTagVisitor.ContainsTag(rowInfo.SegmentPair.Source);
            }
            //unique
            if (success && customSettings.Unique)
            {
                var settings = new DisplayFilterSettings
                {
                    RepetitionTypes = new List <string>
                    {
                        "FirstOccurrences"
                    }
                };

                var isFirst = rowInfo.IsRepetitionsFirstOccurrences(settings);
                if (isFirst)
                {
                    return(true);
                }

                if (rowInfo.SegmentPair.Properties.TranslationOrigin != null)
                {
                    var isRepeated = rowInfo.SegmentPair.Properties.TranslationOrigin.IsRepeated;
                    return(!isRepeated);
                }

                return(false);
            }
            //created by
            if (success && customSettings.CreatedByChecked && !string.IsNullOrWhiteSpace(customSettings.CreatedBy))
            {
                var userVisitor = new UserVisitor();
                success = userVisitor.CreatedBy(rowInfo.SegmentPair.Source, customSettings.CreatedBy);
            }
            //modify by
            if (success && customSettings.ModifiedByChecked && !string.IsNullOrWhiteSpace(customSettings.ModifiedBy))
            {
                var userVisitor = new UserVisitor();
                success = userVisitor.ModifiedBy(rowInfo.SegmentPair.Source, customSettings.ModifiedBy);
            }
            if (success && customSettings.EditedFuzzy)
            {
                success = FuzzyHelper.ContainsFuzzy(rowInfo.SegmentPair.Target) && FuzzyHelper.IsEditedFuzzy(rowInfo.SegmentPair.Target);
            }
            if (success && customSettings.UnEditedFuzzy)
            {
                success = FuzzyHelper.ContainsFuzzy(rowInfo.SegmentPair.Target) && !FuzzyHelper.IsEditedFuzzy(rowInfo.SegmentPair.Target);
            }
            return(success);
        }
コード例 #5
0
        public static bool Reverse(DisplayFilterSettings settings, bool success, DisplayFilterRowInfo rowInfo, CustomFilterSettings customSettings, Document activeDocument)
        {
            success = false;
            if (!success && settings.SegmentReviewTypes != null && settings.SegmentReviewTypes.Any())
            {
                success = rowInfo.IsSegmentReviewTypes(settings);
            }


            if (!success && settings.ConfirmationLevels != null && settings.ConfirmationLevels.Any())
            {
                success = rowInfo.IsConfirmationLevelFound(settings);
            }


            if (!success && settings.OriginTypes != null && settings.OriginTypes.Any())
            {
                success = rowInfo.IsOriginTypeFound(settings);
            }


            if (!success && settings.PreviousOriginTypes != null && settings.PreviousOriginTypes.Any())
            {
                success = rowInfo.IsPreviousOriginTypeFound(settings);
            }


            if (!success && settings.RepetitionTypes != null && settings.RepetitionTypes.Any())
            {
                success = rowInfo.IsRepetitionTypes(settings);
            }


            if (!success && settings.SegmentLockingTypes != null && settings.SegmentLockingTypes.Any())
            {
                success = rowInfo.IsSegmentLockingTypes(settings);
            }


            if (!success && settings.SegmentContentTypes != null && settings.SegmentContentTypes.Any())
            {
                success = rowInfo.IsSegmentContentTypes(settings);
            }


            if (!success && settings.SourceText.Trim() != string.Empty)
            {
                success = rowInfo.IsTextFoundInSource(settings);
            }


            if (!success && settings.TargetText.Trim() != string.Empty)
            {
                success = rowInfo.IsTextFoundInTarget(settings);
            }


            if (!success && !customSettings.UseRegexCommentSearch && settings.CommentText.Trim() != string.Empty)
            {
                success = rowInfo.IsTextFoundInComment(settings);
            }


            if (!success && settings.CommentAuthor.Trim() != string.Empty)
            {
                success = rowInfo.IsAuthorFoundInComment(settings);
            }


            if (!success && settings.CommentSeverity > 0)
            {
                success = rowInfo.IsSeverityFoundInComment(settings);
            }


            if (!success && settings.ContextInfoTypes.Any())
            {
                success = rowInfo.IsContextInfoTypes(settings);
            }

            // check custom settings
            var rowId = rowInfo.SegmentPair.Properties.Id.Id;

            if (!success && customSettings.EvenNo)
            {
                success = SegmentNumbersHelper.IsEven(rowId);
            }
            if (!success && customSettings.OddsNo)
            {
                success = SegmentNumbersHelper.IsOdd(rowId);
            }
            if (!success && customSettings.SplitSegments)
            {
                success = SegmentNumbersHelper.IsSplitSegment(rowId, activeDocument);
            }
            if (!success && (customSettings.MergedSegments || customSettings.MergedAcross))
            {
                success = SegmentNumbersHelper.IsMergedSegment(rowId, activeDocument, customSettings.MergedAcross);
            }
            if (!success && customSettings.SourceEqualsTarget)
            {
                success = SegmentNumbersHelper.IsSourceEqualsToTarget(rowInfo.SegmentPair, customSettings.IsEqualsCaseSensitive);
            }
            if (!success && customSettings.Grouped && !string.IsNullOrWhiteSpace(customSettings.GroupedList))
            {
                success = SegmentNumbersHelper.IdInRange(rowId, customSettings.GroupedList);
            }
            if (!success && customSettings.UseRegexCommentSearch &&
                !string.IsNullOrWhiteSpace(customSettings.CommentRegex))
            {
                //create a list with source and target comments
                var commentsList = rowInfo.SegmentPair.Source.GetComments();
                commentsList.AddRange(rowInfo.SegmentPair.Target.GetComments());

                success = CommentsHelper.IsCommentTextFoundWithRegex(commentsList, customSettings.CommentRegex);
            }
            if (!success && customSettings.Colors.Count > 0)
            {
                try
                {
                    success = ColorPickerHelper.ContainsColor(rowInfo, customSettings.Colors);
                }
                catch (Exception e) { }
            }

            //fuzzy
            if (!success && !string.IsNullOrWhiteSpace(customSettings.FuzzyMin) &&
                !string.IsNullOrWhiteSpace(customSettings.FuzzyMax))
            {
                success = FuzzyHelper.IsInFuzzyRange(rowInfo, customSettings.FuzzyMin, customSettings.FuzzyMax);
            }
            //tags
            if (!success && customSettings.ContainsTags)
            {
                var containsTagVisitor = new TagVisitor();
                success = containsTagVisitor.ContainsTag(rowInfo.SegmentPair.Source);
            }
            if (!success && customSettings.CreatedByChecked && !string.IsNullOrWhiteSpace(customSettings.CreatedBy))
            {
                var userVisitor = new UserVisitor();
                success = userVisitor.CreatedBy(rowInfo.SegmentPair.Source, customSettings.CreatedBy);
            }
            //modify by
            if (!success && customSettings.ModifiedByChecked && !string.IsNullOrWhiteSpace(customSettings.ModifiedBy))
            {
                var userVisitor = new UserVisitor();
                success = userVisitor.ModifiedBy(rowInfo.SegmentPair.Source, customSettings.ModifiedBy);
            }
            if (!success && customSettings.EditedFuzzy)
            {
                if (FuzzyHelper.ContainsFuzzy(rowInfo.SegmentPair.Target))
                {
                    success = FuzzyHelper.IsEditedFuzzy(rowInfo.SegmentPair.Target);
                }
                else
                {
                    return(false);
                }
            }
            if (!success && customSettings.UnEditedFuzzy)
            {
                if (FuzzyHelper.ContainsFuzzy(rowInfo.SegmentPair.Target))
                {
                    success = !FuzzyHelper.IsEditedFuzzy(rowInfo.SegmentPair.Target);
                }
                else
                {
                    return(false);
                }
            }
            return(!success);
        }