From a798a5272a9de91d556f386c1aea99a42cded078 Mon Sep 17 00:00:00 2001 From: Ziya Mollamahmut Date: Mon, 11 Nov 2019 11:40:32 +0300 Subject: [PATCH] support netcore 3.1 --- LazZiya.TagHelpers/AlertTagHelper.cs | 3 +- .../Alerts/AlertPageModelExtensions.cs | 4 +-- LazZiya.TagHelpers/LanguageNavTagHelper.cs | 13 ++++---- LazZiya.TagHelpers/LazZiya.TagHelpers.csproj | 25 ++++++++------- ...ionValidiationScriptsTagHelperComponent.cs | 2 +- LazZiya.TagHelpers/PagingTagHelper.cs | 31 ++++++++++--------- .../Utilities/GenericTempDataExtensions.cs | 6 ++-- .../files/LazZiya.TagHelpers.xml | 22 ++++++------- 8 files changed, 52 insertions(+), 54 deletions(-) diff --git a/LazZiya.TagHelpers/AlertTagHelper.cs b/LazZiya.TagHelpers/AlertTagHelper.cs index e2e60e5..49b2a54 100644 --- a/LazZiya.TagHelpers/AlertTagHelper.cs +++ b/LazZiya.TagHelpers/AlertTagHelper.cs @@ -28,10 +28,9 @@ public class AlertTagHelper : TagHelper public bool Dismissable { get; set; } = true; /// - /// ViewContext property is not required any more to be passed as parameter, you can remove it from the code. + /// ViewContext property is not required to be passed as parameter, it will be assigned automatically by the tag helper. /// View context is required to access TempData dictionary that contains the alerts coming from backend /// - [Obsolete("ViewContext property is not required any more to be passed as parameter, you can remove it from the code. ")] [ViewContext] public ViewContext ViewContext { get; set; } = null; diff --git a/LazZiya.TagHelpers/Alerts/AlertPageModelExtensions.cs b/LazZiya.TagHelpers/Alerts/AlertPageModelExtensions.cs index c44234d..759273f 100644 --- a/LazZiya.TagHelpers/Alerts/AlertPageModelExtensions.cs +++ b/LazZiya.TagHelpers/Alerts/AlertPageModelExtensions.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using LazZiya.TagHelpers.Utilities; using Microsoft.AspNetCore.Mvc.ViewFeatures; -#if NETCOREAPP3_0 +#if NETCOREAPP3_0 || NETCOREAPP3_1 using System.Text.Json; #else using Newtonsoft.Json; @@ -112,7 +112,7 @@ public static void Dark(this ITempDataDictionary tempData, string alertMessage, private static void AddAlert(ITempDataDictionary tempData, AlertStyle alertStyle, string message, string header, bool dismissable) { -#if NETCOREAPP3_0 +#if NETCOREAPP3_0 || NETCOREAPP3_1 var alerts = tempData.ContainsKey(Alert.TempDataKey) ? JsonSerializer.Deserialize>(tempData[Alert.TempDataKey].ToString()) : new List(); diff --git a/LazZiya.TagHelpers/LanguageNavTagHelper.cs b/LazZiya.TagHelpers/LanguageNavTagHelper.cs index 422e31c..a32ba77 100644 --- a/LazZiya.TagHelpers/LanguageNavTagHelper.cs +++ b/LazZiya.TagHelpers/LanguageNavTagHelper.cs @@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ViewFeatures; -#if NETCOREAPP2_2 || NETCOREAPP3_0 +#if NETCOREAPP2_2 || NETCOREAPP3_0 || NETCOREAPP3_1 using Microsoft.AspNetCore.Routing; #endif @@ -54,10 +54,9 @@ public class LanguageNavTagHelper : TagHelper public string HomePageName { get; set; } = "Index"; /// - /// ViewContext property is not required any more to be passed as parameter, you can remove it from the code. + /// ViewContext property is not required to be passed as parameter, it will be auto assigned by the tag helpoer. /// current view context to access RouteData.Values and Request.Query collection /// - [Obsolete("ViewContext property is not required any more to be passed as parameter, you can remove it from the code. ")] [ViewContext] public ViewContext ViewContext { get; set; } @@ -71,9 +70,9 @@ public class LanguageNavTagHelper : TagHelper /// private readonly IOptions _ops; private readonly ILogger _logger; - - -#if NETCOREAPP2_2 || NETCOREAPP3_0 + + +#if NETCOREAPP2_2 || NETCOREAPP3_0 || NETCOREAPP3_1 private readonly IOptions _mvcOps; private readonly LinkGenerator _lg; @@ -218,7 +217,7 @@ private List CreateNavDictionary() // DotNetCore 2.2 uses EndPointRouting, // so we need to use the link generator to generate url url = _lg.GetPathByRouteValues(httpContext: ViewContext.HttpContext, "", _routeData); -#elif NETCOREAPP3_0 +#elif NETCOREAPP3_0 || NETCOREAPP3_1 // DotNetCore 3.0 has optional value to use EndPointRouting // First check if EndPointRouting is enabled // Or use generic urlHelper to generate url diff --git a/LazZiya.TagHelpers/LazZiya.TagHelpers.csproj b/LazZiya.TagHelpers/LazZiya.TagHelpers.csproj index def72d6..4520162 100644 --- a/LazZiya.TagHelpers/LazZiya.TagHelpers.csproj +++ b/LazZiya.TagHelpers/LazZiya.TagHelpers.csproj @@ -1,7 +1,7 @@  - netcoreapp2.0;netcoreapp2.1;netcoreapp2.2;netcoreapp3.0 + netcoreapp2.0;netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1 files\icon.ico Ziya Mollamahmut Ziyad.info @@ -13,12 +13,12 @@ true asp.net, core, razor, mvc, taghelpers, taghelper,tag,helper,language,culture,dropdown, pagination, select, enum - - Fixed issue related to TempData in AlertTagHelper. See: https://github.com/LazZiya/TagHelpers/issues/5 - - removed support for .Net Core 1.x + - Support for dot net core 3.1.0 + - PagingTagHelper : QueryStringValue is Obsolete, replaced by auto assigned ViewContext - 3.0.2 - 3.0.2.0 - 3.0.2.0 + 3.1.0-preview1 + 3.1.0.0 + 3.1.0.0 false https://raw.githubusercontent.com/LazZiya/TagHelpers/master/LazZiya.TagHelpers/files/icon.png @@ -29,20 +29,21 @@ files\LazZiya.TagHelpers.xml - - - - + + + + + - - + + diff --git a/LazZiya.TagHelpers/LocalizationValidiationScriptsTagHelperComponent.cs b/LazZiya.TagHelpers/LocalizationValidiationScriptsTagHelperComponent.cs index ab1eea2..1011534 100644 --- a/LazZiya.TagHelpers/LocalizationValidiationScriptsTagHelperComponent.cs +++ b/LazZiya.TagHelpers/LocalizationValidiationScriptsTagHelperComponent.cs @@ -13,7 +13,7 @@ namespace LazZiya.TagHelpers public class LocalizationValidationScriptsTagHelperComponent : TagHelperComponent { -#if NETCOREAPP3_0 +#if NETCOREAPP3_0 || NETCOREAPP3_1 private readonly IWebHostEnvironment _hosting; /// diff --git a/LazZiya.TagHelpers/PagingTagHelper.cs b/LazZiya.TagHelpers/PagingTagHelper.cs index bf81b0e..fdef66a 100644 --- a/LazZiya.TagHelpers/PagingTagHelper.cs +++ b/LazZiya.TagHelpers/PagingTagHelper.cs @@ -6,6 +6,7 @@ * * *****************************************************/ using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Razor.TagHelpers; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; @@ -20,7 +21,15 @@ namespace LazZiya.TagHelpers public class PagingTagHelper : TagHelper { private IConfiguration Configuration { get; } - private ILogger _logger; + private readonly ILogger _logger; + + + /// + /// ViewContext property is not required to be passed as parameter, it will be assigned automatically by the tag helper. + /// View context is required to access TempData dictionary that contains the alerts coming from backend + /// + [ViewContext] + public ViewContext ViewContext { get; set; } = null; /// /// Creates a pagination control @@ -118,15 +127,9 @@ public PagingTagHelper(IConfiguration configuration, ILogger lo public string QueryStringKeyPageSize { get; set; } /// - /// Query string value starting from the ? including all next query string parameters - /// to consider for next pages links. - /// default: string.Empty - /// - /// - /// @(Request.QueryString.Value) - /// - /// + /// query-string-value is obsolte and will be removed in a future release. /// + [Obsolete("query-string-value is obsolte and will be removed in a future release")] public string QueryStringValue { get; set; } #endregion @@ -479,8 +482,6 @@ private void SetDefaults() QueryStringKeyPageSize = QueryStringKeyPageSize ?? Configuration[$"lazziya:pagingTagHelper:{_settingsJson}:query-string-key-page-size"] ?? "s"; - QueryStringValue = QueryStringValue ?? Configuration[$"lazziya:pagingTagHelper:{_settingsJson}:query-string-value"] ?? ""; - ShowFirstLast = ShowFirstLast == null ? bool.TryParse(Configuration[$"lazziya:pagingTagHelper:{_settingsJson}:show-first-last"], out bool _sfl) ? _sfl : false : ShowFirstLast; @@ -543,7 +544,6 @@ private void SetDefaults() $"{nameof(TotalPages)}: {TotalPages}, " + $"{nameof(QueryStringKeyPageNo)}: {QueryStringKeyPageNo}, " + $"{nameof(QueryStringKeyPageSize)}: {QueryStringKeyPageSize}, " + - $"{nameof(QueryStringValue)}: {QueryStringValue}" + $""); } @@ -596,7 +596,7 @@ private TagBuilder CreatePagingLink(int targetPageNo, string text, string textSr var aTag = new TagBuilder("a"); aTag.AddCssClass("page-link"); - aTag.Attributes.Add("href", CreateUrlTemplate(targetPageNo, PageSize, QueryStringValue)); + aTag.Attributes.Add("href", CreateUrlTemplate(targetPageNo, PageSize)); if (string.IsNullOrWhiteSpace(textSr)) { @@ -665,10 +665,11 @@ private TagBuilder CreatePageSizeControl() /// /// /// - /// /// - private string CreateUrlTemplate(int pageNo, int pageSize, string urlPath) + private string CreateUrlTemplate(int pageNo, int pageSize) { + var urlPath = ViewContext.HttpContext.Request.QueryString.Value; + _logger.LogDebug($"----> Page No '{pageNo}', Page Size '{pageSize}', URL Path '{urlPath}'"); string p = $"{QueryStringKeyPageNo}={pageNo}"; // CurrentPageNo query string parameter, default: p diff --git a/LazZiya.TagHelpers/Utilities/GenericTempDataExtensions.cs b/LazZiya.TagHelpers/Utilities/GenericTempDataExtensions.cs index 7ca0ec0..232272c 100644 --- a/LazZiya.TagHelpers/Utilities/GenericTempDataExtensions.cs +++ b/LazZiya.TagHelpers/Utilities/GenericTempDataExtensions.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.Text; -#if NETCOREAPP3_0 +#if NETCOREAPP3_0 || NETCOREAPP3_1 using System.Text.Json; #else using Newtonsoft.Json; @@ -25,7 +25,7 @@ public static class GenericTempDataExtensions /// public static void Put(this ITempDataDictionary tempData, string key, T value) where T : class { -#if NETCOREAPP3_0 +#if NETCOREAPP3_0 || NETCOREAPP3_1 tempData[key] = JsonSerializer.Serialize(value); #else tempData[key] = JsonConvert.SerializeObject(value); @@ -44,7 +44,7 @@ public static T Get(this ITempDataDictionary tempData, string key) where T : object o; tempData.TryGetValue(key, out o); -#if NETCOREAPP3_0 +#if NETCOREAPP3_0 || NETCOREAPP3_1 var obj = JsonSerializer.Deserialize((string)o); #else var obj = JsonConvert.DeserializeObject((string)o); diff --git a/LazZiya.TagHelpers/files/LazZiya.TagHelpers.xml b/LazZiya.TagHelpers/files/LazZiya.TagHelpers.xml index 03aecb8..ed69805 100644 --- a/LazZiya.TagHelpers/files/LazZiya.TagHelpers.xml +++ b/LazZiya.TagHelpers/files/LazZiya.TagHelpers.xml @@ -262,7 +262,7 @@ - ViewContext property is not required any more to be passed as parameter, you can remove it from the code. + ViewContext property is not required to be passed as parameter, it will be assigned automatically by the tag helper. View context is required to access TempData dictionary that contains the alerts coming from backend @@ -394,7 +394,7 @@ - ViewContext property is not required any more to be passed as parameter, you can remove it from the code. + ViewContext property is not required to be passed as parameter, it will be auto assigned by the tag helpoer. current view context to access RouteData.Values and Request.Query collection @@ -533,6 +533,12 @@ Creates a pagination control + + + ViewContext property is not required to be passed as parameter, it will be assigned automatically by the tag helper. + View context is required to access TempData dictionary that contains the alerts coming from backend + + Creates a pagination control @@ -617,14 +623,7 @@ - Query string value starting from the ? including all next query string parameters - to consider for next pages links. - default: string.Empty - - - @(Request.QueryString.Value) - - + query-string-value is obsolte and will be removed in a future release. @@ -810,13 +809,12 @@ - + edit the url for each page, so it navigates to its target page number -