Skip to content

Commit e9bab86

Browse files
committed
gh-65 address additional warnings reported by sonarqube
Signed-off-by: Victor Chang <[email protected]>
1 parent 7ee6d03 commit e9bab86

40 files changed

+200
-157
lines changed

src/Api/LoggingDataDictionary.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,24 @@
22
// SPDX-FileCopyrightText: © 2021 NVIDIA Corporation
33
// SPDX-License-Identifier: Apache License 2.0
44

5+
using System;
56
using System.Collections.Generic;
67
using System.Linq;
8+
using System.Runtime.Serialization;
79

810
namespace Monai.Deploy.InformaticsGateway.Api
911
{
12+
[Serializable]
1013
public class LoggingDataDictionary<K, V> : Dictionary<K, V>
1114
{
15+
public LoggingDataDictionary()
16+
{
17+
}
18+
19+
protected LoggingDataDictionary(SerializationInfo info, StreamingContext context) : base(info, context)
20+
{
21+
}
22+
1223
public override string ToString()
1324
{
1425
var pairs = this.Select(x => string.Format("{0}={1}", x.Key, x.Value));

src/Api/Rest/InferenceRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ private bool Validate(out string details)
216216
}
217217

218218
if (InputResources.IsNullOrEmpty() ||
219-
InputResources.Count(predicate => predicate.Interface != InputInterfaceType.Algorithm) == 0)
219+
!InputResources.Any(predicate => predicate.Interface != InputInterfaceType.Algorithm))
220220
{
221221
errors.Add("No 'inputResources' specified.");
222222
}

src/Api/Rest/InferenceRequestException.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,22 @@
33
// SPDX-License-Identifier: Apache License 2.0
44

55
using System;
6+
using System.Runtime.Serialization;
67

78
namespace Monai.Deploy.InformaticsGateway.Api.Rest
89
{
910
/// <summary>
1011
/// Inference request exception.
1112
/// </summary>
13+
[Serializable]
1214
public class InferenceRequestException : Exception
1315
{
1416
public InferenceRequestException(string message) : base(message)
1517
{
1618
}
19+
20+
protected InferenceRequestException(SerializationInfo info, StreamingContext context) : base(info, context)
21+
{
22+
}
1723
}
1824
}

src/Api/Storage/FileStorageInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public string FilePath
5151
if (string.IsNullOrWhiteSpace(_filePath))
5252
{
5353
_filePath = GenerateStoragePath();
54-
};
54+
}
5555
return _filePath;
5656
}
5757
set => _filePath = value;

src/CLI/Commands/ConfigurationException.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache License 2.0
33

44
using System;
5+
using System.Runtime.Serialization;
56

67
namespace Monai.Deploy.InformaticsGateway.CLI
78
{
@@ -11,5 +12,9 @@ public class ConfigurationException : Exception
1112
public ConfigurationException(string message) : base(message)
1213
{
1314
}
15+
16+
protected ConfigurationException(SerializationInfo info, StreamingContext context) : base(info, context)
17+
{
18+
}
1419
}
1520
}

src/CLI/ExitCodes.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ public static class ExitCodes
2424
public const int SourceAe_ErrorDelete = 401;
2525
public const int SourceAe_ErrorCreate = 402;
2626

27-
public static int Restart_Cancelled = 500;
28-
public static int Restart_Error = 501;
27+
public const int Restart_Cancelled = 500;
28+
public const int Restart_Error = 501;
2929

30-
public static int Start_Cancelled = 600;
31-
public static int Start_Error = 601;
32-
public static int Start_Error_ApplicationNotFound = 602;
33-
public static int Start_Error_ApplicationAlreadyRunning = 603;
30+
public const int Start_Cancelled = 600;
31+
public const int Start_Error = 601;
32+
public const int Start_Error_ApplicationNotFound = 602;
33+
public const int Start_Error_ApplicationAlreadyRunning = 603;
3434

35-
public static int Stop_Cancelled = 700;
36-
public static int Stop_Error = 701;
35+
public const int Stop_Cancelled = 700;
36+
public const int Stop_Error = 701;
3737

38-
public static int Status_Error = 800;
38+
public const int Status_Error = 800;
3939
}
4040
}

