public void SetProgressMessage(string message, int?percent) { if (InvokeRequired) { Invoke(new SetProgressMessageDelegate(this.SetProgressMessage), new object[] { message, percent }); } else { Controls.ProgressUI progress = CurrentUI as Controls.ProgressUI; if (progress != null) { progress.Message = message; progress.Percent = percent; } } }
void ImporterUIFinished(object sender, EventArgs e) { ((IImporterUI <IBilingualDictionary>)sender).Finished -= new EventHandler(this.ImporterUIFinished); if (select.SelectedItem != null && select.SelectedItem is ImporterItem) { if (CurrentUI is IImporterUI <IBilingualDictionary> ) { ((IImporterUI <IBilingualDictionary>)CurrentUI).Apply(); } CurrentUI = null; Controls.ProgressUI progressUI = new Controls.ProgressUI(); CurrentUI = progressUI; importer.BeginImport(); } }
private void ImporterUIFinished(object sender, EventArgs e) { ((IImporterUI <WordList>)sender).Finished -= ImporterUIFinished; if (importerSelection.SelectedItem is ImporterItem) { var importerUI = CurrentUI as IImporterUI <WordList>; if (importerUI != null) { importerUI.Apply(); } CurrentUI = null; var progressUI = new Controls.ProgressUI(); CurrentUI = progressUI; // Try is needed here too in case the import fails synchronously. try { importer.BeginImport(); } catch (ImportException ex) { ImportFailed(ex); } } }
void ImporterUIFinished(object sender, EventArgs e) { ((IImporterUI<IBilingualDictionary>)sender).Finished -= this.ImporterUIFinished; if (select.SelectedItem != null && select.SelectedItem is ImporterItem) { if (CurrentUI is IImporterUI<IBilingualDictionary>) ((IImporterUI<IBilingualDictionary>)CurrentUI).Apply(); CurrentUI = null; Controls.ProgressUI progressUI = new Controls.ProgressUI(); CurrentUI = progressUI; importer.BeginImport(); } }
private void ImportCompleted(IBilingualDictionary result) { Debug.Assert(!InvokeRequired, "ImportCompleted called on a secondary thread"); try { if (CurrentUI is Controls.ProgressUI) { Controls.ProgressUI prog = (Controls.ProgressUI)CurrentUI; prog.Percent = 100; prog.Message = Properties.Resources.ImportFinished; } this.imported = result; // Modal dialog simplifies things slightly. new DictionaryInfoEditor(imported, false).ShowDialog(); string root = DataStore.UserDataStore.Path; string name = imported.Name ?? Properties.Resources.DefaultDictionaryName; DataStore.UserDataStore.EnsureDirectoryExists(Configuration.DictionariesFolderName); // Attempt to save with a sane name; failing that, use a GUID as the name; otherwise report the error. var ipc = Path.GetInvalidPathChars(); if (name.IndexOfAny(ipc) >= 0) { // TODO: Sanitize file name! } string newPath = Path.Combine(Path.Combine(root, Configuration.DictionariesFolderName), name) + ".dict"; // We don't want to overwrite an existing dictionary. if (File.Exists(newPath)) { name = Guid.NewGuid().ToString("D"); newPath = Path.Combine(Path.Combine(root, Configuration.DictionariesFolderName), name) + ".dict"; } imported.Path = newPath; // If the dictionary can't save, we should delete the half-written file. // TODO: this should probably avoid deleting the file if the error was caused // by the file already existing (say, if it was created between calls). It would be // kind of rare though. try { imported.Save(); } catch (SystemException) { // XXX Lazy. File.Delete(imported.Path); throw; } new LookupForm(imported).Show(); Close(); } catch (ApplicationException ex) { ReportException(ex); } catch (IOException ex) { ReportException(ex); } catch (InvalidOperationException ex) { ReportException(ex); } catch (ArgumentException ex) { ReportException(ex); } }
private void ImporterUIFinished(object sender, EventArgs e) { ((IImporterUI<WordList>)sender).Finished -= ImporterUIFinished; if (importerSelection.SelectedItem is ImporterItem) { var importerUI = CurrentUI as IImporterUI<WordList>; if (importerUI != null) importerUI.Apply(); CurrentUI = null; var progressUI = new Controls.ProgressUI(); CurrentUI = progressUI; // Try is needed here too in case the import fails synchronously. try { importer.BeginImport(); } catch (ImportException ex) { ImportFailed(ex); } } }