Esempio n. 1
0
        public async Task BuildTranslationModel()
        {
            var lastProgressNumber = 0;

            NotifySubscribers(0, 0, Resources.FragmentAlignment_ProgressPreparingMessage);
            _tm.TranslationModelProgress += (o, args) =>
            {
                if (args.ProgressNumber > lastProgressNumber)
                {
                    var text = string.Empty;
                    if (args.ProgressLimit > 0)
                    {
                        text =
                            string.Format(
                                Resources
                                .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;
        }
Esempio n. 2
0
        public async Task AlignTranslationUnits()
        {
            var iter = new RegularIterator();


            var translationUnitCount = _tm.GetTranslationUnitCount();

            var totalUnitsToProcess = _quickAlign
             ? _tm.UnalignedTranslationUnitCount
             : translationUnitCount;

            var lastProgressNumber = 0;

            NotifySubscribers(0, 0, Resources.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(
                                Resources
                                .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;
        }