/// <summary>
        /// Gets a list with the index of PI in segment
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        private List <int> GetPersonalData(string text)
        {
            var personalDataIndex = new List <int>();

            foreach (var rule in SettingsMethods.GetRules())
            {
                var regex   = new Regex(rule.Name, RegexOptions.IgnoreCase);
                var matches = regex.Matches(text);

                foreach (System.Text.RegularExpressions.Match match in matches)
                {
                    if (match.Index.Equals(0))
                    {
                        personalDataIndex.Add(match.Length);
                    }
                    else
                    {
                        //check if there is any text after PI
                        var remainingText = text.Substring(match.Index + match.Length);
                        if (!string.IsNullOrEmpty(remainingText))
                        {
                            //get the position where PI starts to split before
                            personalDataIndex.Add(match.Index);
                            //split after PI
                            personalDataIndex.Add(match.Index + match.Length);
                        }
                        else
                        {
                            personalDataIndex.Add(match.Index);
                        }
                    }
                }
            }
            return(personalDataIndex);
        }
 private bool ContainsPi(string text)
 {
     foreach (var rule in SettingsMethods.GetRules())
     {
         var regex = new Regex(rule.Name, RegexOptions.IgnoreCase);
         var match = regex.Match(text);
         if (match.Success)
         {
             return(true);
         }
     }
     return(false);
 }
 public TranslationViewModel(TranslationMemoryViewModel translationMemoryViewModel)
 {
     _selectedItems = new List <Rule>();
     _translationMemoryViewModel   = translationMemoryViewModel;
     _anonymizeTranslationMemories = new ObservableCollection <AnonymizeTranslationMemory>();
     _rules = SettingsMethods.GetRules();
     foreach (var rule in _rules)
     {
         rule.PropertyChanged += Rule_PropertyChanged;
     }
     _sourceSearchResults                  = new ObservableCollection <SourceSearchResult>();
     _backgroundWorker                     = new BackgroundWorker();
     _backgroundWorker.DoWork             += _backgroundWorker_DoWork;
     _backgroundWorker.RunWorkerCompleted += _backgroundWorker_RunWorkerCompleted;
     _tmsCollection = _translationMemoryViewModel.TmsCollection;
     _tmsCollection.CollectionChanged            += _tmsCollection_CollectionChanged;
     _translationMemoryViewModel.PropertyChanged += _translationMemoryViewModel_PropertyChanged;
     RulesCollection.CollectionChanged           += RulesCollection_CollectionChanged;
 }
        private bool ShouldAnonymize(string currentText, string prevText)
        {
            foreach (var rule in SettingsMethods.GetRules())
            {
                var regex   = new Regex(rule.Name, RegexOptions.IgnoreCase);
                var matches = regex.Matches(currentText);
                foreach (System.Text.RegularExpressions.Match match in matches)
                {
                    var matchesDeselected = _deSelectedWordsDetails.Where(n => n.Text.Equals(match.Value.TrimEnd())).ToList();
                    if (matchesDeselected.Any())
                    {
                        //check the previous word to see if is the same word which user deselected

                        if (!string.IsNullOrEmpty(prevText))
                        {
                            var combinedText = prevText + currentText;

                            var firstPartOfString = combinedText.Substring(0, combinedText.IndexOf(match.Value, StringComparison.Ordinal))
                                                    .TrimEnd();
                            var prevWord = firstPartOfString.Substring(firstPartOfString.LastIndexOf(" ", StringComparison.Ordinal));

                            var matchToBeDeselected = matchesDeselected.FirstOrDefault(w => w.PreviousWord.Equals(prevWord));
                            if (matchToBeDeselected != null)
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            //this means the unselected text is checked second time we need to skip it because we already created a text element
                            return(false);
                        }
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }