コード例 #1
0
        /// <summary>
        /// Handles the Click event of the RestoreDatabaseButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void RestoreDatabaseButton_Click(object sender, RoutedEventArgs e)
        {
            String       filename = TextRestoreFile.Text;
            DatabaseInfo dbInfo   = SelectDatabase.SelectedItem as DatabaseInfo;

            if (null == dbInfo)
            {
                FirstFloor.ModernUI.Windows.Controls.ModernDialog.ShowMessage(string.Format("Please select a database to restore the file into."), "No database selected", MessageBoxButton.OK);
            }
            else
            {
                if (!File.Exists(filename))
                {
                    FirstFloor.ModernUI.Windows.Controls.ModernDialog.ShowMessage(string.Format("The file {0} could not be found. Please select a valid dump file.", filename), "File not found", MessageBoxButton.OK);
                }
                else
                {
                    try
                    {
                        if (FirstFloor.ModernUI.Windows.Controls.ModernDialog.ShowMessage(string.Format("You are about to restore the database {0}[{1}] with a backup file. This means that all content in the database will be overwritten, with the information from the backup file. This action can't be undone. Do you want to continue?", dbInfo.Host, dbInfo.DatabaseName), "Proceed with database restore?", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                        {
                            BackupHandler backupHandler = new BackupHandler();
                            backupHandler.RestoreDatabase(filename, dbInfo.ID);
                            FirstFloor.ModernUI.Windows.Controls.ModernDialog.ShowMessage(string.Format("The database {0} has been restored from this backup dump file '{1}'", dbInfo.DatabaseName, filename), "Success", MessageBoxButton.OK);
                        }
                    }
                    catch (Exception ex)
                    {
                        FirstFloor.ModernUI.Windows.Controls.ModernDialog.ShowMessage(ex.Message, "Error", MessageBoxButton.OK);
                    }
                }
            }
        }