Skip to content

Commit c789f7c

Browse files
committed
fixing from code-analysis and mono build
1 parent dade796 commit c789f7c

29 files changed

+227
-177
lines changed

Retriever/Configuration.cs

+29-13
Original file line numberDiff line numberDiff line change
@@ -75,36 +75,52 @@ public static string DefaultFileName
7575
public string ConfigFileName { get => configFileName; set => configFileName = value; }
7676

7777
private static Configuration instance;
78-
78+
7979
public void Save()
8080
{
81+
if (string.IsNullOrEmpty(ConfigFileName))
82+
{
83+
ConfigFileName = DefaultFileName;
84+
}
8185
string dirName = Path.GetDirectoryName(ConfigFileName);
82-
if (!Directory.Exists(dirName))
86+
if ((!string.IsNullOrEmpty(dirName)) && (!Directory.Exists(dirName)))
8387
{
8488
Directory.CreateDirectory(dirName);
8589
}
8690
JsonSerializer serializer = new JsonSerializer();
87-
using (StreamWriter sw = new StreamWriter(ConfigFileName))
88-
using (JsonWriter writer = new JsonTextWriter(sw))
91+
StreamWriter sw = new StreamWriter(ConfigFileName);
92+
try
8993
{
90-
writer.Formatting = Formatting.Indented;
91-
serializer.Serialize(writer, this);
94+
using (JsonWriter writer = new JsonTextWriter(sw))
95+
{
96+
writer.Formatting = Formatting.Indented;
97+
serializer.Serialize(writer, this);
98+
}
99+
}
100+
finally
101+
{
102+
sw.Close();
92103
}
93104
}
94-
95-
96-
105+
97106
public static void Load(string configFileName)
98107
{
99108
try
100109
{
101110

102111
JsonSerializer serializer = new JsonSerializer();
103-
using (StreamReader sr = new StreamReader(configFileName))
104-
using (JsonReader reader = new JsonTextReader(sr))
112+
StreamReader sr = new StreamReader(configFileName);
113+
try
114+
{
115+
using (JsonReader reader = new JsonTextReader(sr))
116+
{
117+
instance = serializer.Deserialize<Configuration>(reader);
118+
instance.ConfigFileName = configFileName;
119+
}
120+
}
121+
finally
105122
{
106-
instance = serializer.Deserialize<Configuration>(reader);
107-
instance.ConfigFileName = configFileName;
123+
sr.Close();
108124
}
109125
}
110126
catch (Exception ex)

Retriever/ConsoleScanner.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010

1111
namespace Retriever
1212
{
13-
public class ConsoleScanner
13+
public class ConsoleScanner
1414
{
1515
private Profile profile;
1616
private StreamWriter swout;
1717
private Scanner scanner;
1818
private AWSCredentials creds;
19-
19+
20+
2021
public void Scan(string outputFile)
2122
{
2223
Console.WriteLine(String.Format("Writing to '{0}'", outputFile));

Retriever/FormAbout.Designer.cs

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Retriever/FormCredentials.cs

+16-19
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,28 @@ public FormCredentials()
1818
/// Gets the credentials from the GUI
1919
/// </summary>
2020
/// <value>The credentials.</value>
21-
public AWSCredentials Credentials
21+
public AWSCredentials GetCredentials()
2222
{
23-
get
23+
if (!string.IsNullOrEmpty(this.AccessKeyID) && (!string.IsNullOrEmpty(this.SecretAccessKey)))
2424
{
25-
if (!string.IsNullOrEmpty(this.AccessKeyID) && (!string.IsNullOrEmpty(this.SecretAccessKey)))
26-
{
27-
return new BasicAWSCredentials(this.AccessKeyID, this.SecretAccessKey);
28-
}
29-
else if (!string.IsNullOrEmpty(this.ProfileName))
25+
return new BasicAWSCredentials(this.AccessKeyID, this.SecretAccessKey);
26+
}
27+
else if (!string.IsNullOrEmpty(this.ProfileName))
28+
{
29+
SharedCredentialsFile credentialsFile = new SharedCredentialsFile();
30+
if (!credentialsFile.TryGetProfile(ProfileName, out CredentialProfile credentialProfile))
3031
{
31-
SharedCredentialsFile credentialsFile = new SharedCredentialsFile();
32-
if (!credentialsFile.TryGetProfile(ProfileName, out CredentialProfile credentialProfile))
33-
{
34-
throw new ApplicationException(string.Format("Profile '{0}' does not exists", ProfileName));
35-
}
36-
if (!AWSCredentialsFactory.TryGetAWSCredentials(credentialProfile, credentialsFile, out AWSCredentials credentials))
37-
{
38-
throw new ApplicationException(string.Format("Failed to get credentials for profile '{0}'", ProfileName));
39-
}
40-
return credentials;
32+
throw new ApplicationException(string.Format("Profile '{0}' does not exists", ProfileName));
4133
}
42-
else
34+
if (!AWSCredentialsFactory.TryGetAWSCredentials(credentialProfile, credentialsFile, out AWSCredentials credentials))
4335
{
44-
return FallbackCredentialsFactory.GetCredentials();
36+
throw new ApplicationException(string.Format("Failed to get credentials for profile '{0}'", ProfileName));
4537
}
38+
return credentials;
39+
}
40+
else
41+
{
42+
return FallbackCredentialsFactory.GetCredentials();
4643
}
4744
}
4845

Retriever/FormMain.Designer.cs

+1-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Retriever/FormMain.cs

+15-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
using System.ComponentModel;
33
using System.Net;
44
using System.Reflection;
5-
using System.Runtime.CompilerServices;
6-
using System.Threading;
75
using System.Windows.Forms;
86
using Amazon;
97
using Amazon.Runtime;
@@ -31,6 +29,20 @@ public FormMain()
3129
{
3230
InitializeComponent();
3331

32+
try
33+
{
34+
ComponentResourceManager resources = new ComponentResourceManager(typeof(FormMain));
35+
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
36+
this.imageList.ImageStream = ((ImageListStreamer)resources.GetObject("imageList.ImageStream"));
37+
this.imageList.TransparentColor = System.Drawing.Color.Transparent;
38+
this.imageList.Images.SetKeyName(0, "icons8-checkmark-50.png");
39+
this.imageList.Images.SetKeyName(1, "icons8-error-50.png");
40+
}
41+
catch (Exception ex)
42+
{
43+
Console.Error.WriteLine(ex);
44+
}
45+
3446
this.appBar.ToolTip = new ModernToolTip();
3547

3648
PopulateActions();
@@ -300,7 +312,7 @@ private void ShowCredentialsDialog()
300312
DialogResult dr = formCredentials.ShowDialog(this);
301313
if (dr == DialogResult.OK)
302314
{
303-
this.creds = formCredentials.Credentials;
315+
this.creds = formCredentials.GetCredentials();
304316
}
305317
}
306318

Retriever/FormMain.resx

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
132132
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
133133
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAACw
134-
CgAAAk1TRnQBSQFMAgEBAgEAAYgBAQGIAQEBIAEAASABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
134+
CgAAAk1TRnQBSQFMAgEBAgEAAZABAQGQAQEBIAEAASABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
135135
AwABgAMAASADAAEBAQABCAYAARAYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
136136
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
137137
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA

Retriever/FormProfileEditor.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ public FormProfileEditor(Profile profile, string selectedService, string selecte
5050
appBar.ToolTip = new ModernToolTip();
5151

5252
AppAction regionAction = new AppAction();
53-
regionAction.Image = Resources.Regions50;
53+
regionAction.Image = Resources.Regionss50;
5454
regionAction.Cursor = Cursors.Hand;
5555
regionAction.ToolTip = "Regions Editor";
5656
regionAction.Click += RegionAction_Click;
5757
this.appBar.Actions.Add(regionAction);
5858

5959
AppAction saveProfileAction = new AppAction();
60-
saveProfileAction.Image = Resources.SaveAs50;
60+
saveProfileAction.Image = Resources.Save50;
6161
saveProfileAction.Cursor = Cursors.Hand;
6262
saveProfileAction.ToolTip = "Save Profile As...";
6363
saveProfileAction.Click += SaveProfileAction_Click;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Retriever/Model/CloudObjects.cs

+23-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Linq;
55
using CloudOps;
66
using Newtonsoft.Json;
7-
using System;
87

98
namespace Retriever
109
{
@@ -16,25 +15,40 @@ public void Save()
1615
{
1716
Save("objects.json");
1817
}
19-
18+
2019
public void Save(string fileName)
2120
{
2221
JsonSerializer serializer = new JsonSerializer();
23-
using (StreamWriter sw = new StreamWriter(fileName))
24-
using (JsonWriter writer = new JsonTextWriter(sw))
22+
StreamWriter sw = new StreamWriter(fileName);
23+
try
24+
{
25+
using (JsonWriter writer = new JsonTextWriter(sw))
26+
{
27+
writer.Formatting = Formatting.Indented;
28+
serializer.Serialize(writer, this);
29+
}
30+
}
31+
finally
2532
{
26-
writer.Formatting = Formatting.Indented;
27-
serializer.Serialize(writer, this);
33+
sw.Close();
2834
}
2935
}
3036

37+
3138
public static CloudObjects Load()
3239
{
3340
JsonSerializer serializer = new JsonSerializer();
34-
using (StreamReader sr = new StreamReader("objects.json"))
35-
using (JsonReader reader = new JsonTextReader(sr))
41+
StreamReader sr = new StreamReader("objects.json");
42+
try
43+
{
44+
using (JsonReader reader = new JsonTextReader(sr))
45+
{
46+
return serializer.Deserialize<CloudObjects>(reader);
47+
}
48+
}
49+
finally
3650
{
37-
return serializer.Deserialize<CloudObjects>(reader);
51+
sr.Close();
3852
}
3953

4054
}

Retriever/Model/Profile.cs

+23-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Collections.Generic;
22
using System.IO;
33
using CloudOps;
4-
using Retriever.Properties;
54
using Newtonsoft.Json;
65
using AWSRetriver.Controls;
76

@@ -144,23 +143,37 @@ public void Save()
144143
public void SaveAs(string newPath)
145144
{
146145
JsonSerializer serializer = new JsonSerializer();
147-
using (StreamWriter sw = new StreamWriter(newPath))
148-
using (JsonWriter writer = new JsonTextWriter(sw))
146+
StreamWriter sw = new StreamWriter(newPath);
147+
try
149148
{
150-
writer.Formatting = Formatting.Indented;
151-
serializer.Serialize(writer, this);
149+
using (JsonWriter writer = new JsonTextWriter(sw))
150+
{
151+
writer.Formatting = Formatting.Indented;
152+
serializer.Serialize(writer, this);
153+
}
154+
}
155+
finally
156+
{
157+
sw.Close();
152158
}
153159
}
154160

155161
public static Profile Load(string path)
156162
{
157163
JsonSerializer serializer = new JsonSerializer();
158-
using (StreamReader sr = new StreamReader(path))
159-
using (JsonReader reader = new JsonTextReader(sr))
164+
StreamReader sr = new StreamReader(path);
165+
try
166+
{
167+
using (JsonReader reader = new JsonTextReader(sr))
168+
{
169+
Profile p = serializer.Deserialize<Profile>(reader);
170+
p.path = path;
171+
return p;
172+
}
173+
}
174+
finally
160175
{
161-
Profile p = serializer.Deserialize<Profile>(reader);
162-
p.path = path;
163-
return p;
176+
sr.Close();
164177
}
165178
}
166179
}

0 commit comments

Comments
 (0)