private void Import() { OpenFileDialogParameters selectSqlDumpFileDialogParameters = new OpenFileDialogParameters { DialogTitle = "Выбор SQL-дампа", Filter = "Все поддерживаемые файлы|*.sql;*zip;*.rar;*.gz;*.7z|SQL -дампы (*.sql)|*.sql|Архивы (*.zip, *.rar, *.gz, *.7z)|*zip;*.rar;*.gz;*.7z|Все файлы (*.*)|*.*", Multiselect = false }; OpenFileDialogResult selectSqlDumpFileDialogResult = WindowManager.ShowOpenFileDialog(selectSqlDumpFileDialogParameters); if (selectSqlDumpFileDialogResult.DialogResult) { ImportWindowViewModel importWindowViewModel = new ImportWindowViewModel(mainModel, selectSqlDumpFileDialogResult.SelectedFilePaths.First()); IWindowContext importWindowContext = WindowManager.CreateWindow(RegisteredWindows.WindowKey.IMPORT_WINDOW, importWindowViewModel, CurrentWindowContext); importWindowContext.ShowDialog(); if (IsDefaultSearchTabVisible) { DefaultSearchTabViewModel.Refresh(setFocus: true); } else { foreach (SearchTabViewModel searchTabViewModel in TabViewModels.OfType <SearchTabViewModel>()) { searchTabViewModel.Refresh(setFocus: searchTabViewModel == SelectedTabViewModel); } } } }
public IEnumerable <IResult> OpenLiveMatch() { var dialog = new OpenFileDialogResult() { Title = "Open match...", Filter = Format.XML.DialogFilter, }; yield return(dialog); FileName = dialog.Result; var deserialization = new DeserializeMatchResult(FileName, Format.XML.Serializer); yield return(deserialization .Rescue() .WithMessage("Error loading the match", string.Format("Could not load a match from {0}.", dialog.Result)) .Propagate()); // Reraise the error to abort the coroutine Match = deserialization.Result; ActivePlaylist = Match.Playlists.Where(p => p.Name == "Alle").FirstOrDefault(); Events.PublishOnUIThread(new MatchOpenedEvent(Match)); Events.PublishOnUIThread(new HideMenuEvent()); MatchModified = false; MatchSaveAs = true; NotifyOfPropertyChange("MatchSaveAs"); NotifyOfPropertyChange("MatchModified"); }
private void ChangeDatabase() { StringBuilder filterBuilder = new StringBuilder(); filterBuilder.Append(Localization.Databases); filterBuilder.Append(" (*.db)|*.db|"); filterBuilder.Append(Localization.AllFiles); filterBuilder.Append(" (*.*)|*.*"); OpenFileDialogParameters openFileDialogParameters = new OpenFileDialogParameters { DialogTitle = Localization.BrowseDatabaseDialogTitle, Filter = filterBuilder.ToString(), Multiselect = false }; OpenFileDialogResult openFileDialogResult = WindowManager.ShowOpenFileDialog(openFileDialogParameters); if (openFileDialogResult.DialogResult) { string databaseFilePath = openFileDialogResult.SelectedFilePaths.First(); if (MainModel.OpenDatabase(databaseFilePath)) { MainModel.AppSettings.DatabaseFileName = MainModel.GetDatabaseNormalizedPath(databaseFilePath); MainModel.SaveSettings(); GetStats(); } else { ShowMessage(Localization.Error, Localization.GetCannotOpenDatabase(databaseFilePath)); MainModel.OpenDatabase(MainModel.AppSettings.DatabaseFileName); } } }
public void Import(ImportQueueItemViewModel importQueueItemViewModel) { string databaseDumpFilePath; if (SharedSetupContext.SelectedDownloadMode == SharedSetupContext.DownloadMode.DOWNLOAD_MANAGER) { databaseDumpFilePath = importQueueItemViewModel.Collection.DownloadFilePath; } else { OpenFileDialogResult selectDatabaseDumpFileDialogResult = ImportWindowViewModel.SelectDatabaseDumpFile(MainModel); if (!selectDatabaseDumpFileDialogResult.DialogResult) { return; } databaseDumpFilePath = selectDatabaseDumpFileDialogResult.SelectedFilePaths.First(); } importQueueItemViewModel.Status = ImportQueueItemStatus.IMPORTING; TableType expectedTableType; switch (importQueueItemViewModel.Collection.Identifier) { case SharedSetupContext.CollectionIdentifier.NON_FICTION: expectedTableType = TableType.NON_FICTION; break; case SharedSetupContext.CollectionIdentifier.FICTION: expectedTableType = TableType.FICTION; break; case SharedSetupContext.CollectionIdentifier.SCIMAG: expectedTableType = TableType.SCI_MAG; break; default: throw new Exception($"Unexpected collection identifier: {importQueueItemViewModel.Collection.Identifier}."); } ImportWindowViewModel importWindowViewModel = new ImportWindowViewModel(MainModel, databaseDumpFilePath, expectedTableType); IWindowContext importWindowContext = WindowManager.CreateWindow(RegisteredWindows.WindowKey.IMPORT_WINDOW, importWindowViewModel, SetupWizardWindowContext); importWindowContext.ShowDialog(); switch (importWindowViewModel.Status) { case ImportWindowViewModel.ImportStatus.IMPORT_COMPLETE: importQueueItemViewModel.Status = ImportQueueItemStatus.IMPORT_SUCCESSFUL; SelectNextImportQueueItem(); break; case ImportWindowViewModel.ImportStatus.IMPORT_CANCELLED: importQueueItemViewModel.Status = ImportQueueItemStatus.IMPORT_CANCELLED; break; default: importQueueItemViewModel.Status = ImportQueueItemStatus.IMPORT_ERROR; break; } }
public IEnumerable <IResult> OpenMatch(string fileName = null) { Events.PublishOnUIThread(new MediaControlEvent(Media.Control.Stop, Media.Source.Viewer)); bool newVideoLoaded = false; var dialog = new OpenFileDialogResult() { Title = "Open match...", Filter = Format.XML.DialogFilter, }; if (fileName == null || !File.Exists(fileName)) { yield return(dialog); FileName = dialog.Result; } else { FileName = fileName; } var deserialization = new DeserializeMatchResult(FileName, Format.XML.Serializer); yield return(deserialization .Rescue() .WithMessage("Error loading the match", string.Format("Could not load a match from {0}.", dialog.Result)) .Propagate()); // Reraise the error to abort the coroutine var tempMatch = deserialization.Result; if (string.IsNullOrEmpty(tempMatch.VideoFile) || !File.Exists(tempMatch.VideoFile)) { foreach (var result in LoadVideo(tempMatch)) { yield return(result); } newVideoLoaded = true; } else { Events.PublishOnUIThread(new VideoLoadedEvent(tempMatch.VideoFile)); newVideoLoaded = false; } this.Match = tempMatch; if (!newVideoLoaded) { MatchModified = false; } MatchSaveAs = true; NotifyOfPropertyChange("MatchSaveAs"); ActivePlaylist = Match.Playlists.Where(p => p.Name == "Alle").FirstOrDefault(); Events.PublishOnUIThread(new MatchOpenedEvent(Match)); Events.PublishOnUIThread(new HideMenuEvent()); //Events.PublishOnUIThread(new FullscreenEvent(false)); }
public override async Task ExecuteAsync() { if (_docInfoService.IsModifiedDocument) { MessageDialogResult messageDialogResult = await _messageDialog.ShowDialogAsync( new MessageDialogOptions { Title = "Notepad", Content = $"Do you want to save the {_docInfoService.UsedFileNameWithExtension} changes?", Button = MessageBoxButton.YesNoCancel }); switch (messageDialogResult.MessageDialogResultType) { case MessageDialogResultType.Yes: { if (_docInfoService.IsOpenedDocument) { await _textFileWriter.WriteAsync(new WriteTextFileModel { FilePath = _docInfoService.UsedFilePath, Content = CallerViewModel.InputTextBoxViewModel.Content }); } else { SaveFileDialogResult saveFileDialogResult = await _saveFileDialog.ShowDialogAsync(new SaveFileDialogOptions { FileFilters = GetSaveFileDialogFilters() }); if (saveFileDialogResult.SaveFileDialogResultType == SaveFileDialogResultType.Ok) { await _textFileWriter.WriteAsync(new WriteTextFileModel { FilePath = saveFileDialogResult.SavedFilePath, Content = CallerViewModel.InputTextBoxViewModel.Content }); _docInfoService.SetFilePath(saveFileDialogResult.SavedFilePath); } else if (saveFileDialogResult.SaveFileDialogResultType == SaveFileDialogResultType.Cancel) { return; } } _docInfoService.SetUnmodifiedDocumentState(); CallerViewModel.WindowSettingsViewModel.Title = _docInfoService.UsedFileNameWithoutExtension; break; } case MessageDialogResultType.Cancel: { return; } } } OpenFileDialogResult openFileDialogResult = await _openFileDialog.ShowDialogAsync(new OpenFileDialogOptions { FileFilters = GetOpenFileDialogFilters() }); if (openFileDialogResult.OpenFileDialogResultType == OpenFileDialogResultType.Ok) { CallerViewModel.InputTextBoxViewModel.Content = await _textFileReader.ReadAsync <string>(new ReadTextFileModel { FilePath = openFileDialogResult.FilePath }); _docInfoService.SetFilePath(openFileDialogResult.FilePath); _docInfoService.SetUnmodifiedDocumentState(); CallerViewModel.WindowSettingsViewModel.Title = _docInfoService.UsedFileNameWithoutExtension; } }
public async Task OpenFile() { // open file OpenFileDialogArguments dialogArgs = new OpenFileDialogArguments() { Width = 600, Height = 500, Filters = "All files (*.*)|*.*|Excel Worksheets (*.xls, *.xlsx)|*.xls;*.xlsx" }; OpenFileDialogResult result = await OpenFileDialog.ShowDialogAsync(ShellDialogHostIdentifier.ToString(), dialogArgs); }
private void Import() { OpenFileDialogResult selectSqlDumpFileDialogResult = ImportWindowViewModel.SelectDatabaseDumpFile(MainModel); if (selectSqlDumpFileDialogResult.DialogResult) { ImportWindowViewModel importWindowViewModel = new ImportWindowViewModel(MainModel, selectSqlDumpFileDialogResult.SelectedFilePaths.First(), null); IWindowContext importWindowContext = WindowManager.CreateWindow(RegisteredWindows.WindowKey.IMPORT_WINDOW, importWindowViewModel, CurrentWindowContext); importWindowContext.ShowDialog(); RefreshSearchTabCollectionAvailabilities(); } }
public IEnumerable <IResult> LoadVideo() { var videoDialog = new OpenFileDialogResult() { Title = "Open video file...", Filter = string.Format("{0}|{1}", "Video Files", "*.mp4; *.wmv; *.avi; *.mov") }; yield return(videoDialog); MatchModified = videoDialog.Result != Match.VideoFile; Match.VideoFile = videoDialog.Result; Events.PublishOnUIThread(new VideoLoadedEvent(Match.VideoFile)); }
private void BrowseCodeTemplateCommandClick() { var openFileDialogAdapter = this.dialogFactory.GetOpenFileDialog("XML Files (*.xml)|*.xml", "xml"); OpenFileDialogResult dialogResult = openFileDialogAdapter.ShowDialog(); if (dialogResult.DialogResult == DialogResult.Cancel) { return; } XmlMethodInfo xmlMethodInfo = new XmlMethodLoader().LoadMethod(dialogResult.FileName); if (xmlMethodInfo == null) { var messageWindow = this.dialogFactory.GetMessageBoxWindow(); var dialogReuslt = messageWindow.ShowDialog(messageManager.GetMessage("UserCodeTemplateInvalidFormat"), messageManager.GetMessage("Warning"), MessageButtons.OK, MessageIcon.Warning); return; } if (xmlMethodInfo.MethodType != codeProvider.Language) { var messageWindow = this.dialogFactory.GetMessageBoxWindow(); var dialogReuslt = messageWindow.ShowDialog(messageManager.GetMessage("UserCodeTamplateMustBeMethodType", codeProvider.Language), messageManager.GetMessage("Warning"), MessageButtons.OK, MessageIcon.Warning); return; } KeyValuePair <string, XmlMethodInfo> userCodeTemplate = this.UserCodeTemplates.FirstOrDefault(x => x.Key == xmlMethodInfo.MethodName); if (userCodeTemplate.Key == default(KeyValuePair <string, XmlMethodInfo>).Key) { this.globalConfiguration.AddUserCodeTemplatePath(xmlMethodInfo.Path); this.globalConfiguration.Save(); userCodeTemplate = new KeyValuePair <string, XmlMethodInfo>(xmlMethodInfo.MethodName, xmlMethodInfo); UserCodeTemplates.Add(userCodeTemplate); } SelectedUserCodeTemplate = userCodeTemplate; }
private void AddBook() { OpenFileDialogParameters openFileDialogParameters = new OpenFileDialogParameters { Filter = "EPUB files (*.epub)|*.epub|All files (*.*)|*.*", Multiselect = true }; OpenFileDialogResult openDialogResult = windowManager.ShowOpenFileDialog(openFileDialogParameters); if (openDialogResult.DialogResult) { foreach (string selectedFilePath in openDialogResult.SelectedFilePaths) { libraryModel.AddBookToLibrary(selectedFilePath); } RefreshLibrary(); } }
private async void OpenFileDialogButtonClickHandler(object sender, RoutedEventArgs args) { OpenFileDialogArguments dialogArgs = new OpenFileDialogArguments() { Width = 600, Height = 400 }; // await the result of OpenFileDialogResult and do something with it OpenFileDialogResult result = await OpenFileDialog.ShowDialogAsync(MainWindow.DialogHostName, dialogArgs); if (!result.Canceled) { Console.WriteLine("Selected file: " + result.FileInfo.FullName); } else { Console.WriteLine("Cancel open file"); } }
private void Import() { ImportLocalizator importLocalizator = MainModel.Localization.CurrentLanguage.Import; StringBuilder filterBuilder = new StringBuilder(); filterBuilder.Append(importLocalizator.AllSupportedFiles); filterBuilder.Append("|*.sql;*zip;*.rar;*.gz;*.7z|"); filterBuilder.Append(importLocalizator.SqlDumps); filterBuilder.Append(" (*.sql)|*.sql|"); filterBuilder.Append(importLocalizator.Archives); filterBuilder.Append(" (*.zip, *.rar, *.gz, *.7z)|*zip;*.rar;*.gz;*.7z|"); filterBuilder.Append(importLocalizator.AllFiles); filterBuilder.Append(" (*.*)|*.*"); OpenFileDialogParameters selectSqlDumpFileDialogParameters = new OpenFileDialogParameters { DialogTitle = importLocalizator.BrowseImportFileDialogTitle, Filter = filterBuilder.ToString(), Multiselect = false }; OpenFileDialogResult selectSqlDumpFileDialogResult = WindowManager.ShowOpenFileDialog(selectSqlDumpFileDialogParameters); if (selectSqlDumpFileDialogResult.DialogResult) { ImportWindowViewModel importWindowViewModel = new ImportWindowViewModel(MainModel, selectSqlDumpFileDialogResult.SelectedFilePaths.First()); IWindowContext importWindowContext = WindowManager.CreateWindow(RegisteredWindows.WindowKey.IMPORT_WINDOW, importWindowViewModel, CurrentWindowContext); importWindowContext.ShowDialog(); if (IsDefaultSearchTabVisible) { DefaultSearchTabViewModel.Refresh(setFocus: true); } else { foreach (SearchTabViewModel searchTabViewModel in TabViewModels.OfType <SearchTabViewModel>()) { searchTabViewModel.Refresh(setFocus: searchTabViewModel == SelectedTabViewModel); } } } }
private async void OpenFileDialogButtonClickHandler(object sender, RoutedEventArgs args) { OpenFileDialogArguments dialogArgs = new OpenFileDialogArguments() { Width = 600, Height = 400, Filters = "All files|*.*|C# files|*.cs|XAML files|*.xaml" }; OpenFileDialogResult result = await OpenFileDialog.ShowDialogAsync(MainWindow.DialogHostName, dialogArgs); if (DataContext is FileSystemDialogViewModel viewModel) { if (!result.Canceled) { viewModel.SelectedAction = "Selected file: " + result.FileInfo.FullName; } else { viewModel.SelectedAction = "Cancel open file"; } } }
private OpenFileDialogResult ShowOpenFileDialog(OpenFileDialogParameters openFileDialogParameters) { if (openFileDialogParameters == null) { throw new ArgumentNullException("openFileDialogParameters"); } OpenFileDialog openFileDialog = new OpenFileDialog(); if (!String.IsNullOrEmpty(openFileDialogParameters.Filter)) { openFileDialog.Filter = openFileDialogParameters.Filter; } openFileDialog.Multiselect = openFileDialogParameters.Multiselect; if (!String.IsNullOrEmpty(openFileDialogParameters.InitialDirectory)) { openFileDialog.InitialDirectory = openFileDialogParameters.InitialDirectory; } OpenFileDialogResult result = new OpenFileDialogResult(); result.DialogResult = openFileDialog.ShowDialog() == true; result.SelectedFilePaths = result.DialogResult ? openFileDialog.FileNames.ToList() : new List <string>(); return(result); }
protected override async void OnStartup(StartupEventArgs e) { base.OnStartup(e); SetupExceptionHandlers(); try { mainModel = new MainModel(); string databaseFilePath = mainModel.AppSettings.DatabaseFileName; bool saveDatabaseFilePathAfterSuccessfulOpen = false; MainModel.OpenDatabaseOptions openDatabaseOptions = MainModel.OpenDatabaseOptions.NONE; DatabaseOpenResult databaseOpenResult = DatabaseOpenResult.IN_PROGRESS; while (databaseOpenResult == DatabaseOpenResult.IN_PROGRESS) { MainModel.DatabaseStatus databaseStatus = await mainModel.OpenDatabase(databaseFilePath, openDatabaseOptions); if (databaseStatus == MainModel.DatabaseStatus.OPENED) { databaseOpenResult = DatabaseOpenResult.DATABASE_OPENED; if (saveDatabaseFilePathAfterSuccessfulOpen) { mainModel.AppSettings.DatabaseFileName = MainModel.GetDatabaseNormalizedPath(databaseFilePath); mainModel.SaveSettings(); } } else if (databaseStatus == MainModel.DatabaseStatus.NOT_SET) { databaseOpenResult = DatabaseOpenResult.SHOW_SETUP_WIZARD; } else { DatabaseErrorWindowViewModel.OptionSet optionSet; switch (databaseStatus) { case MainModel.DatabaseStatus.NOT_FOUND: optionSet = DatabaseErrorWindowViewModel.OptionSet.DATABASE_NOT_FOUND; break; case MainModel.DatabaseStatus.POSSIBLE_DUMP_FILE: optionSet = DatabaseErrorWindowViewModel.OptionSet.DATABASE_DUMP_FILE; break; case MainModel.DatabaseStatus.OLD_FICTION_SCHEMA: optionSet = DatabaseErrorWindowViewModel.OptionSet.OLD_FICTION_SCHEMA; break; case MainModel.DatabaseStatus.CORRUPTED: optionSet = DatabaseErrorWindowViewModel.OptionSet.DATABASE_NOT_VALID; break; case MainModel.DatabaseStatus.SERVER_DATABASE: optionSet = DatabaseErrorWindowViewModel.OptionSet.SERVER_DATABASE; break; default: throw new Exception($"Unknown database status: {databaseStatus}."); } DatabaseErrorWindowViewModel databaseErrorWindowViewModel = new DatabaseErrorWindowViewModel(mainModel, optionSet, databaseFilePath); IWindowContext windowContext = WindowManager.CreateWindow(RegisteredWindows.WindowKey.DATABASE_ERROR_WINDOW, databaseErrorWindowViewModel); windowContext.ShowDialog(); switch (databaseErrorWindowViewModel.Result) { case DatabaseErrorWindowViewModel.DatabaseErrorWindowResult.OPEN_ANOTHER_DATABASE: OpenFileDialogResult selectDatabaseFileDialogResult = DatabaseWindowViewModel.SelectDatabaseFile(mainModel); if (selectDatabaseFileDialogResult.DialogResult) { databaseFilePath = selectDatabaseFileDialogResult.SelectedFilePaths.First(); saveDatabaseFilePathAfterSuccessfulOpen = true; } break; case DatabaseErrorWindowViewModel.DatabaseErrorWindowResult.START_SETUP_WIZARD: databaseOpenResult = DatabaseOpenResult.SHOW_SETUP_WIZARD; break; case DatabaseErrorWindowViewModel.DatabaseErrorWindowResult.DELETE_FICTION: openDatabaseOptions = MainModel.OpenDatabaseOptions.MIGRATE_FICTION; break; case DatabaseErrorWindowViewModel.DatabaseErrorWindowResult.EXIT: case DatabaseErrorWindowViewModel.DatabaseErrorWindowResult.CANCEL: databaseOpenResult = DatabaseOpenResult.EXIT_REQUESTED; break; default: throw new Exception($"Unknown database error view model result: {databaseErrorWindowViewModel.Result}."); } } } switch (databaseOpenResult) { case DatabaseOpenResult.DATABASE_OPENED: ShowMainWindow(mainModel); break; case DatabaseOpenResult.SHOW_SETUP_WIZARD: ShowSetupWizardWindow(mainModel); break; default: Close(); break; } } catch (Exception exception) { Logger.EnableLogging(); ShowErrorWindow(exception); Close(); } }
private void OkButtonClick() { if (IsCreateDatabaseSelected) { SaveFileDialogParameters saveFileDialogParameters = new SaveFileDialogParameters { DialogTitle = "Сохранение новой базы данных", Filter = "Базы данных (*.db)|*.db|Все файлы (*.*)|*.*", OverwritePrompt = true }; if (eventType == EventType.DATABASE_CORRUPTED) { string databaseFilePath = mainModel.GetDatabaseFullPath(mainModel.AppSettings.DatabaseFileName); saveFileDialogParameters.InitialDirectory = Path.GetDirectoryName(databaseFilePath); saveFileDialogParameters.InitialFileName = Path.GetFileName(databaseFilePath); } else { saveFileDialogParameters.InitialDirectory = Environment.AppDataDirectory; saveFileDialogParameters.InitialFileName = Constants.DEFAULT_DATABASE_FILE_NAME; } SaveFileDialogResult saveFileDialogResult = WindowManager.ShowSaveFileDialog(saveFileDialogParameters); if (saveFileDialogResult.DialogResult) { if (mainModel.CreateDatabase(saveFileDialogResult.SelectedFilePath)) { mainModel.AppSettings.DatabaseFileName = mainModel.GetDatabaseNormalizedPath(saveFileDialogResult.SelectedFilePath); mainModel.SaveSettings(); CurrentWindowContext.CloseDialog(true); } else { MessageBoxWindow.ShowMessage("Ошибка", "Не удалось создать базу данных.", CurrentWindowContext); } } } else { OpenFileDialogParameters openFileDialogParameters = new OpenFileDialogParameters { DialogTitle = "Выбор базы данных", Filter = "Базы данных (*.db)|*.db|Все файлы (*.*)|*.*", Multiselect = false }; OpenFileDialogResult openFileDialogResult = WindowManager.ShowOpenFileDialog(openFileDialogParameters); if (openFileDialogResult.DialogResult) { string databaseFilePath = openFileDialogResult.SelectedFilePaths.First(); if (mainModel.OpenDatabase(databaseFilePath)) { mainModel.AppSettings.DatabaseFileName = mainModel.GetDatabaseNormalizedPath(databaseFilePath); mainModel.SaveSettings(); CurrentWindowContext.CloseDialog(true); } else { UpdateHeaderAndEventType(Path.GetFileName(databaseFilePath)); NotifyPropertyChanged(nameof(Header)); } } } }
public static async Task <bool> OpenDatabase(MainModel mainModel, IWindowContext parentWindowContext) { DatabaseWindowLocalizator databaseLocalizator = mainModel.Localization.CurrentLanguage.Database; MessageBoxLocalizator messageBoxLocalizator = mainModel.Localization.CurrentLanguage.MessageBox; OpenFileDialogResult openFileDialogResult = SelectDatabaseFile(mainModel); if (openFileDialogResult.DialogResult) { string databaseFilePath = openFileDialogResult.SelectedFilePaths.First(); MainModel.OpenDatabaseOptions openDatabaseOptions = MainModel.OpenDatabaseOptions.NONE; MainModel.DatabaseStatus databaseStatus; bool stopOpenAttempts = false; bool openedSuccessfully = false; while (!stopOpenAttempts) { databaseStatus = await mainModel.OpenDatabase(databaseFilePath, openDatabaseOptions); switch (databaseStatus) { case MainModel.DatabaseStatus.OPENED: mainModel.AppSettings.DatabaseFileName = MainModel.GetDatabaseNormalizedPath(databaseFilePath); mainModel.SaveSettings(); openedSuccessfully = true; stopOpenAttempts = true; break; case MainModel.DatabaseStatus.POSSIBLE_DUMP_FILE: WindowManager.ShowMessage(databaseLocalizator.Error, databaseLocalizator.GetDatabaseDumpFileText(databaseFilePath), messageBoxLocalizator.Ok, parentWindowContext); stopOpenAttempts = true; break; case MainModel.DatabaseStatus.OLD_FICTION_SCHEMA: if (WindowManager.ShowPrompt(databaseLocalizator.OldFictionSchemaTitle, databaseLocalizator.GetOldFictionSchemaText(databaseFilePath), messageBoxLocalizator.Yes, messageBoxLocalizator.No, parentWindowContext)) { openDatabaseOptions = MainModel.OpenDatabaseOptions.MIGRATE_FICTION; } else { stopOpenAttempts = true; } break; case MainModel.DatabaseStatus.CORRUPTED: WindowManager.ShowMessage(databaseLocalizator.Error, databaseLocalizator.GetDatabaseNotValidText(databaseFilePath), messageBoxLocalizator.Ok, parentWindowContext); stopOpenAttempts = true; break; case MainModel.DatabaseStatus.SERVER_DATABASE: WindowManager.ShowMessage(databaseLocalizator.Error, databaseLocalizator.GetLibgenServerDatabaseText(databaseFilePath), messageBoxLocalizator.Ok, parentWindowContext); stopOpenAttempts = true; break; default: throw new Exception($"Unexpected database status: {databaseStatus}."); } } if (openedSuccessfully) { return(true); } else { await mainModel.OpenDatabase(mainModel.AppSettings.DatabaseFileName); return(false); } } else { return(false); } }
private void OkButtonClick() { StringBuilder filterBuilder = new StringBuilder(); filterBuilder.Append(Localization.Databases); filterBuilder.Append(" (*.db)|*.db|"); filterBuilder.Append(Localization.AllFiles); filterBuilder.Append(" (*.*)|*.*"); if (IsCreateDatabaseSelected) { SaveFileDialogParameters saveFileDialogParameters = new SaveFileDialogParameters { DialogTitle = Localization.BrowseNewDatabaseDialogTitle, Filter = filterBuilder.ToString(), OverwritePrompt = true }; if (eventType == EventType.DATABASE_CORRUPTED) { string databaseFilePath = MainModel.GetDatabaseFullPath(MainModel.AppSettings.DatabaseFileName); saveFileDialogParameters.InitialDirectory = Path.GetDirectoryName(databaseFilePath); saveFileDialogParameters.InitialFileName = Path.GetFileName(databaseFilePath); } else { saveFileDialogParameters.InitialDirectory = Environment.AppDataDirectory; saveFileDialogParameters.InitialFileName = Constants.DEFAULT_DATABASE_FILE_NAME; } SaveFileDialogResult saveFileDialogResult = WindowManager.ShowSaveFileDialog(saveFileDialogParameters); if (saveFileDialogResult.DialogResult) { if (MainModel.CreateDatabase(saveFileDialogResult.SelectedFilePath)) { MainModel.AppSettings.DatabaseFileName = MainModel.GetDatabaseNormalizedPath(saveFileDialogResult.SelectedFilePath); MainModel.SaveSettings(); CurrentWindowContext.CloseDialog(true); } else { ShowMessage(Localization.Error, Localization.CannotCreateDatabase); } } } else { OpenFileDialogParameters openFileDialogParameters = new OpenFileDialogParameters { DialogTitle = Localization.BrowseExistingDatabaseDialogTitle, Filter = filterBuilder.ToString(), Multiselect = false }; OpenFileDialogResult openFileDialogResult = WindowManager.ShowOpenFileDialog(openFileDialogParameters); if (openFileDialogResult.DialogResult) { string databaseFilePath = openFileDialogResult.SelectedFilePaths.First(); if (MainModel.OpenDatabase(databaseFilePath)) { MainModel.AppSettings.DatabaseFileName = MainModel.GetDatabaseNormalizedPath(databaseFilePath); MainModel.SaveSettings(); CurrentWindowContext.CloseDialog(true); } else { UpdateHeaderAndEventType(Path.GetFileName(databaseFilePath)); NotifyPropertyChanged(nameof(Header)); } } } }