private async void GetStats()
 {
     IsCreatingIndexesMessageVisible = true;
     AreDatabaseStatsVisible = false;
     DatabaseStats databaseStats;
     try
     {
         databaseStats = await MainModel.GetDatabaseStatsAsync();
     }
     catch (Exception exception)
     {
         ShowErrorWindow(exception, CurrentWindowContext);
         CurrentWindowContext.CloseDialog(false);
         return;
     }
     DatabaseFilePath = MainModel.GetDatabaseFullPath(MainModel.AppSettings.DatabaseFileName);
     NonFictionTotalBooks = formatter.ToFormattedString(databaseStats.NonFictionBookCount);
     NonFictionLastUpdate = databaseStats.NonFictionLastUpdate.HasValue ?
         formatter.ToFormattedDateTimeString(databaseStats.NonFictionLastUpdate.Value) : Localization.Never;
     FictionTotalBooks = formatter.ToFormattedString(databaseStats.FictionBookCount);
     FictionLastUpdate = databaseStats.FictionLastUpdate.HasValue ? formatter.ToFormattedDateTimeString(databaseStats.FictionLastUpdate.Value) :
         Localization.Never;
     SciMagTotalArticles = formatter.ToFormattedString(databaseStats.SciMagArticleCount);
     SciMagLastUpdate = databaseStats.SciMagLastUpdate.HasValue ? formatter.ToFormattedDateTimeString(databaseStats.SciMagLastUpdate.Value) :
         Localization.Never;
     IsCreatingIndexesMessageVisible = false;
     AreDatabaseStatsVisible = true;
 }
 private void SkipVersion()
 {
     MainModel.AppSettings.LastUpdate.IgnoreReleaseName = updateCheckResult.NewReleaseName;
     MainModel.SaveSettings();
     MainModel.LastApplicationUpdateCheckResult = null;
     CurrentWindowContext.CloseDialog(true);
 }
 private void OkButtonClick()
 {
     mainModel.AppSettings.Network = new AppSettings.NetworkSettings
     {
         OfflineMode   = NetworkIsOfflineModeOn,
         UseProxy      = NetworkUseProxy,
         ProxyAddress  = NetworkProxyAddress,
         ProxyPort     = NetworkProxyPortValue,
         ProxyUserName = NetworkProxyUserName,
         ProxyPassword = NetworkProxyPassword
     };
     mainModel.AppSettings.Mirrors = new AppSettings.MirrorSettings
     {
         NonFictionBooksMirrorName           = ParseDisplayMirrorName(MirrorsSelectedNonFictionBooksMirror),
         NonFictionCoversMirrorName          = ParseDisplayMirrorName(MirrorsSelectedNonFictionCoversMirror),
         NonFictionSynchronizationMirrorName = ParseDisplayMirrorName(MirrorsSelectedNonFictionSynchronizationMirror),
         FictionBooksMirrorName   = ParseDisplayMirrorName(MirrorsSelectedFictionBooksMirror),
         FictionCoversMirrorName  = ParseDisplayMirrorName(MirrorsSelectedFictionCoversMirror),
         ArticlesMirrorMirrorName = ParseDisplayMirrorName(MirrorsSelectedArticlesMirror)
     };
     mainModel.AppSettings.Search = new AppSettings.SearchSettings
     {
         LimitResults       = SearchIsLimitResultsOn,
         MaximumResultCount = SearchMaximumResultCountValue ?? DEFAULT_MAXIMUM_SEARCH_RESULT_COUNT
     };
     if (SearchIsOpenInModalWindowSelected)
     {
         mainModel.AppSettings.Search.OpenDetailsMode = AppSettings.SearchSettings.DetailsMode.NEW_MODAL_WINDOW;
     }
     else if (SearchIsOpenInNonModalWindowSelected)
     {
         mainModel.AppSettings.Search.OpenDetailsMode = AppSettings.SearchSettings.DetailsMode.NEW_NON_MODAL_WINDOW;
     }
     else if (SearchIsOpenInNewTabSelected)
     {
         mainModel.AppSettings.Search.OpenDetailsMode = AppSettings.SearchSettings.DetailsMode.NEW_TAB;
     }
     mainModel.AppSettings.Export = new AppSettings.ExportSettings
     {
         OpenResultsAfterExport = ExportIsOpenResultsAfterExportEnabled,
         SplitIntoMultipleFiles = ExportIsSplitIntoMultipleFilesEnabled,
         MaximumRowsPerFile     = ExportMaximumRowsPerFileValue ?? MAX_EXPORT_ROWS_PER_FILE
     };
     if (advancedIsLoggingEnabled != mainModel.AppSettings.Advanced.LoggingEnabled)
     {
         mainModel.AppSettings.Advanced.LoggingEnabled = advancedIsLoggingEnabled;
         if (advancedIsLoggingEnabled)
         {
             mainModel.EnableLogging();
         }
         else
         {
             mainModel.DisableLogging();
         }
     }
     mainModel.SaveSettings();
     mainModel.CreateNewHttpClient();
     settingsChanged = false;
     CurrentWindowContext.CloseDialog(true);
 }
Exemple #4
0
 private void CloseTabRequested(object sender, EventArgs e)
 {
     if (modalWindow)
     {
         CurrentWindowContext.CloseDialog(false);
     }
     else
     {
         CurrentWindowContext.Close();
     }
 }
        private void OkButtonClick()
        {
            AppSettings appSettings = MainModel.AppSettings;

            appSettings.Network.ProxyAddress  = ProxyAddress;
            appSettings.Network.ProxyPort     = ProxyPortValue;
            appSettings.Network.ProxyUserName = ProxyUserName ?? String.Empty;
            appSettings.Network.ProxyPassword = ProxyPassword ?? String.Empty;
            MainModel.SaveSettings();
            CurrentWindowContext.CloseDialog(true);
        }
        private async void DownloadAsync()
        {
            IsSkipButtonVisible      = false;
            IsDownloadButtonVisible  = false;
            IsCancelButtonVisible    = false;
            IsInterruptButtonVisible = true;
            string downloadFilePath = null;

            MainModel.DownloadFileResult?result = null;
            try
            {
                string downloadDirectory = Path.Combine(Environment.AppDataDirectory, "Updates");
                if (!Directory.Exists(downloadDirectory))
                {
                    Directory.CreateDirectory(downloadDirectory);
                }
                downloadFilePath = Path.Combine(downloadDirectory, updateCheckResult.FileName);
                Progress <object> downloadProgressHandler = new Progress <object>(HandleDownloadProgress);
                result = await MainModel.DownloadFileAsync(updateCheckResult.DownloadUrl, downloadFilePath, downloadProgressHandler,
                                                           cancellationTokenSource.Token);
            }
            catch (Exception exception)
            {
                ShowErrorWindow(exception, CurrentWindowContext);
                error = true;
            }
            if (!error && result != MainModel.DownloadFileResult.COMPLETED)
            {
                if (result == MainModel.DownloadFileResult.INCOMPLETE)
                {
                    ShowMessage(Localization.Error, Localization.IncompleteDownload);
                }
                error = true;
            }
            IsInterruptButtonVisible = false;
            IsCloseButtonVisible     = true;
            if (!error)
            {
                if (Environment.IsInPortableMode)
                {
                    Process.Start("explorer.exe", $@"/select, ""{downloadFilePath}""");
                    CurrentWindowContext.CloseDialog(false);
                }
                else
                {
                    Process.Start(downloadFilePath);
                    CurrentWindowContext.CloseDialog(false);
                    ApplicationShutdownRequested?.Invoke(this, EventArgs.Empty);
                }
            }
        }
        private async void GetStats()
        {
            isDatabaseOperationInProgress = true;
            AreDatabaseStatsVisible       = false;
            DatabaseStats databaseStats;

            try
            {
                bool databaseStatsIndexesCreated = await MainModel.CheckIfDatabaseStatsIndexesCreated();

                if (!databaseStatsIndexesCreated)
                {
                    if (!ShowPrompt(Localization.IndexesRequiredTitle, Localization.IndexesRequiredText))
                    {
                        isDatabaseOperationInProgress = false;
                        CurrentWindowContext.CloseDialog(false);
                        return;
                    }
                }
                IsCreatingIndexesMessageVisible = true;
                databaseStats = await MainModel.GetDatabaseStatsAsync();
            }
            catch (Exception exception)
            {
                ShowErrorWindow(exception, CurrentWindowContext);
                isDatabaseOperationInProgress = false;
                CurrentWindowContext.CloseDialog(false);
                return;
            }
            DatabaseFilePath     = MainModel.GetDatabaseFullPath(MainModel.AppSettings.DatabaseFileName);
            NonFictionTotalBooks = formatter.ToFormattedString(databaseStats.NonFictionBookCount);
            NonFictionLastUpdate = databaseStats.NonFictionLastUpdate.HasValue ?
                                   formatter.ToFormattedDateTimeString(databaseStats.NonFictionLastUpdate.Value) : Localization.Never;
            FictionTotalBooks = formatter.ToFormattedString(databaseStats.FictionBookCount);
            FictionLastUpdate = databaseStats.FictionLastUpdate.HasValue ? formatter.ToFormattedDateTimeString(databaseStats.FictionLastUpdate.Value) :
                                Localization.Never;
            SciMagTotalArticles = formatter.ToFormattedString(databaseStats.SciMagArticleCount);
            SciMagLastUpdate    = databaseStats.SciMagLastUpdate.HasValue ? formatter.ToFormattedDateTimeString(databaseStats.SciMagLastUpdate.Value) :
                                  Localization.Never;
            IsCreatingIndexesMessageVisible = false;
            AreDatabaseStatsVisible         = true;
            isDatabaseOperationInProgress   = false;
        }
 private async void DownloadAsync()
 {
     IsSkipButtonVisible      = false;
     IsDownloadButtonVisible  = false;
     IsCancelButtonVisible    = false;
     IsInterruptButtonVisible = true;
     Updater.UpdateDownloadResult result = null;
     try
     {
         Progress <object> downloadProgressHandler = new Progress <object>(HandleDownloadProgress);
         result = await MainModel.Updater.DownloadUpdateAsync(updateCheckResult, downloadProgressHandler, cancellationTokenSource.Token);
     }
     catch (Exception exception)
     {
         ShowErrorWindow(exception, CurrentWindowContext);
         error = true;
     }
     if (!error && result.DownloadResult != DownloadUtils.DownloadResult.COMPLETED)
     {
         if ((result.DownloadResult == DownloadUtils.DownloadResult.INCOMPLETE) || (result.DownloadResult == DownloadUtils.DownloadResult.ERROR))
         {
             ShowMessage(Localization.Error, Localization.IncompleteDownload);
         }
         error = true;
     }
     IsInterruptButtonVisible = false;
     IsCloseButtonVisible     = true;
     if (!error)
     {
         if (Environment.IsInPortableMode)
         {
             Process.Start("explorer.exe", $@"/select, ""{result.DownloadFilePath}""");
             CurrentWindowContext.CloseDialog(false);
         }
         else
         {
             Process.Start(result.DownloadFilePath);
             CurrentWindowContext.CloseDialog(false);
             ApplicationShutdownRequested?.Invoke(this, EventArgs.Empty);
         }
     }
 }
