public static void Generate(ISegmentPair segmentPair, IDocumentItemFactory itemFactory)
 {
     try
     {
         var      collector = new RandomTargetGenerator();
         ISegment segment   = collector.GenerateRandomTarget(segmentPair.Source);
         segmentPair.Target.Clear();
         segment.MoveAllItemsTo(segmentPair.Target);
         segmentPair.Properties.TranslationOrigin            = itemFactory.CreateTranslationOrigin();
         segmentPair.Properties.TranslationOrigin.OriginType = DefaultTranslationOrigin.Source;
     }
     catch
     {
         throw;
     }
 }
 public static void Copy(ISegmentPair segmentPair, IDocumentItemFactory itemFactory)
 {
     try
     {
         var      collector = new SourceToTargetCopy();
         ISegment segment   = collector.CopySourceToTarget(segmentPair.Source);
         segmentPair.Target.Clear();
         segment.MoveAllItemsTo(segmentPair.Target);
         segmentPair.Properties.TranslationOrigin            = itemFactory.CreateTranslationOrigin();
         segmentPair.Properties.TranslationOrigin.OriginType = DefaultTranslationOrigin.Source;
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Ejemplo n.º 3
0
        public override void ProcessParagraphUnit(IParagraphUnit paragraphUnit)
        {
            if (paragraphUnit.IsStructure)
            {
                return;
            }

            foreach (var pair in paragraphUnit.SegmentPairs)
            {
                var source = pair.Source;
                var target = pair.Target;

                ISegment clone = (ISegment)source.Clone();

                target.Clear();
                clone.MoveAllItemsTo(target);
            }
        }
        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);
        }