Skip to content

Commit

Permalink
Fix sonar issues and bug finalizing thread manager (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
k3ldar authored Jun 12, 2024
1 parent f61a330 commit c1e51d9
Show file tree
Hide file tree
Showing 31 changed files with 166 additions and 97 deletions.
9 changes: 9 additions & 0 deletions Database/PluginManager.SimpleDB/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Minor Code Smell", "S1905:Redundant casts should not be used", Justification = "Left in situ to make it abundantly obvious as byte size matters", Scope = "member", Target = "~M:SimpleDB.Internal.SimpleDBOperations`1.CreateTableHeaderRecords(System.String,SimpleDB.PageSize)")]
[assembly: SuppressMessage("Major Code Smell", "S3971:\"GC.SuppressFinalize\" should not be called", Justification = "Required at this point as part of functionality", Scope = "member", Target = "~M:SimpleDB.Internal.SimpleDBOperations`1.#ctor(SimpleDB.ISimpleDBManager,SimpleDB.IForeignKeyManager)")]
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ public bool SubmitTicket(in long userId, in int department, in int priority, in
int idDepartment = department;

ticket = new HelpdeskTicket(_tickets.Count + 1,
GetTicketPriorities().FirstOrDefault(p => p.Id == idPriority),
GetTicketDepartments().FirstOrDefault(d => d.Id == idDepartment),
GetTicketStatus().FirstOrDefault(s => s.Id == idStatus),
GetTicketPriorities().Find(p => p.Id == idPriority),
GetTicketDepartments().Find(d => d.Id == idDepartment),
GetTicketStatus().Find(s => s.Id == idStatus),
ticketId,
subject,
DateTime.Now,
Expand Down
8 changes: 8 additions & 0 deletions Demo/NetCorePluginDemoWebsite/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Critical Code Smell", "S2696:Instance members should not write to \"static\" fields", Justification = "<Pending>", Scope = "member", Target = "~M:AspNetCore.PluginManager.DemoWebsite.Classes.MockHelpdeskProvider.GetFeedback(System.Boolean@)~System.Collections.Generic.List{Middleware.Helpdesk.Feedback}")]
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</PropertyGroup>

<PropertyGroup>
<SharedVer>3.14.0</SharedVer>
<SharedVer>3.15.0</SharedVer>
<SharedWinVer>1.5.0</SharedWinVer>
</PropertyGroup>

Expand Down
2 changes: 2 additions & 0 deletions NetCorePluginManager/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
[assembly: SuppressMessage("Minor Code Smell", "S3267:Loops should be simplified with \"LINQ\" expressions", Justification = "<Pending>", Scope = "member", Target = "~M:AspNetCore.PluginManager.Classes.SystemAdmin.LoadedModulesMenu.Data~System.String")]
[assembly: SuppressMessage("Major Code Smell", "S125:Sections of code should not be commented out", Justification = "<Pending>")]
[assembly: SuppressMessage("Minor Code Smell", "S3458:Empty \"case\" clauses that fall through to the \"default\" should be omitted", Justification = "<Pending>", Scope = "member", Target = "~M:AspNetCore.PluginManager.Classes.Minify.MinificationEngine.MinifyData(System.Text.Encoding@,SharedPluginFeatures.MinificationFileType@,System.Byte[]@,System.Byte[]@)~System.Collections.Generic.List{SharedPluginFeatures.IMinifyResult}")]
[assembly: SuppressMessage("Minor Code Smell", "S6602:\"Find\" method should be used instead of the \"FirstOrDefault\" extension", Justification = "Not possible on arrays", Scope = "member", Target = "~M:AspNetCore.PluginManager.RouteDataServices.GetRouteFromClass(System.Type,Microsoft.AspNetCore.Mvc.Infrastructure.IActionDescriptorCollectionProvider)~System.String")]
[assembly: SuppressMessage("Minor Code Smell", "S6602:\"Find\" method should be used instead of the \"FirstOrDefault\" extension", Justification = "Not possible on arrays", Scope = "member", Target = "~M:AspNetCore.PluginManager.RouteDataServices.GetRouteFromMethod(System.Reflection.MethodInfo@,Microsoft.AspNetCore.Mvc.Infrastructure.IActionDescriptorCollectionProvider@)~System.String")]
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@

namespace ApiAuthorization.Plugin
{
/// <summary>
/// Settings which affect how ApiAuthorization is configured and used.
/// </summary>
public class ApiAuthorizationSettings
/// <summary>
/// Settings which affect how ApiAuthorization is configured and used.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Minor Code Smell", "S2094:Classes should not be empty", Justification = "Will be used to contain settings, kept at present")]
public class ApiAuthorizationSettings
{

}
Expand Down
10 changes: 10 additions & 0 deletions Plugins/BadEgg.Plugin/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Minor Code Smell", "S6602:\"Find\" method should be used instead of the \"FirstOrDefault\" extension", Justification = "Not possible on arrays", Scope = "member", Target = "~M:BadEgg.Plugin.BadEggMiddleware.LoadRouteData(Microsoft.AspNetCore.Mvc.Infrastructure.IActionDescriptorCollectionProvider,SharedPluginFeatures.IRouteDataService,PluginManager.Abstractions.IPluginTypesService)")]
[assembly: SuppressMessage("Minor Code Smell", "S1643:Strings should not be concatenated using '+' in a loop", Justification = "Not always more efficient to use string builder", Scope = "member", Target = "~M:BadEgg.Plugin.WebDefender.IpConnectionInfo.GetResults~System.String")]
[assembly: SuppressMessage("Minor Code Smell", "S1643:Strings should not be concatenated using '+' in a loop", Justification = "Not always more efficient to use string builder", Scope = "member", Target = "~M:BadEgg.Plugin.WebDefender.ValidateConnections.ValidateRequest(Microsoft.AspNetCore.Http.HttpRequest@,System.Boolean@,System.Int32@)~SharedPluginFeatures.Enums.ValidateRequestResult")]
16 changes: 9 additions & 7 deletions Plugins/Blog.Plugin/Models/Blog/BlogPostViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;

