Skip to content

Commit 11331ea

Browse files
committed
Merge branch 'maintenance/code-analysis' into develop
Applied code updates based on feedback from Code Analysis. These shouldn't change the functionality, but help maintain consistency and best practices across the application.
2 parents 4962a85 + 3e51b5c commit 11331ea

31 files changed

Lines changed: 206 additions & 53 deletions

OnTopic.Editor.AspNetCore.Host/SampleActivator.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ public SampleActivator(string connectionString, IWebHostEnvironment webHostEnvir
8888
/// <returns>A concrete instance of an <see cref="IController"/>.</returns>
8989
public object Create(ControllerContext context) {
9090

91+
/*------------------------------------------------------------------------------------------------------------------------
92+
| Validate parameters
93+
\-----------------------------------------------------------------------------------------------------------------------*/
94+
Contract.Requires(context, nameof(context));
95+
9196
/*------------------------------------------------------------------------------------------------------------------------
9297
| Determine controller type
9398
\-----------------------------------------------------------------------------------------------------------------------*/
@@ -111,6 +116,11 @@ public object Create(ControllerContext context) {
111116
/// <returns>A concrete instance of an <see cref="IController"/>.</returns>
112117
public object Create(ViewComponentContext context) {
113118

119+
/*------------------------------------------------------------------------------------------------------------------------
120+
| Validate parameters
121+
\-----------------------------------------------------------------------------------------------------------------------*/
122+
Contract.Requires(context, nameof(context));
123+
114124
/*------------------------------------------------------------------------------------------------------------------------
115125
| Determine view component type
116126
\-----------------------------------------------------------------------------------------------------------------------*/

OnTopic.Editor.AspNetCore/Components/ContentTypeListViewComponent.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using OnTopic.Editor.AspNetCore.Models;
1313
using OnTopic.Editor.Models;
1414
using OnTopic.Editor.Models.Metadata;
15+
using OnTopic.Internal.Diagnostics;
1516
using OnTopic.Repositories;
1617

1718
namespace OnTopic.Editor.AspNetCore.Components {
@@ -58,6 +59,11 @@ public IViewComponentResult Invoke(
5859
string onModalClose = null
5960
) {
6061

62+
/*------------------------------------------------------------------------------------------------------------------------
63+
| Validate parameters
64+
\-----------------------------------------------------------------------------------------------------------------------*/
65+
Contract.Requires(currentTopic, nameof(currentTopic));
66+
6167
/*------------------------------------------------------------------------------------------------------------------------
6268
| Establish view model
6369
\-----------------------------------------------------------------------------------------------------------------------*/

OnTopic.Editor.AspNetCore/Components/DateTimeViewComponent.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using OnTopic.Editor.Models;
88
using OnTopic.Editor.Models.Components.ViewModels;
99
using OnTopic.Editor.Models.Metadata;
10+
using OnTopic.Internal.Diagnostics;
1011

1112
namespace OnTopic.Editor.AspNetCore.Components {
1213

@@ -39,6 +40,12 @@ public IViewComponentResult Invoke(
3940
string htmlFieldPrefix
4041
) {
4142

43+
/*------------------------------------------------------------------------------------------------------------------------
44+
| Validate parameters
45+
\-----------------------------------------------------------------------------------------------------------------------*/
46+
Contract.Requires(currentTopic, nameof(currentTopic));
47+
Contract.Requires(attribute, nameof(attribute));
48+
4249
/*------------------------------------------------------------------------------------------------------------------------
4350
| Set HTML prefix
4451
\-----------------------------------------------------------------------------------------------------------------------*/

OnTopic.Editor.AspNetCore/Components/FileListViewComponent.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using OnTopic.Editor.AspNetCore.Models;
1313
using OnTopic.Editor.Models;
1414
using OnTopic.Editor.Models.Metadata;
15+
using OnTopic.Internal.Diagnostics;
1516

1617
#nullable enable
1718

@@ -52,6 +53,12 @@ public IViewComponentResult Invoke(
5253
string htmlFieldPrefix
5354
) {
5455

56+
/*------------------------------------------------------------------------------------------------------------------------
57+
| Validate parameters
58+
\-----------------------------------------------------------------------------------------------------------------------*/
59+
Contract.Requires(currentTopic, nameof(currentTopic));
60+
Contract.Requires(attribute, nameof(attribute));
61+
5562
/*------------------------------------------------------------------------------------------------------------------------
5663
| Set HTML prefix
5764
\-----------------------------------------------------------------------------------------------------------------------*/
@@ -73,7 +80,7 @@ string htmlFieldPrefix
7380
/*------------------------------------------------------------------------------------------------------------------------
7481
| Set model values
7582
\-----------------------------------------------------------------------------------------------------------------------*/
76-
model.Files = GetFiles(model.InheritedValue, attribute, model.AbsolutePath);
83+
model.Files.AddRange(GetFiles(model.InheritedValue, attribute, model.AbsolutePath));
7784
model.AbsolutePath = _webHostEnvironment.ContentRootPath + attribute.Path;
7885

7986
/*------------------------------------------------------------------------------------------------------------------------
@@ -95,6 +102,11 @@ public static List<SelectListItem> GetFiles(
95102
string absolutePath
96103
) {
97104

105+
/*------------------------------------------------------------------------------------------------------------------------
106+
| Validate parameters
107+
\-----------------------------------------------------------------------------------------------------------------------*/
108+
Contract.Requires(attribute, nameof(attribute));
109+
98110
/*------------------------------------------------------------------------------------------------------------------------
99111
| INSTANTIATE OBJECTS
100112
\-----------------------------------------------------------------------------------------------------------------------*/

OnTopic.Editor.AspNetCore/Components/FilePathViewComponent.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class FilePathViewComponent: ViewComponent {
2828
/*==========================================================================================================================
2929
| PRIVATE VARIABLES
3030
\-------------------------------------------------------------------------------------------------------------------------*/
31-
private Topic? _currentTopic = null;
31+
private Topic? _currentTopic;
3232

3333
/*==========================================================================================================================
3434
| CONSTRUCTOR
@@ -91,6 +91,12 @@ public IViewComponentResult Invoke(
9191
string htmlFieldPrefix
9292
) {
9393

94+
/*------------------------------------------------------------------------------------------------------------------------
95+
| Validate parameters
96+
\-----------------------------------------------------------------------------------------------------------------------*/
97+
Contract.Requires(currentTopic, nameof(currentTopic));
98+
Contract.Requires(attribute, nameof(attribute));
99+
94100
/*------------------------------------------------------------------------------------------------------------------------
95101
| Set HTML prefix
96102
\-----------------------------------------------------------------------------------------------------------------------*/
@@ -158,6 +164,11 @@ public string GetInheritedValue(string attributeKey, FilePathAttributeTopicViewM
158164
/// <returns>A constructed file path.</returns>
159165
public string GetPath(string attributeKey, FilePathAttributeTopicViewModel options) {
160166

167+
/*------------------------------------------------------------------------------------------------------------------------
168+
| Validate parameters
169+
\-----------------------------------------------------------------------------------------------------------------------*/
170+
Contract.Requires(options, nameof(options));
171+
161172
/*------------------------------------------------------------------------------------------------------------------------
162173
| Build configured file path string base on values and settings parameters passed to the method
163174
\-----------------------------------------------------------------------------------------------------------------------*/
@@ -192,7 +203,7 @@ public string GetPath(string attributeKey, FilePathAttributeTopicViewModel optio
192203
);
193204
}
194205
var startTopicWebPath = startTopic.GetWebPath().Replace("/Root/", "/");
195-
relativePath = endTopic?.GetWebPath().Substring(Math.Max(startTopicWebPath.Length-1,0));
206+
relativePath = endTopic?.GetWebPath()[Math.Max(startTopicWebPath.Length-1, 0)..];
196207
}
197208

198209
/*------------------------------------------------------------------------------------------------------------------------
@@ -215,7 +226,7 @@ public string GetPath(string attributeKey, FilePathAttributeTopicViewModel optio
215226
/*------------------------------------------------------------------------------------------------------------------------
216227
| Replace path slashes with backslashes if the resulting file path value uses a UNC or basic file path format
217228
\-----------------------------------------------------------------------------------------------------------------------*/
218-
if (filePath.IndexOf("\\", StringComparison.InvariantCulture) >= 0) {
229+
if (filePath.Contains("\\", StringComparison.InvariantCulture)) {
219230
filePath = filePath.Replace("/", "\\");
220231
}
221232

OnTopic.Editor.AspNetCore/Components/HtmlViewComponent.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.AspNetCore.Mvc;
77
using OnTopic.Editor.Models;
88
using OnTopic.Editor.Models.Metadata;
9+
using OnTopic.Internal.Diagnostics;
910

1011
namespace OnTopic.Editor.AspNetCore.Components {
1112

@@ -37,6 +38,12 @@ public IViewComponentResult Invoke(
3738
string htmlFieldPrefix
3839
) {
3940

41+
/*------------------------------------------------------------------------------------------------------------------------
42+
| Validate parameters
43+
\-----------------------------------------------------------------------------------------------------------------------*/
44+
Contract.Requires(currentTopic, nameof(currentTopic));
45+
Contract.Requires(attribute, nameof(attribute));
46+
4047
/*------------------------------------------------------------------------------------------------------------------------
4148
| Set HTML prefix
4249
\-----------------------------------------------------------------------------------------------------------------------*/

OnTopic.Editor.AspNetCore/Components/IncomingRelationshipViewComponent.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using OnTopic.Editor.Models;
99
using OnTopic.Editor.Models.Components.ViewModels;
1010
using OnTopic.Editor.Models.Metadata;
11+
using OnTopic.Internal.Diagnostics;
1112
using OnTopic.Repositories;
1213
using OnTopic.ViewModels;
1314

@@ -48,6 +49,12 @@ public IViewComponentResult Invoke(
4849
string htmlFieldPrefix
4950
) {
5051

52+
/*------------------------------------------------------------------------------------------------------------------------
53+
| Validate parameters
54+
\-----------------------------------------------------------------------------------------------------------------------*/
55+
Contract.Requires(currentTopic, nameof(currentTopic));
56+
Contract.Requires(attribute, nameof(attribute));
57+
5158
/*------------------------------------------------------------------------------------------------------------------------
5259
| Set HTML prefix
5360
\-----------------------------------------------------------------------------------------------------------------------*/

OnTopic.Editor.AspNetCore/Components/LastModifiedByViewComponent.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using OnTopic.Editor.Models;
88
using OnTopic.Editor.Models.Components.ViewModels;
99
using OnTopic.Editor.Models.Metadata;
10+
using OnTopic.Internal.Diagnostics;
1011

1112
namespace OnTopic.Editor.AspNetCore.Components {
1213

@@ -38,6 +39,12 @@ public IViewComponentResult Invoke(
3839
string htmlFieldPrefix
3940
) {
4041

42+
/*------------------------------------------------------------------------------------------------------------------------
43+
| Validate parameters
44+
\-----------------------------------------------------------------------------------------------------------------------*/
45+
Contract.Requires(currentTopic, nameof(currentTopic));
46+
Contract.Requires(attribute, nameof(attribute));
47+
4148
/*------------------------------------------------------------------------------------------------------------------------
4249
| Set HTML prefix
4350
\-----------------------------------------------------------------------------------------------------------------------*/

OnTopic.Editor.AspNetCore/Components/LastModifiedViewComponent.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
| Project Topics Library
55
\=============================================================================================================================*/
66
using System;
7+
using System.Globalization;
78
using Microsoft.AspNetCore.Mvc;
89
using OnTopic.Editor.Models;
910
using OnTopic.Editor.Models.Components.ViewModels;
1011
using OnTopic.Editor.Models.Metadata;
12+
using OnTopic.Internal.Diagnostics;
1113

1214
namespace OnTopic.Editor.AspNetCore.Components {
1315

@@ -40,6 +42,12 @@ public IViewComponentResult Invoke(
4042
string htmlFieldPrefix
4143
) {
4244

45+
/*------------------------------------------------------------------------------------------------------------------------
46+
| Validate parameters
47+
\-----------------------------------------------------------------------------------------------------------------------*/
48+
Contract.Requires(currentTopic, nameof(currentTopic));
49+
Contract.Requires(attribute, nameof(attribute));
50+
4351
/*------------------------------------------------------------------------------------------------------------------------
4452
| Set HTML prefix
4553
\-----------------------------------------------------------------------------------------------------------------------*/
@@ -54,12 +62,12 @@ string htmlFieldPrefix
5462
| Set model values
5563
\-----------------------------------------------------------------------------------------------------------------------*/
5664
if (currentTopic.LastModified != DateTime.MinValue) {
57-
model.CurrentValue = currentTopic.LastModified.ToString();
65+
model.CurrentValue = currentTopic.LastModified.ToString(CultureInfo.InvariantCulture);
5866
}
5967
else {
6068
model.CurrentValue = model.Value;
6169
}
62-
model.Value = DateTime.Now.ToString();
70+
model.Value = DateTime.Now.ToString(CultureInfo.InvariantCulture);
6371

6472
/*------------------------------------------------------------------------------------------------------------------------
6573
| Return view with view model

OnTopic.Editor.AspNetCore/Components/NestedTopicListViewComponent.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using OnTopic.Editor.Models;
1010
using OnTopic.Editor.Models.Components.ViewModels;
1111
using OnTopic.Editor.Models.Metadata;
12+
using OnTopic.Internal.Diagnostics;
1213
using OnTopic.Repositories;
1314

1415
namespace OnTopic.Editor.AspNetCore.Components {
@@ -48,6 +49,12 @@ public IViewComponentResult Invoke(
4849
string htmlFieldPrefix
4950
) {
5051

52+
/*------------------------------------------------------------------------------------------------------------------------
53+
| Validate parameters
54+
\-----------------------------------------------------------------------------------------------------------------------*/
55+
Contract.Requires(currentTopic, nameof(currentTopic));
56+
Contract.Requires(attribute, nameof(attribute));
57+
5158
/*------------------------------------------------------------------------------------------------------------------------
5259
| Set HTML prefix
5360
\-----------------------------------------------------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)