Skip to content

Commit 94b9842

Browse files
committed
Merge branch 'maintenance/code-analysis-cleanup' into develop
2 parents d8a2a56 + e88dee0 commit 94b9842

11 files changed

Lines changed: 22 additions & 26 deletions

File tree

OnTopic.Editor.AspNetCore.Host/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace OnTopicTest {
1616
/// The <see cref="Program"/> class—and it's <see cref="Program.Main(String[])"/> method—represent the entry point into the
1717
/// ASP.NET Core web application.
1818
/// </summary>
19-
public class Program {
19+
public static class Program {
2020

2121
/*==========================================================================================================================
2222
| METHOD: MAIN
@@ -37,7 +37,7 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
3737
.CreateDefaultBuilder(args)
3838
.ConfigureWebHostDefaults(webBuilder => {
3939
webBuilder.UseStartup<Startup>();
40-
});
40+
});
4141

4242
} //Class
4343
} //Namespace

OnTopic.Editor.AspNetCore.Host/SampleActivator.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public class SampleActivator : IControllerActivator, IViewComponentActivator {
3737
private readonly ITopicRepository _topicRepository;
3838
private readonly IWebHostEnvironment _webHostEnvironment;
3939
private readonly StandardEditorComposer _standardEditorComposer;
40-
private readonly Topic _rootTopic;
4140

4241
/*==========================================================================================================================
4342
| CONSTRUCTOR
@@ -70,7 +69,7 @@ public SampleActivator(string connectionString, IWebHostEnvironment webHostEnvir
7069
_topicRepository = cachedTopicRepository;
7170
_typeLookupService = new EditorViewModelLookupService();
7271
_topicMappingService = new TopicMappingService(_topicRepository, _typeLookupService);
73-
_rootTopic = _topicRepository.Load();
72+
_ = _topicRepository.Load();
7473

7574
/*------------------------------------------------------------------------------------------------------------------------
7675
| Establish standard editor composer
@@ -120,7 +119,7 @@ public object Create(ViewComponentContext context) {
120119
/*------------------------------------------------------------------------------------------------------------------------
121120
| Configure and return appropriate view component
122121
\-----------------------------------------------------------------------------------------------------------------------*/
123-
if (_standardEditorComposer.IsEditorComponent(type)) {
122+
if (StandardEditorComposer.IsEditorComponent(type)) {
124123
return _standardEditorComposer.ActivateEditorComponent(type, _topicRepository);
125124
}
126125

OnTopic.Editor.AspNetCore.Host/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void ConfigureServices(IServiceCollection services) {
110110
/// Provides configuration the application. This method is called by the runtime to bootstrap the application
111111
/// configuration, including the HTTP pipeline.
112112
/// </summary>
113-
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
113+
public static void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
114114

115115
/*------------------------------------------------------------------------------------------------------------------------
116116
| Configure: Error Pages

OnTopic.Editor.AspNetCore/Components/FileListViewComponent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ string htmlFieldPrefix
7373
/*------------------------------------------------------------------------------------------------------------------------
7474
| Set model values
7575
\-----------------------------------------------------------------------------------------------------------------------*/
76-
model.AbsolutePath = _webHostEnvironment.ContentRootPath + attribute.Path;
7776
model.Files = GetFiles(model.InheritedValue, attribute, model.AbsolutePath);
77+
model.AbsolutePath = _webHostEnvironment.ContentRootPath + attribute.Path;
7878

7979
/*------------------------------------------------------------------------------------------------------------------------
8080
| Return view with view model
@@ -89,7 +89,7 @@ string htmlFieldPrefix
8989
/// <summary>
9090
/// Retrieves a collection of files in a directory, given the provided <see cref="Path"/>.
9191
/// </summary>
92-
public List<SelectListItem> GetFiles(
92+
public static List<SelectListItem> GetFiles(
9393
string inheritedValue,
9494
FileListAttributeTopicViewModel attribute,
9595
string absolutePath

OnTopic.Editor.AspNetCore/Components/FilePathViewComponent.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public string GetInheritedValue(string attributeKey, FilePathAttributeTopicViewM
137137
inheritedValue = GetPath(attributeKey, attribute);
138138
}
139139
else if (attribute.InheritValue == true) {
140-
inheritedValue = CurrentTopic.Attributes.GetValue(attributeKey, true);
140+
inheritedValue = CurrentTopic?.Attributes.GetValue(attributeKey, true)?? "";
141141
}
142142

143143
return inheritedValue;
@@ -164,7 +164,7 @@ public string GetPath(string attributeKey, FilePathAttributeTopicViewModel optio
164164
var filePath = "";
165165
var relativePath = (string?)null;
166166
var startTopic = CurrentTopic;
167-
var endTopic = (options.IncludeCurrentTopic is null)? CurrentTopic: CurrentTopic.Parent?? CurrentTopic;
167+
var endTopic = (options.IncludeCurrentTopic is null)? CurrentTopic: CurrentTopic?.Parent?? CurrentTopic;
168168
var truncatePathAtTopic = options.BaseTopicPath?.Split(',').ToArray()?? Array.Empty<string>();
169169

170170
/*------------------------------------------------------------------------------------------------------------------------
@@ -186,13 +186,13 @@ public string GetPath(string attributeKey, FilePathAttributeTopicViewModel optio
186186
| Add topic keys (directory names) between the start topic and the end topic based on the topic's WebPath property
187187
\-----------------------------------------------------------------------------------------------------------------------*/
188188
if (startTopic != null) {
189-
if (startTopic.GetWebPath().Length > endTopic.GetWebPath().Length) {
189+
if (startTopic.GetWebPath().Length > endTopic?.GetWebPath().Length) {
190190
throw new InvalidOperationException(
191191
$"The path of {startTopic.GetWebPath()} should be shorter than the length of {endTopic.GetWebPath()}."
192192
);
193193
}
194194
var startTopicWebPath = startTopic.GetWebPath().Replace("/Root/", "/");
195-
relativePath = endTopic.GetWebPath().Substring(Math.Max(startTopicWebPath.Length-1,0));
195+
relativePath = endTopic?.GetWebPath().Substring(Math.Max(startTopicWebPath.Length-1,0));
196196
}
197197

198198
/*------------------------------------------------------------------------------------------------------------------------

OnTopic.Editor.AspNetCore/Components/LastModifiedByViewComponent.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ string htmlFieldPrefix
4646
/*------------------------------------------------------------------------------------------------------------------------
4747
| Establish view model
4848
\-----------------------------------------------------------------------------------------------------------------------*/
49-
var model = new LastModifiedByAttributeViewModel(currentTopic, attribute);
49+
var model = new LastModifiedByAttributeViewModel(currentTopic, attribute);
5050

5151
/*------------------------------------------------------------------------------------------------------------------------
5252
| Set model values
5353
\-----------------------------------------------------------------------------------------------------------------------*/
54-
model.Value = HttpContext.User.Identity.Name ?? "System";
55-
model.CurrentValue = currentTopic.Attributes["LastModifiedBy"]?? model.Value;
54+
model.CurrentValue = currentTopic.Attributes["LastModifiedBy"]?? model.Value;
55+
model.Value = HttpContext.User.Identity.Name?? "System";
5656

5757
/*------------------------------------------------------------------------------------------------------------------------
5858
| Return view with view model

OnTopic.Editor.AspNetCore/Components/LastModifiedViewComponent.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ string htmlFieldPrefix
5353
/*------------------------------------------------------------------------------------------------------------------------
5454
| Set model values
5555
\-----------------------------------------------------------------------------------------------------------------------*/
56-
model.Value = DateTime.Now.ToString();
5756
if (currentTopic.LastModified != null && currentTopic.LastModified != DateTime.MinValue) {
58-
model.CurrentValue = currentTopic.LastModified.ToString();
57+
model.CurrentValue = currentTopic.LastModified.ToString();
5958
}
6059
else {
61-
model.CurrentValue = model.Value;
60+
model.CurrentValue = model.Value;
6261
}
62+
model.Value = DateTime.Now.ToString();
6363

6464
/*------------------------------------------------------------------------------------------------------------------------
6565
| Return view with view model

OnTopic.Editor.AspNetCore/Components/TopicListViewComponent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public IViewComponentResult Invoke(
151151
>---------------------------------------------------------------------------------------------------------------------------
152152
| Retrieves a collection of topics with optional control call filter properties Scope, AttributeName and AttributeValue.
153153
\-------------------------------------------------------------------------------------------------------------------------*/
154-
public List<QueryResultTopicViewModel> GetTopics(
154+
public static List<QueryResultTopicViewModel> GetTopics(
155155
Topic topic = null,
156156
string attributeKey = null,
157157
string attributeValue = null,

OnTopic.Editor.AspNetCore/StandardEditorComposer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public StandardEditorComposer(ITopicRepository topicRepository, IWebHostEnvironm
6666
/// <summary>
6767
/// Determines whether a given type is capable of being activated by the <see cref="Activate"/> method.
6868
/// </summary>
69-
public bool IsEditorComponent(Type type) =>
69+
public static bool IsEditorComponent(Type type) =>
7070
typeof(StandardEditorComposer).Assembly.Equals(type.Assembly) &&
7171
typeof(ViewComponent).IsAssignableFrom(type);
7272

OnTopic.Editor.Models/AttributeViewModel{T}.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ public AttributeViewModel(
3131
currentTopic,
3232
attributeDescriptor
3333
) {
34-
AttributeDescriptor = attributeDescriptor;
34+
AttributeDescriptor = attributeDescriptor;
35+
Value = value;
36+
InheritedValue = inheritedValue;
3537
}
3638

3739
/*==========================================================================================================================

0 commit comments

Comments
 (0)