using SharedPluginFeatures;

Expand Down Expand Up @@ -181,22 +182,23 @@ public BlogPostViewModel(in BaseModelData baseModelData, in int id, in string ti
Tags = String.Join(' ', tags);
}

#endregion Constructors
#endregion Constructors

#region Properties
#region Properties

/// <summary>
/// Unique id representing the blog entry.
/// </summary>
/// <value>int</value>
/// <summary>
/// Unique id representing the blog entry.
/// </summary>
/// <value>int</value>
[JsonRequired]
public int Id { get; set; }

/// <summary>
/// Title of blog entry.
/// </summary>
/// <value>string</value>
[Required(ErrorMessage = nameof(Languages.LanguageStrings.PleaseEnterBlogTitle))]
public string Title { get; set; }
public string Title { get; set; }

/// <summary>
/// Brief description describing the blog entry.
Expand Down
8 changes: 8 additions & 0 deletions Plugins/Breadcrumb.Plugin/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Minor Code Smell", "S6602:\"Find\" method should be used instead of the \"FirstOrDefault\" extension", Justification = "<Pending>", Scope = "member", Target = "~M:Breadcrumb.Plugin.BreadcrumbMiddleware.LoadBreadcrumbData(Microsoft.AspNetCore.Mvc.Infrastructure.IActionDescriptorCollectionProvider@,SharedPluginFeatures.IRouteDataService@,PluginManager.Abstractions.IPluginTypesService@,Breadcrumb.Plugin.BreadcrumbSettings@)")]
3 changes: 2 additions & 1 deletion Plugins/Breadcrumb.Plugin/PluginInitialisation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public void Initialise(ILogger logger)

public void Finalise()
{
ThreadManager.Finalise();
if (ThreadManager.IsInitialized)
ThreadManager.Finalise();
}

public void ConfigureServices(IServiceCollection services)
Expand Down
3 changes: 2 additions & 1 deletion Plugins/ErrorManager.Plugin/PluginInitialisation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public void ConfigureServices(IServiceCollection services)

public void Finalise()
{
ThreadManager.Finalise();
if (ThreadManager.IsInitialized)
ThreadManager.Finalise();
}

public ushort GetVersion()
Expand Down
3 changes: 2 additions & 1 deletion Plugins/GeoIpPlugin/PluginInitialisation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public void Initialise(ILogger logger)

public void Finalise()
{
ThreadManager.Finalise();
if (ThreadManager.IsInitialized)
ThreadManager.Finalise();
}

public void ConfigureServices(IServiceCollection services)
Expand Down
3 changes: 2 additions & 1 deletion Plugins/ImageManager.Plugin/PluginInitialisation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public void ConfigureServices(IServiceCollection services)

public void Finalise()
{
ThreadManager.Finalise();
if (ThreadManager.IsInitialized)
ThreadManager.Finalise();
}

public ushort GetVersion()
Expand Down
3 changes: 2 additions & 1 deletion Plugins/LocalizationPlugin/PluginInitialisation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public void Initialise(ILogger logger)

