From 065be0e79049aa22fdf1e67e6382fb866d759bc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0vihl=C3=ADk?= Date: Sat, 24 Feb 2024 16:02:42 +0100 Subject: [PATCH] net8 --- .github/workflows/integrate.yml | 2 +- .github/workflows/release.yml | 2 +- jsConnect.sln | 6 ++-- src/jsConnect.Tests/jsConnect.Tests.csproj | 2 +- .../Controllers/AbstractControllerBase.cs | 15 +++------ .../Controllers/JsConnectController.cs | 10 ++---- src/jsConnect/Extensions.cs | 26 +++++----------- src/jsConnect/JsConnectException.cs | 31 ++++++++----------- .../Models/JsConnectResponseModel.cs | 2 +- src/jsConnect/jsConnect.csproj | 2 +- 10 files changed, 35 insertions(+), 63 deletions(-) diff --git a/.github/workflows/integrate.yml b/.github/workflows/integrate.yml index 6adc3f3..b6f2e79 100644 --- a/.github/workflows/integrate.yml +++ b/.github/workflows/integrate.yml @@ -16,7 +16,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: 7.0.x + dotnet-version: 8.0.x - name: Restore dependencies run: dotnet restore - name: Build diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 68ae857..f0c25ae 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,7 +14,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: 7.0.x + dotnet-version: 8.0.x - name: Extract version from tag id: get_version uses: battila7/get-version-action@v2 diff --git a/jsConnect.sln b/jsConnect.sln index 62c2bb9..7f50d18 100644 --- a/jsConnect.sln +++ b/jsConnect.sln @@ -1,14 +1,16 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29411.108 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34616.47 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0EB0E003-5911-4A1F-A4FE-27A046C69D1A}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{06DB3DBE-1BB3-4D9F-9FD9-3AD7E9F07967}" ProjectSection(SolutionItems) = preProject .gitignore = .gitignore + .github\workflows\integrate.yml = .github\workflows\integrate.yml README.md = README.md + .github\workflows\release.yml = .github\workflows\release.yml EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "jsConnect", "src\jsConnect\jsConnect.csproj", "{912C9673-A2BE-4841-80DE-4927B00D4AAB}" diff --git a/src/jsConnect.Tests/jsConnect.Tests.csproj b/src/jsConnect.Tests/jsConnect.Tests.csproj index 7262da3..76bb158 100644 --- a/src/jsConnect.Tests/jsConnect.Tests.csproj +++ b/src/jsConnect.Tests/jsConnect.Tests.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 diff --git a/src/jsConnect/Controllers/AbstractControllerBase.cs b/src/jsConnect/Controllers/AbstractControllerBase.cs index a4af8bc..68c7678 100644 --- a/src/jsConnect/Controllers/AbstractControllerBase.cs +++ b/src/jsConnect/Controllers/AbstractControllerBase.cs @@ -7,17 +7,10 @@ namespace jsConnect.Controllers /// /// Base controller containing default shared functionality. /// - public abstract class AbstractControllerBase : Controller + public abstract class AbstractControllerBase(IConfiguration configuration, ILogger logger, ILoggerFactory loggerFactory) : Controller { - protected IConfiguration Configuration { get; set; } - protected ILogger Logger { get; set; } - protected ILoggerFactory LoggerFactory { get; set; } - - protected AbstractControllerBase(IConfiguration configuration, ILogger logger, ILoggerFactory loggerFactory) - { - Configuration = configuration; - Logger = logger; - LoggerFactory = loggerFactory; - } + protected IConfiguration Configuration { get; set; } = configuration; + protected ILogger Logger { get; set; } = logger; + protected ILoggerFactory LoggerFactory { get; set; } = loggerFactory; } } diff --git a/src/jsConnect/Controllers/JsConnectController.cs b/src/jsConnect/Controllers/JsConnectController.cs index 0d8d258..921cebc 100644 --- a/src/jsConnect/Controllers/JsConnectController.cs +++ b/src/jsConnect/Controllers/JsConnectController.cs @@ -18,7 +18,7 @@ namespace jsConnect.Controllers /// Authentication endpoint implemented in accordance with http://docs.vanillaforums.com/help/sso/jsconnect/seamless/. /// [Route("[controller]")] - public class JsConnectController : AbstractControllerBase + public class JsConnectController(IConfiguration configuration, ILogger logger, ILoggerFactory loggerFactory, HashAlgorithm hashAlgorithm) : AbstractControllerBase(configuration, logger, loggerFactory) { #region "Configuration" @@ -61,13 +61,7 @@ public class JsConnectController : AbstractControllerBase #endregion - private HashAlgorithm HashAlgorithm { get; set; } - - - public JsConnectController(IConfiguration configuration, ILogger logger, ILoggerFactory loggerFactory, HashAlgorithm hashAlgorithm) : base(configuration, logger, loggerFactory) - { - HashAlgorithm = hashAlgorithm; - } + private HashAlgorithm HashAlgorithm { get; set; } = hashAlgorithm; /// /// Returns details of a currently signed-in user, if any. diff --git a/src/jsConnect/Extensions.cs b/src/jsConnect/Extensions.cs index 479a591..0ce2425 100644 --- a/src/jsConnect/Extensions.cs +++ b/src/jsConnect/Extensions.cs @@ -22,11 +22,8 @@ public static string ToJsonp(this object o, string callback) { throw new ArgumentNullException(nameof(callback), "Callback parameter must be initialized."); } - if (o == null) - { - throw new ArgumentNullException(nameof(o)); - } - var settings = new JsonSerializerSettings + ArgumentNullException.ThrowIfNull(o); + var settings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; @@ -50,11 +47,8 @@ public static int Timestamp(this DateTime dt) /// Array to convert. public static string ToHexString(this byte[] buff) { - if (buff == null) - { - throw new ArgumentNullException(nameof(buff)); - } - return buff.Aggregate("", (current, t) => current + t.ToString("x2")); + ArgumentNullException.ThrowIfNull(buff); + return buff.Aggregate("", (current, t) => current + t.ToString("x2")); } /// @@ -62,10 +56,7 @@ public static string ToHexString(this byte[] buff) /// public static string UrlEncode(this string s) { - if (s == null) - { - throw new ArgumentNullException(nameof(s)); - } + ArgumentNullException.ThrowIfNull(s); static string me(Match m) => m.ToString().ToUpper(); string result = WebUtility.UrlEncode(s); @@ -86,11 +77,8 @@ public static string UrlEncode(this string s) /// Returns value if the given key exists. Otherwise, returns a default value of . public static L GetValue(this Dictionary dic, T key) { - if (dic == null) - { - throw new ArgumentNullException(nameof(dic)); - } - if (dic.TryGetValue(key, out L value)) + ArgumentNullException.ThrowIfNull(dic); + if (dic.TryGetValue(key, out L value)) { return value; } diff --git a/src/jsConnect/JsConnectException.cs b/src/jsConnect/JsConnectException.cs index 875ce9e..8046a8c 100644 --- a/src/jsConnect/JsConnectException.cs +++ b/src/jsConnect/JsConnectException.cs @@ -2,10 +2,13 @@ namespace jsConnect { - /// - /// Exception object containing parameters expected by Vanilla Forums. - /// - public class JsConnectException : Exception + /// + /// Exception object containing parameters expected by Vanilla Forums. + /// + /// + /// Default constructor. + /// + public class JsConnectException(string error, string message) : Exception(message) { #region "Preconfigured error codes" @@ -19,19 +22,11 @@ public class JsConnectException : Exception /// public const string ERROR_INVALID_CLIENT = "invalid_client"; - #endregion + #endregion - /// - /// Short error code. - /// - public string Error { get; set; } - - /// - /// Default constructor. - /// - public JsConnectException(string error, string message) : base(message) - { - Error = error; - } - } + /// + /// Short error code. + /// + public string Error { get; set; } = error; + } } diff --git a/src/jsConnect/Models/JsConnectResponseModel.cs b/src/jsConnect/Models/JsConnectResponseModel.cs index e54a64f..4375890 100644 --- a/src/jsConnect/Models/JsConnectResponseModel.cs +++ b/src/jsConnect/Models/JsConnectResponseModel.cs @@ -48,7 +48,7 @@ public string Message #region "User Data" [JsonIgnore] - private readonly Dictionary UserData = new(); + private readonly Dictionary UserData = []; [JsonProperty("uniqueid")] public string UniqueId diff --git a/src/jsConnect/jsConnect.csproj b/src/jsConnect/jsConnect.csproj index 2ef210d..75ddcb3 100644 --- a/src/jsConnect/jsConnect.csproj +++ b/src/jsConnect/jsConnect.csproj @@ -3,7 +3,7 @@ Vanilla Forums' jsConnect for ASP.NET Core MVC Petr Svihlik;Jan Lenoch - net7.0 + net8.0 jsConnect jsConnectAspNetCoreMvc https://github.com/petrsvihlik/jsConnectAspNetCoreMvc/blob/master/LICENSE