Example #1
0
        public async Task BuildTranslationModel()
        {
            var lastProgressNumber = 0;

            NotifySubscribers(0, 0, StringResources.FragmentAlignment_ProgressPreparingMessage);
            _tm.TranslationModelProgress += (o, args) =>
            {
                if (args.ProgressNumber > lastProgressNumber)
                {
                    var text = string.Empty;
                    if (args.ProgressLimit > 0)
                    {
                        text =
                            string.Format(
                                StringResources
                                .FragmentAlignment_ProgressProcessedOfTranslationUnitsMessage
                                , ProcessorUtil.GetProgresssStageText(args.ProgressStage), args.ProgressNumber, args.ProgressLimit);
                    }

                    NotifySubscribers(args.ProgressLimit, args.ProgressNumber, text);
                    lastProgressNumber = args.ProgressNumber;
                }
            };

            var t = new Task(() => _tm.BuildModel());


            t.ContinueWith(task =>
            {
                throw new Exception(ProcessorUtil.ExceptionToMsg(task.Exception));
            }, TaskContinuationOptions.OnlyOnFaulted);

            t.ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    throw new Exception(ProcessorUtil.ExceptionToMsg(task.Exception));
                }
                if (!task.IsCompleted)
                {
                    return;
                }
                ProcessorUtil.UpdateTranslationMemory(_tm);
            }, TaskScheduler.FromCurrentSynchronizationContext());

            t.Start();
            await t;
        }
        public void Uplift(TranslationMemoryInfo tm, BackgroundWorker bw)
        {
            var originalTmFilePath = ProcessorUtil.RenameOriginalTm(tm.Name, tm.FilePath);
            var upliftTmFilePath   = ProcessorUtil.GetOutputTmFullPath(tm.Name, tm.FilePath);

            _reindexStatus.AppendLine(string.Format("Start uplift {0} translation memory", tm.Name));
            bw.ReportProgress(0, _reindexStatus.ToString());

            File.Copy(originalTmFilePath, upliftTmFilePath, true);
            var tmOut = new FileBasedTranslationMemory(upliftTmFilePath);

            tmOut.FGASupport = FGASupport.Automatic;
            tmOut.Save();
            var tmExporter = new TmExporter(tmOut);
            var tmIn       = new FileBasedTranslationMemory(tm.FilePath);
            var tmImporter = new TmImporter(tmIn);

            var modelBuilder    = new ModelBuilder(tmOut);
            var fragmentAligner = new FragmentAligner(tmOut);

            if (tmIn.FGASupport != FGASupport.NonAutomatic)
            {
                Process(modelBuilder, fragmentAligner, bw);
            }
            else
            {
                Process(tmExporter,
                        tmImporter,
                        modelBuilder,
                        fragmentAligner, bw);
            }
            if (!bw.CancellationPending)
            {
                ProcessorUtil.UpdateTranslationMemory(tmOut);
                _reindexStatus.AppendLine(string.Format("Finish uplift {0} translation memory", tm.Name));

                bw.ReportProgress(0, _reindexStatus.ToString());
            }
            else
            {
                bw.ReportProgress(100, "");
            }
        }
        public async Task AlignTranslationUnits()
        {
            var iter = new RegularIterator();


            var translationUnitCount = _tm.GetTranslationUnitCount();

            var totalUnitsToProcess = _quickAlign
             ? _tm.UnalignedTranslationUnitCount
             : translationUnitCount;

            var lastProgressNumber = 0;

            NotifySubscribers(0, 0, StringResources.FragmentAlignment_ProgressPreparingMessage);

            var t = new Task(() =>
            {
                while (_tm.AlignTranslationUnits(false, _quickAlign, ref iter))
                {
                    if (iter.ProcessedTranslationUnits <= lastProgressNumber)
                    {
                        continue;
                    }
                    var text = string.Empty;
                    if (totalUnitsToProcess > 0)
                    {
                        text =
                            string.Format(
                                StringResources
                                .FragmentAlignment_ProgressAlignedOfTranslationUnitsMessage
                                , iter.ProcessedTranslationUnits, totalUnitsToProcess);
                    }

                    NotifySubscribers(totalUnitsToProcess, iter.ProcessedTranslationUnits, text);
                    lastProgressNumber = iter.ProcessedTranslationUnits;
                }
            });


            t.ContinueWith(task =>
            {
                throw new Exception(ProcessorUtil.ExceptionToMsg(task.Exception));
            }, TaskContinuationOptions.OnlyOnFaulted);

            t.ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    throw new Exception(ProcessorUtil.ExceptionToMsg(task.Exception));
                }
                if (!task.IsCompleted)
                {
                    return;
                }
                ProcessorUtil.UpdateTranslationMemory(_tm);
                NotifySubscribers(translationUnitCount, translationUnitCount, "Complete");
            }, TaskScheduler.FromCurrentSynchronizationContext());

            t.Start();
            await t;
        }