public void Finalise()
{
ThreadManager.Finalise();
if (ThreadManager.IsInitialized)
ThreadManager.Finalise();
}

public void ConfigureServices(IServiceCollection services)
Expand Down
4 changes: 2 additions & 2 deletions Plugins/Login.Plugin/Controllers/LoginController.Facebook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

using static Shared.Utilities;

#pragma warning disable CS1591
#pragma warning disable CS1591, S1075

namespace LoginPlugin.Controllers
{
Expand Down Expand Up @@ -231,4 +231,4 @@ private TokenUserDetails GetFacebookUserDetails(TokenResponse facebookPlusAccess
}
}

#pragma warning restore CS1591
#pragma warning restore CS1591, S1075
3 changes: 2 additions & 1 deletion Plugins/MemoryCachePlugin/PluginInitialisation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public void Initialise(ILogger logger)

public void Finalise()
{
ThreadManager.Finalise();
if (ThreadManager.IsInitialized)
ThreadManager.Finalise();
}

public void ConfigureServices(IServiceCollection services)
Expand Down
1 change: 1 addition & 0 deletions Plugins/SystemAdmin.Plugin/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
[assembly: SuppressMessage("Critical Code Smell", "S1215:\"GC.Collect\" should not be called", Justification = "Required at this point, should not be removed", Scope = "member", Target = "~M:SystemAdmin.Plugin.Classes.GCAnalysis.Run(System.Object)~System.Boolean")]
[assembly: SuppressMessage("Major Code Smell", "S6561:Avoid using \"DateTime.Now\" for benchmarking or timing operations", Justification = "Required for this context", Scope = "member", Target = "~M:SystemAdmin.Plugin.Classes.MenuItems.DatabaseTimings.Data~System.String")]
[assembly: SuppressMessage("Major Code Smell", "S6561:Avoid using \"DateTime.Now\" for benchmarking or timing operations", Justification = "Required for this context", Scope = "member", Target = "~M:SystemAdmin.Plugin.Classes.MenuItems.AllTimings.Data~System.String")]
[assembly: SuppressMessage("Minor Code Smell", "S6602:\"Find\" method should be used instead of the \"FirstOrDefault\" extension", Justification = "Not possible on arrays", Scope = "member", Target = "~M:SystemAdmin.Plugin.Controllers.SystemAdminController.ValidateIncomingProperties(SystemAdmin.Plugin.Models.SettingsViewModel,SystemAdmin.Plugin.Classes.MenuItems.SettingsMenuItem,System.Collections.Generic.List{System.String})")]
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ namespace UserAccount.Plugin.Controllers

public partial class AccountController
{
#region Public Action Methods
private const string LocalAccountUri = "/Account/";

[HttpGet]
#region Public Action Methods

[HttpGet]
[LoggedOut]
[Breadcrumb(nameof(Languages.LanguageStrings.CreateAccount), nameof(AccountController), nameof(Index))]
public IActionResult CreateAccount(string returnUrl)
Expand Down Expand Up @@ -77,13 +79,20 @@ public IActionResult CreateAccount(CreateAccountViewModel model)
if (session != null)
session.Login(userId, $"{ValidateUserInput(model.FirstName, ValidationType.Name)} {ValidateUserInput(model.Surname, ValidationType.Name)}", ValidateUserInput(model.Email, ValidationType.Email));

if (String.IsNullOrEmpty(model.ReturnUrl))
return Redirect("/Account/");
else
return Redirect(model.ReturnUrl);
}

PrepareCreateAccountModel(ref model);
if (String.IsNullOrEmpty(model.ReturnUrl))
{
return Redirect(LocalAccountUri);
}
else
{
if (Url.IsLocalUrl(model.ReturnUrl))
return Redirect(model.ReturnUrl);
else
return Redirect(LocalAccountUri);
}
}

PrepareCreateAccountModel(ref model);

return View(model);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
using System;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;

using SharedPluginFeatures;

Expand Down Expand Up @@ -52,11 +53,12 @@ public EditDeliveryAddressViewModel(in BaseModelData baseModelData)

}

#endregion Constructors
#endregion Constructors

#region Properties
#region Properties

public long AddressId { get; set; }
[JsonRequired]
public long AddressId { get; set; }

public bool ShowName { get; set; }

Expand Down
8 changes: 5 additions & 3 deletions Plugins/UserAccount.Plugin/Models/InvoiceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Text.Json.Serialization;

using Middleware;
using Middleware.Accounts.Invoices;
Expand Down Expand Up @@ -77,11 +78,12 @@ public InvoiceViewModel(in BaseModelData baseModelData, Invoice invoice)
}
}

