Skip to content

Commit c70d123

Browse files
committed
chore: add remember password + handle multiple request for restore
1 parent 9d245f8 commit c70d123

File tree

5 files changed

+97
-25
lines changed

5 files changed

+97
-25
lines changed

MainWindow.Designer.cs

Lines changed: 32 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MainWindow.cs

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using postgres_database_restore_tool.ValueObject;
99
using postgres_database_restore_tool.Constants;
1010
using postgres_database_restore_tool.Properties;
11-
using System.Threading;
1211

1312
namespace postgres_database_restore_tool
1413
{
@@ -46,6 +45,8 @@ private void AddEventHandlers()
4645

4746
private void OnFormLoad(object sender, EventArgs e)
4847
{
48+
ApplyTheme();
49+
4950
LoadPostgresUserData();
5051

5152
var commandType = new List<string>()
@@ -62,6 +63,29 @@ private void OnFormLoad(object sender, EventArgs e)
6263
TypeSelectorElem.DataSource = commandType;
6364
}
6465

66+
private void ApplyTheme()
67+
{
68+
label4.ApplyRegularFont();
69+
label3.ApplyBoldFont();
70+
label2.ApplyRegularFont();
71+
UserLbl.ApplyRegularFont();
72+
PasswordLbl.ApplyRegularFont();
73+
DbNamelbl.ApplyRegularFont();
74+
TypeLbl.ApplyRegularFont();
75+
label1.ApplyRegularFont();
76+
WorkingStatus.ApplyRegularFont();
77+
UserNameElm.ApplyRegularFont();
78+
PasswordElm.ApplyRegularFont();
79+
DatabaseElem.ApplyRegularFont();
80+
TypeSelectorElem.ApplyRegularFont();
81+
ActionSelectorElem.ApplyRegularFont();
82+
SelectedFilelbl.ApplyRegularFont();
83+
RestoreBtn.ApplyBoldFont();
84+
FileOpenElem.ApplyRegularFont();
85+
rememberPassword.ApplyRegularFont();
86+
statusStrip1.ApplyRegularFont();
87+
}
88+
6589
private void LoadPostgresUserData()
6690
{
6791
UserNameElm.Text = Settings.Default.PostgresUserName;
@@ -70,6 +94,8 @@ private void LoadPostgresUserData()
7094

7195
private void OnFileOpenClick(object sender, EventArgs e)
7296
{
97+
if (isRestoring) return;
98+
7399
var selected = TargetLocation.ShowDialog();
74100
if (selected == DialogResult.OK)
75101
{
@@ -84,24 +110,29 @@ private void OnFileOpenClick(object sender, EventArgs e)
84110
}
85111
}
86112
}
87-
113+
114+
bool isRestoring = false;
88115
private void OnRestore(object sender, EventArgs e)
89116
{
90117
try
91118
{
92-
SaveUserAndPassword();
119+
if (isRestoring) return;
120+
121+
isRestoring = true;
122+
SaveUserInfo();
93123

94124
StartLoading("Restoring Database");
95125

96-
var connection = UserConnectionValidator.ValidateConnection(new UserConnectionVo()
126+
var connection = new UserConnectionVo()
97127
{
98-
UserName = UserNameElm.Text,
99-
Password = PasswordElm.Text,
100-
DatabaseName = DatabaseElem.Text,
128+
UserName = UserNameElm.Text.Trim(),
129+
Password = PasswordElm.Text.Trim(),
130+
DatabaseName = DatabaseElem.Text.Trim(),
101131
ActionTypeValue = ActionSelectorElem.SelectedValue.ToString(),
102132
DatabaseBackupType = TypeSelectorElem.SelectedValue.ToString(),
103-
RestoreFileLocation = TargetLocation.FileName,
104-
});
133+
RestoreFileLocation = TargetLocation.FileName.Trim(),
134+
}
135+
.Validate();
105136

106137
RestoreBtn.Text = "⚒ Restoring...";
107138
var bgw = new BackgroundWorker();
@@ -125,7 +156,7 @@ private void OnRestore(object sender, EventArgs e)
125156
}
126157
FinalizeLoadingFinished();
127158
};
128-
bgw.RunWorkerAsync();
159+
bgw.RunWorkerAsync();
129160
}
130161
catch (Exception ex)
131162
{
@@ -143,13 +174,24 @@ private void FinalizeLoadingFinished()
143174
EndLoading();
144175
SelectedFilelbl.Text = "No file Selected";
145176
RestoreBtn.Text = "⚒ Restore";
177+
isRestoring = false;
146178
}
147179

148-
private void SaveUserAndPassword()
180+
private void SaveUserInfo()
149181
{
150182
Settings.Default.PostgresUserName = UserNameElm.Text;
151-
Settings.Default.PostgresPassword = PasswordElm.Text;
152183
Settings.Default.Save();
153184
}
185+
186+
private void RememberPassword_CheckedChanged(object sender, EventArgs e)
187+
{
188+
var needToRemeberPassword = this.rememberPassword.Checked;
189+
190+
if (needToRemeberPassword)
191+
{
192+
Settings.Default.PostgresPassword = PasswordElm.Text;
193+
Settings.Default.Save();
194+
}
195+
}
154196
}
155197
}

MainWindow.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@
123123
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
124124
<value>183, 11</value>
125125
</metadata>
126+
<metadata name="tooltip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
127+
<value>299, 11</value>
128+
</metadata>
129+
<metadata name="tooltip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
130+
<value>299, 11</value>
131+
</metadata>
126132
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
127133
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
128134
<value>

Validator/UserConnectionValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace postgres_database_restore_tool.Validator
55
{
66
public static class UserConnectionValidator
77
{
8-
public static UserConnectionVo ValidateConnection(UserConnectionVo connectionVo)
8+
public static UserConnectionVo Validate(this UserConnectionVo connectionVo)
99
{
1010
if (string.IsNullOrEmpty(connectionVo.UserName))
1111
{

postgres-database-restore-tool.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
<Compile Include="Constants\ActionTypeConstants.cs" />
5050
<Compile Include="Constants\CommandTypeConstants.cs" />
5151
<Compile Include="Constants\PostgresConstants.cs" />
52+
<Compile Include="Helper\ApplyFont.cs" />
5253
<Compile Include="Helper\CommandExecutor.cs" />
5354
<Compile Include="MainWindow.cs">
5455
<SubType>Form</SubType>
@@ -58,6 +59,7 @@
5859
</Compile>
5960
<Compile Include="Program.cs" />
6061
<Compile Include="Properties\AssemblyInfo.cs" />
62+
<Compile Include="Providers\FontProvider.cs" />
6163
<Compile Include="Validator\UserConnectionValidator.cs" />
6264
<Compile Include="ValueObject\UserConnectionVo.cs" />
6365
<EmbeddedResource Include="MainWindow.resx">
@@ -89,6 +91,8 @@
8991
<None Include="App.config" />
9092
</ItemGroup>
9193
<ItemGroup>
94+
<None Include="Assets\Fonts\Inter-Bold.ttf" />
95+
<None Include="Assets\Fonts\Inter-Regular.ttf" />
9296
<None Include="Resources\postgres_database_restore_icon.png" />
9397
</ItemGroup>
9498
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

0 commit comments

Comments
 (0)