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);
        }
Ejemplo n.º 2
0
        public override void ProcessParagraphUnit(IParagraphUnit paragraphUnit)
        {
            ISegment         sourceSegment;
            string           sourceText;
            List <TagData>   sourceTags;
            List <IndexData> sourceLContent;
            List <IndexData> sourceResult;

            ISegment         targetSegment;
            string           targetText;
            List <TagData>   targetTags;
            List <IndexData> targetLContent;
            List <IndexData> targetResult;

            ConfirmationLevel itemStatus;

            if (!paragraphUnit.IsStructure)
            {
                foreach (ISegmentPair item in paragraphUnit.SegmentPairs)
                {
                    sourceTags   = null;
                    sourceResult = null;
                    targetTags   = null;
                    targetResult = null;

                    // extract text and tags from Segment
                    sourceSegment = item.Source;
                    _dataExtractor.Process(sourceSegment);
                    sourceText     = _dataExtractor.PlainText.ToString();
                    sourceTags     = _dataExtractor.Tags;
                    sourceLContent = _dataExtractor.LockedContent;

                    targetSegment = item.Target;
                    _dataExtractor.Process(targetSegment);
                    targetText     = _dataExtractor.PlainText.ToString();
                    targetTags     = _dataExtractor.Tags;
                    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))
                        {
                            itemStatus = (_searchSettings.UpdateStatus ? _searchSettings.NewStatus : item.Properties.ConfirmationLevel);

                            CollectResults(item.Properties.Id.Id, sourceText, itemStatus, sourceSegment, sourceResult, sourceTags, true);
                            CollectResults(item.Properties.Id.Id, targetText, itemStatus, targetSegment, targetResult, targetTags, false);

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

                            // update segment properties
                            StatusUpdateHelper.UpdateSegmentProperties(item, _searchSettings);
                        }
                    }
                }
            }

            base.ProcessParagraphUnit(paragraphUnit);
        }