Skip to content

Commit 69e7517

Browse files
committed
Fixed some crashes on putting invalid token or URL to settings; Dropped unused username field from settings
1 parent 5bcf3ba commit 69e7517

File tree

10 files changed

+294
-328
lines changed

10 files changed

+294
-328
lines changed

GitlabCleaner/App.config

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
<setting name="url" serializeAs="String">
1414
<value />
1515
</setting>
16-
<setting name="username" serializeAs="String">
17-
<value />
18-
</setting>
1916
<setting name="apikey" serializeAs="String">
2017
<value />
2118
</setting>

GitlabCleaner/MainForm.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Windows.Forms;
66
using GitLabApiClient;
77
using GitLabApiClient.Models.Pipelines;
8-
using GitLabApiClient.Models.Pipelines.Responses;
98

109
namespace GitlabCleaner
1110
{
@@ -32,14 +31,19 @@ private void settingsButton_Click(object sender, EventArgs e)
3231

3332
private async void connectButton_Click(object sender, EventArgs e)
3433
{
35-
if (Properties.Settings.Default.apikey.Length == 0)
34+
if (Properties.Settings.Default.apikey.Length == 0 || Properties.Settings.Default.url.Length == 0)
3635
{
3736
return;
3837
}
3938

40-
if (client == null)
39+
try
4140
{
42-
client = new GitLabClient(Properties.Settings.Default.url, Properties.Settings.Default.apikey);
41+
listView1.UseWaitCursor = true;
42+
if (client == null)
43+
{
44+
client = new GitLabClient(Properties.Settings.Default.url, Properties.Settings.Default.apikey);
45+
}
46+
listView1.Items.Clear();
4347
toolStripStatusLabel1.Text = Properties.Resources.Connecting;
4448
toolStripProgressBar1.Style = ProgressBarStyle.Marquee;
4549
GitLabApiClient.Models.Users.Responses.Session session = await client.Users.GetCurrentSessionAsync().ConfigureAwait(true);
@@ -52,6 +56,7 @@ private async void connectButton_Click(object sender, EventArgs e)
5256
};
5357
userAvatar.LoadAsync();
5458
userAvatar.LoadCompleted += delegate { toolStripLabel1.Image = userAvatar.Image; };
59+
userAvatar.Dispose();
5560

5661
toolStripStatusLabel1.Text = Properties.Resources.DownloadingProjects;
5762
IList<GitLabApiClient.Models.Projects.Responses.Project> projects = await client.Projects.GetAsync().ConfigureAwait(true);
@@ -60,8 +65,9 @@ private async void connectButton_Click(object sender, EventArgs e)
6065
toolStripProgressBar1.Maximum = projects.Count;
6166
toolStripProgressBar1.Style = ProgressBarStyle.Continuous;
6267
listView1.Items.Clear();
63-
listView1.UseWaitCursor = true;
64-
foreach (GitLabApiClient.Models.Projects.Responses.Project project in projects) {
68+
69+
foreach (GitLabApiClient.Models.Projects.Responses.Project project in projects)
70+
{
6571
toolStripProgressBar1.PerformStep();
6672
toolStripStatusLabel1.Text = String.Format(CultureInfo.CurrentCulture, Properties.Resources.DownloadingPipelineProgress, toolStripProgressBar1.Value, toolStripProgressBar1.Maximum, Math.Ceiling(toolStripProgressBar1.Value / toolStripProgressBar1.Maximum * 100.0));
6773
ListViewGroup group = new ListViewGroup(project.NameWithNamespace);
@@ -85,6 +91,15 @@ private async void connectButton_Click(object sender, EventArgs e)
8591

8692
selectDropdownButton.Enabled = true;
8793
connectButton.Enabled = false;
94+
95+
}
96+
catch (Exception ex)
97+
{
98+
selectDropdownButton.Enabled = false;
99+
MessageBox.Show(ex.Message, Properties.Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
100+
}
101+
finally
102+
{
88103
toolStripStatusLabel1.Text = Properties.Resources.Ready;
89104
toolStripProgressBar1.Value = 0;
90105
listView1.UseWaitCursor = false;

GitlabCleaner/Properties/Resources.Designer.cs

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

GitlabCleaner/Properties/Resources.pl-PL.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@
132132
<data name="DownloadingProjects" xml:space="preserve">
133133
<value>Czytanie projektów...</value>
134134
</data>
135+
<data name="Error" xml:space="preserve">
136+
<value>Błąd</value>
137+
</data>
135138
<data name="Ready" xml:space="preserve">
136139
<value>Gotowy.</value>
137140
</data>

GitlabCleaner/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@
132132
<data name="DownloadingProjects" xml:space="preserve">
133133
<value>Reading projects...</value>
134134
</data>
135+
<data name="Error" xml:space="preserve">
136+
<value>Error</value>
137+
</data>
135138
<data name="Ready" xml:space="preserve">
136139
<value>Ready.</value>
137140
</data>

GitlabCleaner/Properties/Settings.Designer.cs

Lines changed: 1 addition & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GitlabCleaner/Properties/Settings.settings

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
<Setting Name="url" Type="(Web Service URL)" Scope="User">
66
<Value Profile="(Default)" />
77
</Setting>
8-
<Setting Name="username" Type="System.String" Scope="User">
9-
<Value Profile="(Default)" />
10-
</Setting>
118
<Setting Name="apikey" Type="System.String" Scope="User">
129
<Value Profile="(Default)" />
1310
</Setting>

GitlabCleaner/SettingsForm.Designer.cs

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

GitlabCleaner/SettingsForm.cs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Globalization;
3-
using System.Threading.Tasks;
43
using System.Windows.Forms;
54

65

@@ -15,22 +14,39 @@ public SettingsForm()
1514

1615
private async void verifyButton_Click(object sender, EventArgs e)
1716
{
18-
GitLabApiClient.GitLabClient client = new GitLabApiClient.GitLabClient(urlTextBox.Text, apikeyTextBox.Text);
19-
Task<GitLabApiClient.Models.Users.Responses.Session> sessionTask = client.Users.GetCurrentSessionAsync();
20-
21-
GitLabApiClient.Models.Users.Responses.Session response = await sessionTask.ConfigureAwait(true);
22-
23-
pictureBox1.ImageLocation = response.AvatarUrl;
24-
pictureBox1.LoadAsync();
25-
MessageBox.Show(String.Format(CultureInfo.CurrentCulture, Properties.Resources.TestingSucceeded, response.Name));
17+
try
18+
{
19+
GitLabApiClient.GitLabClient client = new GitLabApiClient.GitLabClient(urlTextBox.Text, apikeyTextBox.Text);
20+
GitLabApiClient.Models.Users.Responses.Session response = await client.Users.GetCurrentSessionAsync().ConfigureAwait(true);
21+
pictureBox1.Visible = false;
22+
pictureBox1.ImageLocation = response.AvatarUrl;
23+
pictureBox1.LoadAsync();
24+
MessageBox.Show(String.Format(CultureInfo.CurrentCulture, Properties.Resources.TestingSucceeded, response.Name));
25+
saveButton.Enabled = true;
26+
}
27+
catch (Exception ex)
28+
{
29+
saveButton.Enabled = false;
30+
MessageBox.Show(ex.Message, Properties.Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
31+
return;
32+
}
2633
}
2734

2835
private void saveButton_Click(object sender, EventArgs e)
2936
{
3037
Properties.Settings.Default.url = urlTextBox.Text;
31-
Properties.Settings.Default.username = usernameTextBox.Text;
3238
Properties.Settings.Default.apikey = apikeyTextBox.Text;
3339
Properties.Settings.Default.Save();
3440
}
41+
42+
private void urlTextBox_TextChanged(object sender, EventArgs e)
43+
{
44+
verifyButton.Enabled = urlTextBox.Text.Length > 0 && apikeyTextBox.Text.Length > 0;
45+
}
46+
47+
private void pictureBox1_LoadCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
48+
{
49+
pictureBox1.Visible = true;
50+
}
3551
}
3652
}

0 commit comments

Comments
 (0)