public override void ProcessParagraphUnit(IParagraphUnit paragraphUnit)
        {
            var sourceResult = new List <IndexData>();
            var targetResult = new List <IndexData>();

            if (!paragraphUnit.IsStructure)
            {
                foreach (var item in paragraphUnit.SegmentPairs)
                {
                    var itemStatus = item.Properties.ConfirmationLevel;

                    // extract text and tags from Segment
                    var sourceSegment = item.Source;
                    _dataExtractor.Process(sourceSegment);
                    var sourceTags = _dataExtractor.Tags;
                    //we need to add a space before the soft return so the soft return is highlightable when searching for it
                    var sourceText     = _dataExtractor.PlainText.ToString().Replace("\n", " \n");
                    var sourceLContent = _dataExtractor.LockedContent;

                    var targetSegment = item.Target;
                    _dataExtractor.Process(targetSegment);
                    //we need to add a space before the soft return so the soft return is highlightable when searching for it
                    var targetText     = _dataExtractor.PlainText.ToString().Replace("\n", " \n");
                    var targetTags     = _dataExtractor.Tags;
                    var targetLContent = _dataExtractor.LockedContent;

                    // perform search
                    if (_searcher.CheckSegment(item.Properties.IsLocked, item.Properties.ConfirmationLevel))
                    {
                        if (_searchSettings.SearchInSource && (sourceText.Length > 0 || sourceTags.Count > 0))
                        {
                            _searcher.SearchInSegment(sourceText, sourceTags, sourceLContent);
                            sourceResult = _searcher.ResultsInText;
                            sourceTags   = _searcher.ResultsInTags;
                        }

                        if (_searchSettings.SearchInTarget && (targetText.Length > 0 || targetTags.Count > 0))
                        {
                            _searcher.SearchInSegment(targetText, targetTags, targetLContent);
                            targetResult = _searcher.ResultsInText;
                            targetTags   = _searcher.ResultsInTags;
                        }

                        // collect results
                        if (SegmentHelper.ContainMatches(sourceResult, sourceTags) || SegmentHelper.ContainMatches(targetResult, targetTags))
                        {
                            CollectResults(item.Properties.Id.Id, sourceText, itemStatus, sourceSegment, sourceResult, sourceTags, true);
                            CollectResults(item.Properties.Id.Id, targetText, itemStatus, targetSegment, targetResult, targetTags, false);
                        }
                    }
                }
            }
        }
        public override void ProcessParagraphUnit(IParagraphUnit paragraphUnit)
        {
            ISegment sourceSegment;
            string   sourceText;

            ISegment         targetSegment;
            string           targetText;
            List <IndexData> targetLContent;
            SegmentData      segmentSearch;

            ConfirmationLevel itemStatus;

            if (paragraphUnit.IsStructure)
            {
                base.ProcessParagraphUnit(paragraphUnit);
                return;
            }

            foreach (ISegmentPair item in paragraphUnit.SegmentPairs)
            {
                sourceSegment = item.Source;
                targetSegment = item.Target;
                itemStatus    = item.Properties.ConfirmationLevel;
                if (_searcher.CheckSegment(item.Properties.IsLocked, itemStatus))
                {
                    _dataExtractor.Process(targetSegment);
                    targetText     = _dataExtractor.PlainText.ToString();
                    targetLContent = _dataExtractor.LockedContent;
                    if (targetText.Length > 0)
                    {
                        // do search & save found results
                        _searcher.SearchInSegment(targetText, targetLContent);

                        // if matches in target were found
                        if (SegmentHelper.ContainMatches(_searcher.ResultsInText))
                        {
                            #region extract source text
                            _dataExtractor.Process(sourceSegment);
                            sourceText = _dataExtractor.PlainText.ToString();
                            #endregion
                            CollectResults(item.Properties.Id.Id, sourceText, itemStatus, sourceSegment, null, true);
                            CollectResults(item.Properties.Id.Id, targetText, itemStatus, targetSegment, _searcher.ResultsInText, false);

                            segmentSearch = _resultTrg[_resultTrg.Count - 1];

                            ISegment originalSegment = (ISegment)targetSegment.Clone();
                            // unlock selections
                            if (_searchSettings.UnlockContent)
                            {
                                StatusUpdateHelper.UnlockContent(targetSegment, ItemFactory, PropertiesFactory);
                            }

                            #region REPLACE Logic
                            int textLoc = 0;
                            int cnt     = 0;
                            int status  = 0;
                            for (int i = segmentSearch.SearchResults.Count - 1; i >= 0; i--)
                            {
                                // add warning - cannot be replaced
                                if (segmentSearch.SearchResults[i].IsIndexOverlap)
                                {
                                    status = -4;
                                    _resultWarnings.Add(new WarningData(segmentSearch.Sid,
                                                                        segmentSearch.SearchResults[i],
                                                                        WarningData.WarningType.IndexOverlap));
                                }
                                else
                                {
                                    // DO REPLACE - success
                                    status = PerformReplace(targetSegment, segmentSearch.SearchResults[i], ref textLoc);
                                    #region report warning - fail
                                    if (status != 0)
                                    {
                                        if (status == -1)
                                        {
                                            _resultWarnings.Add(new WarningData(segmentSearch.Sid,
                                                                                segmentSearch.SearchResults[i],
                                                                                WarningData.WarningType.TagFound,
                                                                                segmentSearch.SearchResults[i].Length + textLoc));
                                        }
                                        else if (status == -2)
                                        {
                                            _resultWarnings.Add(new WarningData(segmentSearch.Sid,
                                                                                segmentSearch.SearchResults[i],
                                                                                WarningData.WarningType.ContainLContent,
                                                                                segmentSearch.SearchResults[i].Length + textLoc));
                                        }
                                        else if (status == -3)
                                        {
                                            _resultWarnings.Add(new WarningData(segmentSearch.Sid,
                                                                                segmentSearch.SearchResults[i],
                                                                                WarningData.WarningType.ContainComment,
                                                                                segmentSearch.SearchResults[i].Length + textLoc));
                                        }
                                        else
                                        {
                                            _resultWarnings.Add(new WarningData(segmentSearch.Sid,
                                                                                segmentSearch.SearchResults[i],
                                                                                WarningData.WarningType.Other));
                                        }
                                    }
                                    #endregion
                                }

                                if (i == segmentSearch.SearchResults.Count - 1)
                                {
                                    // collect results
                                    _resultReplace.Add(new SegmentData(_resultReplace.Count,
                                                                       segmentSearch.SegmentId,
                                                                       segmentSearch.SegmentText,
                                                                       segmentSearch.SegmentStatus,
                                                                       segmentSearch.SegmentContent));
                                    _resultReplace[_resultReplace.Count - 1].SearchResults = new List <IndexData>();
                                }

                                // if replace was successful
                                if (status == 0)
                                {
                                    _resultReplace[_resultReplace.Count - 1].SearchResults.Add(segmentSearch.SearchResults[i]);
                                    _resultReplace[_resultReplace.Count - 1].SearchResults[cnt++].RealStartIndex = textLoc;
                                }
                            }
                            #endregion

                            #region UPDATE STATUSES Logic
                            // if replace occured
                            if (_resultReplace[_resultReplace.Count - 1].IndexMatchesCount > 0)
                            {
                                // update segment properties
                                StatusUpdateHelper.UpdateSegmentProperties(item, _searchSettings);
                            }
                            else
                            {
                                item.Target.Clear();
                                originalSegment.MoveAllItemsTo(item.Target);
                            }
                            #endregion
                        }
                    }
                }
            }

            base.ProcessParagraphUnit(paragraphUnit);
        }