コード例 #1
0
        private void Translate_Batch_Clicked(object sender, RoutedEventArgs e)
        {
            if (!(TranslateData.DataContext is Project.TranslationPair[] currentPairs))
            {
                MessageBox.Show(this, "No section is open", "Turansuraetu", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            ProgressDisplay disp = new ProgressDisplay();

            List <ITranslateService> activeServices =
                ITranslateService.TranslationServices.Where(x => x.IsActive(this)).ToList();

            bool overwriteTranslations = DoOverwrite.IsChecked;

            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += (o, args) =>
            {
                try
                {
                    foreach (ITranslateService service in activeServices)
                    {
                        int i = 1;
                        foreach (Project.TranslationPair pair in currentPairs)
                        {
                            disp.Update($"{service.GetType().Name} - {i}/{currentPairs.Length}",
                                        (double)i / currentPairs.Length);

                            try
                            {
                                service.Translate(Translate.Language.Japanese, Translate.Language.English,
                                                  pair.Original,
                                                  ref pair.machine, overwriteTranslations);
                            }
                            catch (Exception e)
                            {
                                Dispatcher.Invoke(() =>
                                {
                                    MessageBox.Show(
                                        $"An error has occured whilst translating with {service.GetType().Name}: {e.GetType().Name} {e.Message}",
                                        "Turansuraetu", MessageBoxButton.OK, MessageBoxImage.Stop);
                                });
                            }

                            i++;
                        }
                    }
                }
                finally
                {
                    disp.Done();
                }
            };

            worker.RunWorkerCompleted += (o, args) => { RefreshTable(); };

            worker.RunWorkerAsync();
            disp.ShowDialog();
        }
コード例 #2
0
ファイル: Project.cs プロジェクト: fuj1n/Turansuraetu
        public static Task <Project> Open(MainWindow window, string file)
        {
            file = Path.GetFullPath(file);

            { // Validate file
                string header = File.ReadAllLines(file).SingleOrDefault() ?? "";
                if (!header.Trim().Equals("> RPGMAKER TRANS PATCH V3"))
                {
                    MessageBox.Show(window, "Cannot open project, header file is invalid.", "Turansuraetu",
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                    return(null);
                }
            }

            ProgressDisplay progress = new ProgressDisplay();
            Task <Project>  worker   = new Task <Project>(() => Open_Do(file, progress));

            worker.Start();
            progress.ShowDialog();

            return(worker);
        }