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;
        }
Example #2
0
 public void BuildTranslationModel()
 {
     _tm.BuildModel();
 }