src/CLI/Options/Common.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Monai.Deploy.InformaticsGateway.CLI
88
{
9-
public class Common
9+
public static class Common
1010
{
1111
public static readonly string HomeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
1212
public static readonly string MigDirectory = Path.Combine(HomeDir, ".mig");

src/CLI/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
namespace Monai.Deploy.InformaticsGateway.CLI
2020
{
21-
internal partial class Program
21+
internal static class Program
2222
{
2323
private static async Task<int> Main(string[] args)
2424
{

src/CLI/Services/DockerRunner.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ public async Task<ImageVersion> GetLatestApplicationVersion(string version, Canc
6868
public async Task<IList<ImageVersion>> GetApplicationVersions(CancellationToken cancellationToken = default)
6969
=> await GetApplicationVersions(_configurationService.Configurations.DockerImagePrefix, cancellationToken).ConfigureAwait(false);
7070

71-
public async Task<IList<ImageVersion>> GetApplicationVersions(string label, CancellationToken cancellationToken = default)
71+
public async Task<IList<ImageVersion>> GetApplicationVersions(string version, CancellationToken cancellationToken = default)
7272
{
73-
Guard.Against.NullOrWhiteSpace(label, nameof(label));
73+
Guard.Against.NullOrWhiteSpace(version, nameof(version));
7474

7575
_logger.Log(LogLevel.Debug, "Connecting to Docker...");
7676
var parameters = new ImagesListParameters
@@ -79,7 +79,7 @@ public async Task<IList<ImageVersion>> GetApplicationVersions(string label, Canc
7979
{
8080
["reference"] = new Dictionary<string, bool>
8181
{
82-
[label] = true
82+
[version] = true
8383
}
8484
}
8585
};

src/Client.Common/UriExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ public static Uri EnsureUriEndsWithSlash(this Uri input)
1717

1818
if (!string.IsNullOrWhiteSpace(str) && !str.EndsWith("/"))
1919
{
20+
#pragma warning disable S1075 // URIs should not be hardcoded
2021
return new Uri(str + '/');
22+
#pragma warning restore S1075 // URIs should not be hardcoded
2123
}
2224

2325
return input;

src/Client/InformaticsGatewayClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public void ConfigureServiceUris(Uri uriRoot)
5757
Guard.Against.MalformUri(uriRoot, nameof(uriRoot));
5858

5959
_httpClient.BaseAddress = uriRoot;
60+
_logger.Log(LogLevel.Debug, $"Service URI set to {uriRoot}");
6061
}
6162

6263
/// <inheritdoc/>

src/Client/Services/AeTitle{T}Service.cs

Lines changed: 21 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -42,66 +42,38 @@ public async Task<T> Create(T item, CancellationToken cancellationToken)
4242
Guard.Against.Null(item, nameof(item));
4343

4444
Logger.Log(LogLevel.Debug, $"Sending request to {Route}");
45-
try
46-
{
47-
var response = await HttpClient.PostAsync<T>(Route, item, new JsonMediaTypeFormatter(), cancellationToken);
48-
await response.EnsureSuccessStatusCodeWithProblemDetails(Logger);
49-
return await response.Content.ReadAsAsync<T>(cancellationToken);
50-
}
51-
catch
52-
{
53-
throw;
54-
}
45+
var response = await HttpClient.PostAsync<T>(Route, item, new JsonMediaTypeFormatter(), cancellationToken);
46+
await response.EnsureSuccessStatusCodeWithProblemDetails(Logger);
47+
return await response.Content.ReadAsAsync<T>(cancellationToken);
5548
}
5649

57-
public async Task<T> Delete(string name, CancellationToken cancellationToken)
50+
public async Task<T> Delete(string aeTitle, CancellationToken cancellationToken)
5851
{
59-
name = Uri.EscapeUriString(name);
60-
Guard.Against.NullOrWhiteSpace(name, nameof(name));
61-
Logger.Log(LogLevel.Debug, $"Sending request to {Route}/{name}");
62-
try
63-
{
64-
var response = await HttpClient.DeleteAsync($"{Route}/{name}", cancellationToken);
65-
await response.EnsureSuccessStatusCodeWithProblemDetails(Logger);
66-
return await response.Content.ReadAsAsync<T>(cancellationToken);
67-
}
68-
catch
69-
{
70-
throw;
71-
}
52+
aeTitle = Uri.EscapeUriString(aeTitle);
53+
Guard.Against.NullOrWhiteSpace(aeTitle, nameof(aeTitle));
54+
Logger.Log(LogLevel.Debug, $"Sending request to {Route}/{aeTitle}");
55+
var response = await HttpClient.DeleteAsync($"{Route}/{aeTitle}", cancellationToken);
56+
await response.EnsureSuccessStatusCodeWithProblemDetails(Logger);
57+
return await response.Content.ReadAsAsync<T>(cancellationToken);
7258
}
7359

74-
public async Task<T> Get(string name, CancellationToken cancellationToken)
60+
public async Task<T> Get(string aeTitle, CancellationToken cancellationToken)
7561
{
76-
name = Uri.EscapeUriString(name);
77-
Guard.Against.NullOrWhiteSpace(name, nameof(name));
78-
Logger.Log(LogLevel.Debug, $"Sending request to {Route}/{name}");
79-
try
80-
{
81-
var response = await HttpClient.GetAsync($"{Route}/{name}", cancellationToken);
82-
await response.EnsureSuccessStatusCodeWithProblemDetails(Logger);
83-
return await response.Content.ReadAsAsync<T>(cancellationToken);
84-
}
85-
catch
86-
{
87-
throw;
88-
}
62+
aeTitle = Uri.EscapeUriString(aeTitle);
63+
Guard.Against.NullOrWhiteSpace(aeTitle, nameof(aeTitle));
64+
Logger.Log(LogLevel.Debug, $"Sending request to {Route}/{aeTitle}");
65+
var response = await HttpClient.GetAsync($"{Route}/{aeTitle}", cancellationToken);
66+
await response.EnsureSuccessStatusCodeWithProblemDetails(Logger);
67+
return await response.Content.ReadAsAsync<T>(cancellationToken);
8968
}
9069

9170
public async Task<IReadOnlyList<T>> List(CancellationToken cancellationToken)
9271
{
9372
Logger.Log(LogLevel.Debug, $"Sending request to {Route}");
94-
try
95-
{
96-
var response = await HttpClient.GetAsync(Route, cancellationToken);
97-
await response.EnsureSuccessStatusCodeWithProblemDetails(Logger);
98-
var list = await response.Content.ReadAsAsync<IEnumerable<T>>(cancellationToken);
99-
return list.ToList().AsReadOnly();
100-
}
101-
catch
102-
{
103-
throw;
104-
}
73+
var response = await HttpClient.GetAsync(Route, cancellationToken);
74+
await response.EnsureSuccessStatusCodeWithProblemDetails(Logger);
75+
var list = await response.Content.ReadAsAsync<IEnumerable<T>>(cancellationToken);
76+
return list.ToList().AsReadOnly();
10577
}
10678
}
10779
}

src/Client/Services/HealthService.cs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,17 @@ public HealthService(HttpClient httpClient, ILogger logger = null)
3636
public async Task<HealthStatusResponse> Status(CancellationToken cancellationToken)
3737
{
3838
Logger.Log(LogLevel.Debug, $"Sending request to {Route}/status");
39-
try
40-
{
41-
var response = await HttpClient.GetAsync($"{Route}/status", cancellationToken);
42-
await response.EnsureSuccessStatusCodeWithProblemDetails(Logger);
43-
return await response.Content.ReadAsAsync<HealthStatusResponse>(cancellationToken);
44-
}
45-
catch
46-
{
47-
throw;
48-
}
39+
var response = await HttpClient.GetAsync($"{Route}/status", cancellationToken);
40+
await response.EnsureSuccessStatusCodeWithProblemDetails(Logger);
41+
return await response.Content.ReadAsAsync<HealthStatusResponse>(cancellationToken);
4942
}
5043

5144
private async Task<string> LiveReady(string uriPath, CancellationToken cancellationToken)
5245
{
5346
Logger.Log(LogLevel.Debug, $"Sending request to {Route}/{uriPath}");
54-
try
55-
{
56-
var response = await HttpClient.GetAsync($"{Route}/{uriPath}", cancellationToken);
57-
await response.EnsureSuccessStatusCodeWithProblemDetails(Logger);
58-
return await response.Content.ReadAsStringAsync();
59-
}
60-
catch
61-
{
62-
throw;
63-
}
47+
var response = await HttpClient.GetAsync($"{Route}/{uriPath}", cancellationToken);
48+
await response.EnsureSuccessStatusCodeWithProblemDetails(Logger);
49+
return await response.Content.ReadAsStringAsync();
6450
}
6551
}
6652
}

src/Client/Services/InferenceService.cs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,17 @@ public InferenceService(HttpClient httpClient, ILogger logger = null)
2929
public async Task<InferenceRequestResponse> New(InferenceRequest request, CancellationToken cancellationToken)
3030
{
3131
Logger.Log(LogLevel.Debug, $"Sending request to {Route}");
32-
try
33-
{
34-
var response = await HttpClient.PostAsync($"{Route}", request, new JsonMediaTypeFormatter(), cancellationToken);
35-
await response.EnsureSuccessStatusCodeWithProblemDetails(Logger);
36-
return await response.Content.ReadAsAsync<InferenceRequestResponse>(cancellationToken);
37-
}
38-
catch
39-
{
40-
throw;
41-
}
32+
var response = await HttpClient.PostAsync($"{Route}", request, new JsonMediaTypeFormatter(), cancellationToken);
33+
await response.EnsureSuccessStatusCodeWithProblemDetails(Logger);
34+
return await response.Content.ReadAsAsync<InferenceRequestResponse>(cancellationToken);
4235
}
4336

4437
public async Task<InferenceStatusResponse> Status(string transactionId, CancellationToken cancellationToken)
4538
{
4639
Logger.Log(LogLevel.Debug, $"Sending request to {Route}/status");
47-
try
48-
{
49-
var response = await HttpClient.GetAsync($"{Route}/{transactionId}", cancellationToken);
50-
await response.EnsureSuccessStatusCodeWithProblemDetails(Logger);
51-
return await response.Content.ReadAsAsync<InferenceStatusResponse>(cancellationToken);
52-
}
53-
catch
54-
{
55-
throw;
56-
}
40+
var response = await HttpClient.GetAsync($"{Route}/{transactionId}", cancellationToken);
41+
await response.EnsureSuccessStatusCodeWithProblemDetails(Logger);
42+
return await response.Content.ReadAsAsync<InferenceStatusResponse>(cancellationToken);
5743
}
5844
}
5945
}

src/Client/Test/HttpResponseMessageExtensionsTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public class HttpResponseMessageExtensionsTest
2222
public async Task SuccessStatusCode()
2323
{
2424
var message = new HttpResponseMessage(HttpStatusCode.OK);
25-
await message.EnsureSuccessStatusCodeWithProblemDetails();
25+
var exception = await Record.ExceptionAsync(async () => await message.EnsureSuccessStatusCodeWithProblemDetails()).ConfigureAwait(false);
26+
Assert.Null(exception);
2627
}
2728

2829
[Fact(DisplayName = "Returns problem details")]

src/Configuration/ConfigurationException.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
// SPDX-License-Identifier: Apache License 2.0
44

55
using System;
6+
using System.Runtime.Serialization;
67

78
namespace Monai.Deploy.InformaticsGateway.Configuration
89
{
910
/// <summary>
1011
/// Represnets an exception based upon invalid configuration.
1112
/// </summary>
13+
[Serializable]
1214
public class ConfigurationException : Exception
1315
{
1416
public ConfigurationException(string message) : base(message)
@@ -18,5 +20,9 @@ public ConfigurationException(string message) : base(message)
1820
public ConfigurationException(string message, Exception innerException) : base(message, innerException)
1921
{
2022
}
23+
24+
protected ConfigurationException(SerializationInfo info, StreamingContext context) : base(info, context)
25+
{
26+
}
2127
}
2228
}

src/Configuration/ScpConfiguration.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ public class ScpConfiguration
4545
[JsonProperty(PropertyName = "logDimseDatasets")]
4646
public bool LogDimseDatasets { get; set; } = DefaultLogDimseDatasets;
4747

48-
public IList<string> VerificationServiceTransferSyntaxes = new List<string> {
48+
private static readonly List<string> VerificationServiceTransferSyntaxList = new List<string> {
4949
"1.2.840.10008.1.2.1", //Explicit VR Little Endian
5050
"1.2.840.10008.1.2" , //Implicit VR Little Endian
5151
"1.2.840.10008.1.2.2", //Explicit VR Big Endian
5252
};
53+
public IReadOnlyList<string> VerificationServiceTransferSyntaxes { get => VerificationServiceTransferSyntaxList; }
5354

5455
public ScpConfiguration()
5556
{

0 commit comments

Comments
 (0)