コード例 #1
0
        private void TranslateLanguage_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string selectedValue = (sender as System.Windows.Controls.ComboBox).SelectedValue.ToString();

            Settings.SaveSettings("General", "TransLang", LanguageDictionary.GetTranslateLanguageCode(selectedValue));
        }
コード例 #2
0
        private async void ScanFileButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "(Support Files)|*.doc;*.docx;*.odf;*.pdf;*.ppt;*.pptx;*.ps;*.rtf;*.txt;*.xls;*.xlsx";
            if (openFileDialog.ShowDialog() == true)
            {
                string filePath = openFileDialog.FileName;
                string fileName = Path.GetFileNameWithoutExtension(filePath);

                ProgressDialogController progressDialog = await this.ShowProgressAsync("Processing...", "Always smile and happy :)");

                progressDialog.SetIndeterminate();
                try
                {
                    if (progressDialog.IsOpen)
                    {
                        using (System.Net.WebClient webClient = new System.Net.WebClient())
                        {
                            byte[] response = await webClient.UploadFileTaskAsync(new Uri("https://translate.googleusercontent.com/translate_f?tl=" + LanguageDictionary.GetTranslateLanguageCode(TranslateLanguageSelected)), filePath);

                            string dataFilePath = Path.Combine(App.SCANFILE_PATH, fileName + "_" + LanguageDictionary.GetTranslateLanguageCode(TranslateLanguageSelected) + ".html");
                            File.WriteAllBytes(dataFilePath, response);
                            await Task.Delay(4000);

                            Process.Start(dataFilePath);
                            await progressDialog.CloseAsync();
                        }
                    }
                }
                catch (OperationCanceledException ex)
                {
                    await progressDialog.CloseAsync();

                    MessageBox.Show("Scan file Error: " + ex.Message, "Error", MessageBoxButton.OK);
                }
                catch (Exception ex)
                {
                    await progressDialog.CloseAsync();

                    MessageBox.Show("Scan file Error: " + ex.Message, "Error", MessageBoxButton.OK);
                }
            }
        }