Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 88 additions & 32 deletions MainWindow.Designer.cs

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

49 changes: 40 additions & 9 deletions MainWindow.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using postgres_database_restore_tool.Helper;
using postgres_database_restore_tool.Validator;
Expand All @@ -15,6 +16,20 @@ public PgAdmin()
AddEventHandlers();
}

private void StartLoading(string msg)
{
loadingLbl.Text = msg;
loadingLbl.Visible = true;
loadingBar.Visible = true;
}

private void EndLoading()
{
loadingLbl.Text = "";
loadingLbl.Visible = false;
loadingBar.Visible = false;
}

const string pwdKey = "PGPASSWORD";

private void AddEventHandlers()
Expand Down Expand Up @@ -54,8 +69,8 @@ private void OnRestore(object sender, EventArgs e)
{
try
{
StartLoading("Restoring Database");


var connection = UserConnectionValidator.ValidateConnection(new UserConnectionVo()
{
UserName = UserNameElm.Text,
Expand All @@ -67,20 +82,36 @@ private void OnRestore(object sender, EventArgs e)
});

WorkingStatus.Text = "Restoring...";
CommandExecutor.ExecuteRestore(connection);
WorkingStatus.Text = "Completed";
MessageBox.Show($"Database #{DatabaseElem.Text} restored successfully");
SelectedFilelbl.Text = "";
WorkingStatus.Text = "";
var bgw = new BackgroundWorker();
bgw.DoWork += (object _, DoWorkEventArgs args) =>
{
CommandExecutor.ExecuteRestore(connection);
};
bgw.RunWorkerCompleted += (object _, RunWorkerCompletedEventArgs args) =>
{
if(args.Error == null)
{
WorkingStatus.Text = "Completed";
MessageBox.Show($"Database #{DatabaseElem.Text} restored successfully");
}
else
{
var msg = (args.Error as Exception)?.Message ?? "Error during operation";
MessageBox.Show(msg);
}
SelectedFilelbl.Text = "";
WorkingStatus.Text = "";
EndLoading();

};
bgw.RunWorkerAsync();
}
catch (Exception ex)
{
EndLoading();
SelectedFilelbl.Text = "";
WorkingStatus.Text = "";
MessageBox.Show(ex.Message);
}
finally
{
Environment.SetEnvironmentVariable(pwdKey, "");
}
}
Expand Down
3 changes: 3 additions & 0 deletions MainWindow.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,7 @@
<metadata name="TargetLocation.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>25, 11</value>
</metadata>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>183, 11</value>
</metadata>
</root>