Skip to content

Commit

Permalink
support netcore 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
LazZiya committed Nov 11, 2019
1 parent 0f6bc9d commit a798a52
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 54 deletions.
3 changes: 1 addition & 2 deletions LazZiya.TagHelpers/AlertTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ public class AlertTagHelper : TagHelper
public bool Dismissable { get; set; } = true;

/// <summary>
/// <para>ViewContext property is not required any more to be passed as parameter, you can remove it from the code.</para>
/// <para>ViewContext property is not required to be passed as parameter, it will be assigned automatically by the tag helper.</para>
/// <para>View context is required to access TempData dictionary that contains the alerts coming from backend</para>
/// </summary>
[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;

Expand Down
4 changes: 2 additions & 2 deletions LazZiya.TagHelpers/Alerts/AlertPageModelExtensions.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<List<Alert>>(tempData[Alert.TempDataKey].ToString())
: new List<Alert>();
Expand Down
13 changes: 6 additions & 7 deletions LazZiya.TagHelpers/LanguageNavTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -54,10 +54,9 @@ public class LanguageNavTagHelper : TagHelper
public string HomePageName { get; set; } = "Index";

/// <summary>
/// <para>ViewContext property is not required any more to be passed as parameter, you can remove it from the code.</para>
/// <para>ViewContext property is not required to be passed as parameter, it will be auto assigned by the tag helpoer.</para>
/// <para>current view context to access RouteData.Values and Request.Query collection</para>
/// </summary>
[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; }

Expand All @@ -71,9 +70,9 @@ public class LanguageNavTagHelper : TagHelper
/// </summary>
private readonly IOptions<RequestLocalizationOptions> _ops;
private readonly ILogger _logger;
#if NETCOREAPP2_2 || NETCOREAPP3_0


#if NETCOREAPP2_2 || NETCOREAPP3_0 || NETCOREAPP3_1
private readonly IOptions<MvcOptions> _mvcOps;
private readonly LinkGenerator _lg;

Expand Down Expand Up @@ -218,7 +217,7 @@ private List<LanguageItem> 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
Expand Down
25 changes: 13 additions & 12 deletions LazZiya.TagHelpers/LazZiya.TagHelpers.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;netcoreapp2.1;netcoreapp2.2;netcoreapp3.0</TargetFrameworks>
<TargetFrameworks>netcoreapp2.0;netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1</TargetFrameworks>
<ApplicationIcon>files\icon.ico</ApplicationIcon>
<Authors>Ziya Mollamahmut</Authors>
<Company>Ziyad.info</Company>
Expand All @@ -13,12 +13,12 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageTags>asp.net, core, razor, mvc, taghelpers, taghelper,tag,helper,language,culture,dropdown, pagination, select, enum</PackageTags>
<PackageReleaseNotes>
- 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
</PackageReleaseNotes>
<Version>3.0.2</Version>
<AssemblyVersion>3.0.2.0</AssemblyVersion>
<FileVersion>3.0.2.0</FileVersion>
<Version>3.1.0-preview1</Version>
<AssemblyVersion>3.1.0.0</AssemblyVersion>
<FileVersion>3.1.0.0</FileVersion>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageLicenseUrl></PackageLicenseUrl>
<PackageIconUrl>https://raw.githubusercontent.com/LazZiya/TagHelpers/master/LazZiya.TagHelpers/files/icon.png</PackageIconUrl>
Expand All @@ -29,20 +29,21 @@
<DocumentationFile>files\LazZiya.TagHelpers.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'netcoreapp3.0'">
<PackageReference Include="Microsoft.AspNetCore.Localization" Version="1.0.0" Exclude="build,analyzers" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0' OR '$(TargetFramework)' == 'netcoreapp2.1' OR '$(TargetFramework)' == 'netcoreapp2.2'">
<PackageReference Include="Microsoft.AspNetCore.Mvc.TagHelpers" Version="2.0.0" Exclude="build,analyzers" />
<PackageReference Include="Microsoft.AspNetCore.Localization" Version="2.0.0" Exclude="build,analyzers" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.2'">
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="2.2.0" Exclude="Build,Analyzers" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
<FrameworkReference Include="Microsoft.AspNetCore.App" Version="3.0.0" Exclude="Build,Analyzers" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.2'">
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="2.2.0" Exclude="Build,Analyzers" />
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<FrameworkReference Include="Microsoft.AspNetCore.App" Version="3.1.0" Exclude="Build,Analyzers" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace LazZiya.TagHelpers
public class LocalizationValidationScriptsTagHelperComponent : TagHelperComponent
{

#if NETCOREAPP3_0
#if NETCOREAPP3_0 || NETCOREAPP3_1
private readonly IWebHostEnvironment _hosting;

/// <summary>
Expand Down
31 changes: 16 additions & 15 deletions LazZiya.TagHelpers/PagingTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,7 +21,15 @@ namespace LazZiya.TagHelpers
public class PagingTagHelper : TagHelper
{
private IConfiguration Configuration { get; }
private ILogger _logger;
private readonly ILogger _logger;


/// <summary>
/// <para>ViewContext property is not required to be passed as parameter, it will be assigned automatically by the tag helper.</para>
/// <para>View context is required to access TempData dictionary that contains the alerts coming from backend</para>
/// </summary>
[ViewContext]
public ViewContext ViewContext { get; set; } = null;

/// <summary>
/// Creates a pagination control
Expand Down Expand Up @@ -118,15 +127,9 @@ public PagingTagHelper(IConfiguration configuration, ILogger<PagingTagHelper> lo
public string QueryStringKeyPageSize { get; set; }

/// <summary>
/// Query string value starting from the ? including all next query string parameters
/// to consider for next pages links.
/// <para>default: string.Empty</para>
/// <example>
/// <code>
/// @(Request.QueryString.Value)
/// </code>
/// </example>
/// query-string-value is obsolte and will be removed in a future release.
/// </summary>
[Obsolete("query-string-value is obsolte and will be removed in a future release")]
public string QueryStringValue { get; set; }

#endregion
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -543,7 +544,6 @@ private void SetDefaults()
$"{nameof(TotalPages)}: {TotalPages}, " +
$"{nameof(QueryStringKeyPageNo)}: {QueryStringKeyPageNo}, " +
$"{nameof(QueryStringKeyPageSize)}: {QueryStringKeyPageSize}, " +
$"{nameof(QueryStringValue)}: {QueryStringValue}" +
$"");
}

Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -665,10 +665,11 @@ private TagBuilder CreatePageSizeControl()
/// </summary>
/// <param name="pageNo"></param>
/// <param name="pageSize"></param>
/// <param name="urlPath"></param>
/// <returns></returns>
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
Expand Down
6 changes: 3 additions & 3 deletions LazZiya.TagHelpers/Utilities/GenericTempDataExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,7 +25,7 @@ public static class GenericTempDataExtensions
/// <param name="value"></param>
public static void Put<T>(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);
Expand All @@ -44,7 +44,7 @@ public static T Get<T>(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<T>((string)o);
#else
var obj = JsonConvert.DeserializeObject<T>((string)o);
Expand Down
22 changes: 10 additions & 12 deletions LazZiya.TagHelpers/files/LazZiya.TagHelpers.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a798a52

Please sign in to comment.