Skip to content

Commit e821a17

Browse files
committed
gh-61 address errors, warnings and most messages reported by .net analyzers
Signed-off-by: Victor Chang <[email protected]>
1 parent 2903d71 commit e821a17

File tree

68 files changed

+848
-784
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+848
-784
lines changed

src/Api/IsExternalinit.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
// See the License for the specific language governing permissions and
1010
// limitations under the License.
1111

12+
using System.ComponentModel;
1213
namespace System.Runtime.CompilerServices
1314
{
14-
using System.ComponentModel;
1515

1616
/// <summary>
1717
/// Reserved to be used by the compiler for tracking metadata.

src/Api/Storage/Payload.cs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,10 @@ public enum PayloadState
3838
}
3939

4040
public const int MAX_RETRY = 3;
41-
42-
private readonly Guid _id;
4341
private readonly Stopwatch _lastReceived;
44-
private int _fileCount;
42+
private bool _disposedValue;
4543

46-
public Guid Id => _id;
44+
public Guid Id { get; }
4745

4846
public uint Timeout { get; init; }
4947

@@ -59,7 +57,7 @@ public enum PayloadState
5957

6058
public IList<FileStorageInfo> Files { get; }
6159

62-
public int Count { get => _fileCount; }
60+
public int Count { get; private set; }
6361

6462
public IEnumerable<string> Workflows
6563
{
@@ -77,9 +75,9 @@ public Payload(string key, string correlationId, uint timeout)
7775
{
7876
Guard.Against.NullOrWhiteSpace(key, nameof(key));
7977

80-
_id = Guid.NewGuid();
78+
Id = Guid.NewGuid();
8179
_lastReceived = new Stopwatch();
82-
_fileCount = 0;
80+
Count = 0;
8381
Key = key;
8482
CorrelationId = correlationId;
8583
Timeout = timeout;
@@ -96,7 +94,7 @@ public void Add(FileStorageInfo value)
9694
Files.Add(value);
9795
_lastReceived.Reset();
9896
_lastReceived.Start();
99-
_fileCount = Files.Count;
97+
Count = Files.Count;
10098

10199
if (Files.Count == 1)
102100
{
@@ -119,10 +117,25 @@ public void ResetRetry()
119117
RetryCount = 0;
120118
}
121119

120+
protected virtual void Dispose(bool disposing)
121+
{
122+
if (!_disposedValue)
123+
{
124+
if (disposing)
125+
{
126+
_lastReceived.Stop();
127+
Files.Clear();
128+
}
129+
130+
_disposedValue = true;
131+
}
132+
}
133+
122134
public void Dispose()
123135
{
124-
_lastReceived.Stop();
125-
Files.Clear();
136+
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
137+
Dispose(disposing: true);
138+
GC.SuppressFinalize(this);
126139
}
127140
}
128141
}

src/Api/Test/InferenceRequestTest.cs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ public void Algorithm_ShallReturnAlgorithm()
5858
public void IsValid_ShallReturnAllErrors()
5959
{
6060
var request = new InferenceRequest();
61-
Assert.False(request.IsValid(out string _));
61+
Assert.False(request.IsValid(out var _));
6262

6363
request.InputResources.Add(new RequestInputDataResource { Interface = InputInterfaceType.Algorithm });
64-
Assert.False(request.IsValid(out string _));
64+
Assert.False(request.IsValid(out var _));
6565
}
6666

6767
[Fact(DisplayName = "IsValid shall return false if no studies were defined")]
@@ -90,7 +90,7 @@ public void IsValid_ShallReturnFalseWithEmptyStudy()
9090
Type = InferenceRequestType.DicomUid
9191
}
9292
};
93-
Assert.False(request.IsValid(out string _));
93+
Assert.False(request.IsValid(out var _));
9494
}
9595

9696
[Fact(DisplayName = "IsValid shall return false if study contains no UID")]
@@ -125,7 +125,7 @@ public void IsValid_ShallReturnFalseWithEmptyStudyInstanceUid()
125125
}
126126
}
127127
};
128-
Assert.False(request.IsValid(out string _));
128+
Assert.False(request.IsValid(out var _));
129129
}
130130

131131
[Fact(DisplayName = "IsValid shall return false if series contains no UID")]
@@ -167,7 +167,7 @@ public void IsValid_ShallReturnFalseWithEmptySeriesInstanceUid()
167167
}
168168
}
169169
};
170-
Assert.False(request.IsValid(out string _));
170+
Assert.False(request.IsValid(out var _));
171171
}
172172