#endregion Constructors
#endregion Constructors

#region Properties
#region Properties

public long InvoiceId { get; private set; }
[JsonRequired]
public long InvoiceId { get; private set; }

public CultureInfo Culture { get; private set; }

Expand Down
8 changes: 5 additions & 3 deletions Plugins/UserAccount.Plugin/Models/OrderViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Text.Json.Serialization;

using Middleware;
using Middleware.Accounts.Orders;
Expand Down Expand Up @@ -77,11 +78,12 @@ public OrderViewModel(in BaseModelData baseModelData, Order order)
}
}

#endregion Constructors
#endregion Constructors

#region Properties
#region Properties

public long OrderId { get; private set; }
[JsonRequired]
public long OrderId { get; private set; }

public CultureInfo Culture { get; private set; }

Expand Down
8 changes: 5 additions & 3 deletions Plugins/UserAccount.Plugin/Models/ViewLicenceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
using System;
using System.Text.Json.Serialization;

using SharedPluginFeatures;

Expand Down Expand Up @@ -57,11 +58,12 @@ public ViewLicenceViewModel(in BaseModelData baseModelData,
Licence = licence ?? throw new ArgumentNullException(nameof(licence));
}

#endregion Constructors
#endregion Constructors

#region Properties
#region Properties

public long Id { get; set; }
[JsonRequired]
public long Id { get; set; }

public string Domain { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public UserSessionCore(HttpContext context, string sessionId)
IsMobileDevice = CheckIfMobileDevice(UserAgent);
IsBrowserMobile = false;// Request.Browser.IsMobileDevice;

MobileRedirect = IsMobileDevice | IsBrowserMobile;
MobileRedirect = IsMobileDevice || IsBrowserMobile;

MobileManufacturer = "";// Request.Browser.MobileDeviceManufacturer;
MobileModel = ""; // Request.Browser.MobileDeviceModel;
Expand Down
10 changes: 10 additions & 0 deletions Plugins/UserSessionMiddlewarePlugin/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Minor Code Smell", "S6602:\"Find\" method should be used instead of the \"FirstOrDefault\" extension", Justification = "<Pending>", Scope = "member", Target = "~M:UserSessionMiddleware.Plugin.SessionMiddleware.LoadLoggedInData(Microsoft.AspNetCore.Mvc.Infrastructure.IActionDescriptorCollectionProvider,SharedPluginFeatures.IRouteDataService,PluginManager.Abstractions.IPluginTypesService)")]
[assembly: SuppressMessage("Minor Code Smell", "S6602:\"Find\" method should be used instead of the \"FirstOrDefault\" extension", Justification = "<Pending>", Scope = "member", Target = "~M:UserSessionMiddleware.Plugin.SessionMiddleware.LoadLoggedOutData(Microsoft.AspNetCore.Mvc.Infrastructure.IActionDescriptorCollectionProvider,SharedPluginFeatures.IRouteDataService,PluginManager.Abstractions.IPluginTypesService)")]
[assembly: SuppressMessage("Minor Code Smell", "S6602:\"Find\" method should be used instead of the \"FirstOrDefault\" extension", Justification = "<Pending>", Scope = "member", Target = "~M:UserSessionMiddleware.Plugin.SessionMiddleware.LoadLoggedInOutData(Microsoft.AspNetCore.Mvc.Infrastructure.IActionDescriptorCollectionProvider,SharedPluginFeatures.IRouteDataService,PluginManager.Abstractions.IPluginTypesService)")]
6 changes: 2 additions & 4 deletions Plugins/UserSessionMiddlewarePlugin/PluginInitialisation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ public sealed class PluginInitialisation : IPlugin, IInitialiseEvents

internal static ILogger GetLogger { get; private set; }

internal static string[] ValidCultures { get; private set; }


#endregion Internal Static Properties

#region IPlugin Methods
Expand All @@ -77,7 +74,8 @@ public void Initialise(ILogger logger)
/// </summary>
public void Finalise()
{
ThreadManager.Finalise();
if (ThreadManager.IsInitialized)
ThreadManager.Finalise();
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion Plugins/WebSmokeTest.Plugin/PluginInitialisation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public void Initialise(ILogger logger)

public void Finalise()
{
ThreadManager.Finalise();
if (ThreadManager.IsInitialized)
ThreadManager.Finalise();
}

public void ConfigureServices(IServiceCollection services)
Expand Down
Loading

0 comments on commit c1e51d9

Please sign in to comment.