Exemple #9
0
        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));
                    }
                }
            }
        }
 private void OkButtonClick()
 {
     Result = Options.First(option => option.IsSelected).Result;
     CurrentWindowContext.CloseDialog(true);
 }
Exemple #11
0
 private void CancelButtonClick()
 {
     CurrentWindowContext.CloseDialog(false);
 }
 private void Cancel()
 {
     CurrentWindowContext.CloseDialog(false);
 }
Exemple #13
0
 private void CloseWindow()
 {
     CurrentWindowContext.CloseDialog(true);
 }
 private void CancelButtonClick()
 {
     Result = DatabaseErrorWindowResult.CANCEL;
     CurrentWindowContext.CloseDialog(false);
 }
Exemple #15
0
 private void OkButtonClick()
 {
     MainModel.AppSettings.General = new GeneralSettings
     {
         Language    = GeneralSelectedLanguage.Value.Name,
         UpdateCheck = GeneralSelectedUpdateCheckInterval.Key
     };
     MainModel.AppSettings.Network = new NetworkSettings
     {
         OfflineMode   = NetworkIsOfflineModeOn,
         UseProxy      = NetworkUseProxy,
         ProxyAddress  = NetworkProxyAddress,
         ProxyPort     = NetworkProxyPortValue,
         ProxyUserName = NetworkProxyUserName ?? String.Empty,
         ProxyPassword = NetworkProxyPassword ?? String.Empty
     };
     MainModel.AppSettings.Download = new DownloadSettings
     {
         UseDownloadManager = DownloadIsUseDownloadManagerSelected,
         DownloadDirectory  = DownloadDirectory,
         Timeout            = DownloadTimeoutValue ?? DEFAULT_DOWNLOAD_TIMEOUT,
         Attempts           = DownloadAttemptCountValue ?? DEFAULT_DOWNLOAD_ATTEMPT_COUNT,
         RetryDelay         = DownloadRetryDelayValue ?? DEFAULT_DOWNLOAD_RETRY_DELAY
     };
     MainModel.AppSettings.Mirrors = new MirrorSettings
     {
         NonFictionBooksMirrorName           = ParseDisplayMirrorName(MirrorsSelectedNonFictionBooksMirror),
         NonFictionCoversMirrorName          = ParseDisplayMirrorName(MirrorsSelectedNonFictionCoversMirror),
         NonFictionSynchronizationMirrorName = ParseDisplayMirrorName(MirrorsSelectedNonFictionSynchronizationMirror),
         FictionBooksMirrorName  = ParseDisplayMirrorName(MirrorsSelectedFictionBooksMirror),
         FictionCoversMirrorName = ParseDisplayMirrorName(MirrorsSelectedFictionCoversMirror),
         ArticlesMirrorName      = ParseDisplayMirrorName(MirrorsSelectedArticlesMirror)
     };
     MainModel.AppSettings.Search = new SearchSettings
     {
         LimitResults       = SearchIsLimitResultsOn,
         MaximumResultCount = SearchMaximumResultCountValue ?? DEFAULT_MAXIMUM_SEARCH_RESULT_COUNT
     };
     if (SearchIsOpenInModalWindowSelected)
     {
         MainModel.AppSettings.Search.OpenDetailsMode = SearchSettings.DetailsMode.NEW_MODAL_WINDOW;
     }
     else if (SearchIsOpenInNonModalWindowSelected)
     {
         MainModel.AppSettings.Search.OpenDetailsMode = SearchSettings.DetailsMode.NEW_NON_MODAL_WINDOW;
     }
     else if (SearchIsOpenInNewTabSelected)
     {
         MainModel.AppSettings.Search.OpenDetailsMode = SearchSettings.DetailsMode.NEW_TAB;
     }
     MainModel.AppSettings.Export = new ExportSettings
     {
         OpenResultsAfterExport = ExportIsOpenResultsAfterExportEnabled,
         SplitIntoMultipleFiles = ExportIsSplitIntoMultipleFilesEnabled,
         MaximumRowsPerFile     = ExportMaximumRowsPerFileValue ?? MAX_EXPORT_ROWS_PER_FILE
     };
     if (advancedIsLoggingEnabled != MainModel.AppSettings.Advanced.LoggingEnabled)
     {
         MainModel.AppSettings.Advanced.LoggingEnabled = advancedIsLoggingEnabled;
         if (advancedIsLoggingEnabled)
         {
             MainModel.EnableLogging();
         }
         else
         {
             MainModel.DisableLogging();
         }
     }
     MainModel.AppSettings.Advanced.SqlDebuggerEnabled = AdvancedIsSqlDebuggerEnabled;
     MainModel.SaveSettings();
     MainModel.ReconfigureSettingsDependencies();
     settingsChanged = false;
     CurrentWindowContext.CloseDialog(true);
 }
Exemple #16
0
 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));
             }
         }
     }
 }
 private void Close()
 {
     CurrentWindowContext.CloseDialog(!error);
 }
 private void FinishButtonClick()
 {
     currentPage.OnFinishButtonClick();
     CurrentWindowContext.CloseDialog(true);
 }
 private void Update()
 {
     ApplicationUpdateRequested = true;
     CurrentWindowContext.CloseDialog(true);
 }