173173
[Fact(DisplayName = "IsValid shall return false if instance contains no instance")]
@@ -216,7 +216,7 @@ public void IsValid_ShallReturnFalseWithEmptySopInstanceUid()
216216
}
217217
}
218218
};
219-
Assert.False(request.IsValid(out string _));
219+
Assert.False(request.IsValid(out var _));
220220
}
221221

222222
[Fact(DisplayName = "IsValid shall return false if missing patient ID")]
@@ -245,7 +245,7 @@ public void IsValid_ShallReturnFalseWithoutPatientId()
245245
Type = InferenceRequestType.DicomPatientId
246246
}
247247
};
248-
Assert.False(request.IsValid(out string _));
248+
Assert.False(request.IsValid(out var _));
249249
}
250250

251251
[Fact(DisplayName = "IsValid shall return false if no accession number were defined")]
@@ -274,7 +274,7 @@ public void IsValid_ShallReturnFalseWithoutAccessNumbers()
274274
Type = InferenceRequestType.AccessionNumber
275275
}
276276
};
277-
Assert.False(request.IsValid(out string _));
277+
Assert.False(request.IsValid(out var _));
278278
}
279279

280280
[Fact(DisplayName = "IsValid shall return false for unknown request type")]
@@ -300,7 +300,7 @@ public void IsValid_ShallReturnFalseForUnknownRequestType()
300300
{
301301
Details = new InferenceRequestDetails()
302302
};
303-
Assert.False(request.IsValid(out string _));
303+
Assert.False(request.IsValid(out var _));
304304
}
305305

306306
[Fact(DisplayName = "IsValid shall return false without a valid credential")]
@@ -325,7 +325,7 @@ public void IsValid_ShallReturnFalseWithoutAValidCredential()
325325
{
326326
Details = new InferenceRequestDetails()
327327
};
328-
Assert.False(request.IsValid(out string _));
328+
Assert.False(request.IsValid(out var _));
329329
}
330330

331331
[Fact(DisplayName = "IsValid shall return false with invalid uri")]
@@ -361,15 +361,15 @@ public void IsValid_ShallReturnFalseWithInvalidUri()
361361
}
362362
}
363363
};
364-
Assert.False(request.IsValid(out string _));
364+
Assert.False(request.IsValid(out var _));
365365
}
366366

367367
[Fact(DisplayName = "IsValid shall return false with missing TransactionId")]
368368
public void IsValid_ShallReturnFalseWithEmptyTransactionId()
369369
{
370370
var request = MockGoodRequest();
371371
request.TransactionId = "";
372-
Assert.False(request.IsValid(out string _));
372+
Assert.False(request.IsValid(out var _));
373373
}
374374

375375
[Fact(DisplayName = "IsValid shall return false with no resource defined for FHIR input")]
@@ -381,7 +381,7 @@ public void IsValid_ShallReturnFalsWithNoResourceInFhirInput()
381381
Type = InferenceRequestType.FhireResource
382382
};
383383

384-
Assert.False(request.IsValid(out string _));
384+
Assert.False(request.IsValid(out var _));
385385
}
386386

387387
[Fact(DisplayName = "IsValid shall return false with no resource type for a FHIR resource")]
@@ -397,7 +397,7 @@ public void IsValid_ShallReturnFalsWithNoResourceTypeForFhirResource()
397397
}
398398
};
399399

400-
Assert.False(request.IsValid(out string _));
400+
Assert.False(request.IsValid(out var _));
401401
}
402402

403403
[Fact(DisplayName = "IsValid shall return false with malformed input FHIR URI")]
@@ -416,7 +416,7 @@ public void IsValid_ShallReturnFalsWithBadUriInFhirInputUri()
416416
}
417417
});
418418

419-
Assert.False(request.IsValid(out string _));
419+
Assert.False(request.IsValid(out var _));
420420
}
421421

422422
[Fact(DisplayName = "IsValid shall return false with malformed output FHIR URI")]
@@ -435,20 +435,22 @@ public void IsValid_ShallReturnFalsWithBadUriInFhirOutputUri()
435435
}
436436
});
437437

438-
Assert.False(request.IsValid(out string _));
438+
Assert.False(request.IsValid(out var _));
439439
}
440440

441441
[Fact(DisplayName = "IsValid shall return true with valid request")]
442442
public void IsValid_ShallReturnTrue()
443443
{
444444
var request = MockGoodRequest();
445-
Assert.True(request.IsValid(out string _));
445+
Assert.True(request.IsValid(out var _));
446446
}
447447

