Skip to content

Commit

Permalink
Merge pull request #2 from minton/backup
Browse files Browse the repository at this point in the history
Add Backup Function
  • Loading branch information
Michael Minton committed Feb 5, 2015
2 parents 075b556 + 456417d commit 09267a4
Show file tree
Hide file tree
Showing 10 changed files with 6,688 additions and 34 deletions.
6 changes: 3 additions & 3 deletions Setup/setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "DataButler"
#define MyAppVersion "1.0.0.32"
#define MyAppVersion "1.0.0.33"
#define MyAppPublisher "Michael Minton"
#define MyAppURL "http://michaelminton.com"
#define MyAppURL "http://michael.minton.io"
#define MyAppExeName "DataButler.exe"

[Setup]
Expand All @@ -24,7 +24,7 @@ DefaultGroupName={#MyAppName}
AllowNoIcons=yes
LicenseFile=C:\Dev\DataButler\Resources\License.txt
OutputDir=C:\Dev\DataButler\Setup
OutputBaseFilename=DataButlerSetup1.0.0.32
OutputBaseFilename=DataButlerSetup1.0.0.33
SetupIconFile=C:\Dev\DataButler\Resources\DataButler.ico
Compression=lzma
SolidCompression=yes
Expand Down
151 changes: 151 additions & 0 deletions src/DataButler/Backup.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 88 additions & 0 deletions src/DataButler/Backup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using DataButler.Utilities;

namespace DataButler
{
public partial class Backup : Form
{
readonly BackgroundWorker _backgroundWorker = new BackgroundWorker { WorkerReportsProgress = true };
public Backup()
{
InitializeComponent();
lnkVersion.Text = Application.ProductVersion;
_backgroundWorker.DoWork += BackgroundWorkerOnDoWork;
_backgroundWorker.RunWorkerCompleted += BackgroundWorkerOnRunWorkerCompleted;
_backgroundWorker.ProgressChanged += ProgressReported;
btnBackup.Enabled = false;
string failure;

var databases = Database.GetDatabases(out failure);
if (databases.Any())
{
cbDatabase.Items.AddRange(databases);
return;
}

LogMessage(failure);
txtLog.Visible = true;
}

void ProgressReported(object sender, ProgressChangedEventArgs e)
{
var userState = e.UserState.ToString();
LogMessage(userState);
}

void LogMessage(string msg)
{
txtLog.AppendText(string.Format("{0}{1}", msg, Environment.NewLine));
txtLog.ScrollToCaret();
}

private void BackupClicked(object sender, EventArgs e)
{
txtLog.BackColor = SystemColors.Window;
txtLog.ForeColor = SystemColors.WindowText;
txtLog.Visible = true;
txtLog.Clear();
Cursor = Cursors.WaitCursor;
btnBackup.Enabled = cbDatabase.Enabled = false;
WaitImage.Visible = true;
_backgroundWorker.RunWorkerAsync(cbDatabase.SelectedItem as SqlDatabase);
}

private void BackgroundWorkerOnDoWork(object sender, DoWorkEventArgs e)
{
var database = e.Argument as SqlDatabase;
e.Result = Database.Backup(database, _backgroundWorker);
}

private void BackgroundWorkerOnRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
Cursor = Cursors.Default;
var result = e.Result as string;
var success = txtLog.Text.Contains("BACKUP DATABASE successfully") &&
txtLog.Text.Contains(string.Format("The backup set on file {0} is valid.", result));
txtLog.BackColor = success ? Color.MediumSpringGreen : Color.DarkRed;
txtLog.ForeColor = success ? Color.Black : Color.Yellow;
var message = success ? "Backup SUCCESSFULLY COMPLETE." : "Backup FAILED!";
LogMessage(message);
btnBackup.Enabled = true;
}

private void VersionLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start("https://github.com/minton/DataButler");
}

private void DatabaseSelected(object sender, EventArgs e)
{
btnBackup.Enabled = cbDatabase.SelectedItem != null;
}
}
}
Loading

0 comments on commit 09267a4

Please sign in to comment.