Esempio n. 1
0
        public async Task <ImportStatistics> Import(string tmxPath)
        {
            var importer = new TranslationMemoryImporter(_tm.LanguageDirection);


            importer.BatchImported += importer_BatchImported;

            GetImportSettings(importer.ImportSettings);


            var t = new Task(() => importer.Import(tmxPath));



#pragma warning disable 4014
            t.ContinueWith(task =>
#pragma warning restore 4014
            {
                if (task.IsFaulted)
                {
                    throw new Exception(ProcessorUtil.ExceptionToMsg(task.Exception));
                }
            }, TaskScheduler.FromCurrentSynchronizationContext());

            t.Start();
            await t;

            Results = importer.Statistics;
            return(Results);
        }
Esempio n. 2
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. 3
0
        public async Task <string> Export()
        {
            TotalExported = 0;

            var exporter = new TranslationMemoryExporter(_tm.LanguageDirection);

            TotalUnits = exporter.TranslationMemoryLanguageDirection.GetTranslationUnitCount();

            exporter.BatchExported += exporter_BatchExported;
            var exportName = string.Format(
                CultureInfo.CurrentCulture,
                "{0}_{1}_{2}.tmx",
                _tm.Name,
                _tm.LanguageDirection.SourceLanguage,
                _tm.LanguageDirection.TargetLanguage);

            var exportFullPath = Path.Combine(Path.GetDirectoryName(_tm.FilePath), exportName);

            if (File.Exists(exportFullPath))
            {
                File.Delete(exportFullPath);
            }


            var t = new Task(() => exporter.Export(exportFullPath, true));

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

            t.Start();
            await t;

            return(exportFullPath);
        }
Esempio n. 4
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;
        }