448-
private InferenceRequest MockGoodRequest()
448+
private static InferenceRequest MockGoodRequest()
449449
{
450-
var request = new InferenceRequest();
451-
request.TransactionId = Guid.NewGuid().ToString();
450+
var request = new InferenceRequest
451+
{
452+
TransactionId = Guid.NewGuid().ToString()
453+
};
452454
request.InputResources.Add(new RequestInputDataResource
453455
{
454456
Interface = InputInterfaceType.Algorithm,

src/CLI/Commands/AetCommand.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class AetCommand : CommandBase
3333
{
3434
public AetCommand() : base("aet", "Configure SCP Application Entities")
3535
{
36-
this.AddAlias("aetitle");
36+
AddAlias("aetitle");
3737

3838
SetupAddAetCommand();
3939
SetupRemoveAetCommand();
@@ -44,7 +44,7 @@ private void SetupListAetCommand()
4444
{
4545
var listCommand = new Command("ls", "List all SCP Application Entities");
4646
listCommand.AddAlias("list");
47-
this.AddCommand(listCommand);
47+
AddCommand(listCommand);
4848

4949
listCommand.Handler = CommandHandler.Create<IHost, bool, CancellationToken>(ListAeTitlehandlerAsync);
5050
}
@@ -53,7 +53,7 @@ private void SetupRemoveAetCommand()
5353
{
5454
var removeCommand = new Command("rm", "Remove a SCP Application Entity");
5555
removeCommand.AddAlias("del");
56-
this.AddCommand(removeCommand);
56+
AddCommand(removeCommand);
5757

5858
var nameOption = new Option<string>(new string[] { "-n", "--name" }, "Name of the SCP Application Entity") { IsRequired = true };
5959
removeCommand.AddOption(nameOption);
@@ -64,7 +64,7 @@ private void SetupRemoveAetCommand()
6464
private void SetupAddAetCommand()
6565
{
6666
var addCommand = new Command("add", "Add a new SCP Application Entity");
67-
this.AddCommand(addCommand);
67+
AddCommand(addCommand);
6868

6969
var nameOption = new Option<string>(new string[] { "-n", "--name" }, "Name of the SCP Application Entity") { IsRequired = false };
7070
addCommand.AddOption(nameOption);
@@ -213,19 +213,19 @@ private async Task<int> AddAeTitlehandlerAsync(MonaiApplicationEntity entity, IH
213213
var result = await client.MonaiScpAeTitle.Create(entity, cancellationToken);
214214

215215
logger.Log(LogLevel.Information, "New MONAI Deploy SCP Application Entity created:");
216-
logger.Log(LogLevel.Information, "\tName: {0}", result.Name);
217-
logger.Log(LogLevel.Information, "\tAE Title: {0}", result.AeTitle);
218-
logger.Log(LogLevel.Information, "\tGrouping: {0}", result.Grouping);
219-
logger.Log(LogLevel.Information, "\tTimeout: {0}s", result.Timeout);
216+
logger.Log(LogLevel.Information, $"\tName: {result.Name}");
217+
logger.Log(LogLevel.Information, $"\tAE Title: {result.AeTitle}");
218+
logger.Log(LogLevel.Information, $"\tGrouping: {result.Grouping}");
219+
logger.Log(LogLevel.Information, $"\tTimeout: {result.Grouping}s");
220220

221221
if (result.Workflows.Any())
222222
{
223-
logger.Log(LogLevel.Information, "\tWorkflows:{0}", string.Join(',', result.Workflows));
223+
logger.Log(LogLevel.Information, $"\tWorkflows:{string.Join(',', result.Workflows)}");
224224
logger.Log(LogLevel.Warning, "Data received by this Application Entity will bypass Data Routing Service.");
225225
}
226226
if (result.IgnoredSopClasses.Any())
227227
{
228-
logger.Log(LogLevel.Information, "\tIgnored SOP Classes:{0}", string.Join(',', result.IgnoredSopClasses));
228+
logger.Log(LogLevel.Information, $"\tIgnored SOP Classes:{string.Join(',', result.IgnoredSopClasses)}");
229229
logger.Log(LogLevel.Warning, "Instances with matching SOP class UIDs are accepted but dropped.");
230230
}
231231
}

src/CLI/Commands/ConfigCommand.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public ConfigCommand() : base("config", "Configure the CLI endpoint")
3636
private void AddCommandRunner()
3737
{
3838
var endpointCommand = new Command("runner", $"Default container runner/orchestration engine to run {Strings.ApplicationName}.");
39-
this.Add(endpointCommand);
39+
Add(endpointCommand);
4040

4141
endpointCommand.AddArgument(new Argument<Runner>("runner"));
4242
endpointCommand.Handler = CommandHandler.Create<Runner, IHost, bool>((Runner runner, IHost host, bool verbose) =>
@@ -50,7 +50,7 @@ private void AddCommandRunner()
5050
private void AddCommandEndpoint()
5151
{
5252
var endpointCommand = new Command("endpoint", $"URL to the {Strings.ApplicationName} API. E.g. http://localhost:5000");
53-
this.Add(endpointCommand);
53+
Add(endpointCommand);
5454

5555
endpointCommand.AddArgument(new Argument<string>("uri"));
5656
endpointCommand.Handler = CommandHandler.Create<string, IHost, bool>((string uri, IHost host, bool verbose) =>
@@ -64,7 +64,7 @@ private void AddCommandEndpoint()
6464
private void SetupInitCommand()
6565
{
6666
var listCommand = new Command("init", $"Initialize with default configuration options");
67-
this.AddCommand(listCommand);
67+
AddCommand(listCommand);
6868

6969
listCommand.Handler = CommandHandler.Create<IHost, bool, bool, CancellationToken>(InitHandlerAsync);
7070
AddConfirmationOption(listCommand);
@@ -73,7 +73,7 @@ private void SetupInitCommand()
7373
private void SetupShowConfigCommand()
7474
{
7575
var showCommand = new Command("show", "Show configurations");
76-
this.AddCommand(showCommand);
76+
AddCommand(showCommand);
7777

7878
showCommand.Handler = CommandHandler.Create<IHost, bool, CancellationToken>(ShowConfigurationHandler);
7979
}

src/CLI/Commands/DestinationCommand.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public class DestinationCommand : CommandBase
3333
{
3434
public DestinationCommand() : base("dst", "Configure DICOM destinations")
3535
{
36-
this.AddAlias("dest");
37-
this.AddAlias("destination");
36+
AddAlias("dest");
37+
AddAlias("destination");
3838

3939
SetupAddDestinationCommand();
4040
SetupRemoveDestinationCommand();
@@ -45,7 +45,7 @@ private void SetupListDestinationCommand()
4545
{
4646
var listCommand = new Command("ls", "List all DICOM destinations");
4747
listCommand.AddAlias("list");
48-
this.AddCommand(listCommand);
48+
AddCommand(listCommand);
4949

5050
listCommand.Handler = CommandHandler.Create<DestinationApplicationEntity, IHost, bool, CancellationToken>(ListDestinationHandlerAsync);
5151
}
@@ -54,7 +54,7 @@ private void SetupRemoveDestinationCommand()
5454
{
5555
var removeCommand = new Command("rm", "Remove a DICOM destination");
5656
removeCommand.AddAlias("del");
57-
this.AddCommand(removeCommand);
57+
AddCommand(removeCommand);
5858

5959
var nameOption = new Option<string>(new string[] { "-n", "--name" }, "Name of the DICOM destination") { IsRequired = true };
6060
removeCommand.AddOption(nameOption);
@@ -65,7 +65,7 @@ private void SetupRemoveDestinationCommand()
6565
private void SetupAddDestinationCommand()
6666
{
6767
var addCommand = new Command("add", "Add a new DICOM destination");
68-
this.AddCommand(addCommand);
68+
AddCommand(addCommand);
6969

7070
var nameOption = new Option<string>(new string[] { "--name", "-n" }, "Name of the DICOM destination") { IsRequired = false };
7171
addCommand.AddOption(nameOption);
@@ -201,11 +201,11 @@ private async Task<int> AddDestinationHandlerAsync(DestinationApplicationEntity
201201
LogVerbose(verbose, host, $"Connecting to {Strings.ApplicationName} at {configService.Configurations.InformaticsGatewayServerEndpoint}...");
202202
var result = await client.DicomDestinations.Create(entity, cancellationToken);
203203

204-
logger.Log(LogLevel.Information, "New DICOM destination created:");
205-
logger.Log(LogLevel.Information, "\tName: {0}", result.Name);
206-
logger.Log(LogLevel.Information, "\tAE Title: {0}", result.AeTitle);
207-
logger.Log(LogLevel.Information, "\tHost/IP Address: {0}", result.HostIp);
208-
logger.Log(LogLevel.Information, "\tPort: {0}", result.Port);
204+
logger.Log(LogLevel.Information, $"New DICOM destination created:");
205+
logger.Log(LogLevel.Information, $"\tName: {result.Name}");
206+
logger.Log(LogLevel.Information, $"\tAE Title: {result.AeTitle}");
207+
logger.Log(LogLevel.Information, $"\tHost/IP Address: {result.HostIp}");
208+
logger.Log(LogLevel.Information, $"\tPort: {result.Port}");
209209
}
210210
catch (ConfigurationException ex)
211211
{

0 commit comments

Comments
 (0)