Skip to content

Commit

Permalink
upgrading to .net 8
Browse files Browse the repository at this point in the history
  • Loading branch information
mariodivece committed Jan 12, 2024
1 parent 5e8b91d commit fb55f4f
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<PreserveCompilationContext>true</PreserveCompilationContext>
<AssemblyName>Unosquare.Tubular.AspNetCoreSample</AssemblyName>
<OutputType>Exe</OutputType>
Expand All @@ -23,10 +23,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.1" />
<PackageReference Include="Unosquare.Swan.AspNetCore" Version="1.2.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.34.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.2.0" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions src/Unosquare.Tubular.EmbedioSample/PeopleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ namespace Unosquare.Tubular.EmbedioSample;
/// </summary>
public class PeopleController : WebApiController
{
private static readonly List<Person> People = new()
{
private static readonly List<Person> People =
[
new() { Key = 1, Name = "Mario Di Vece", Age = 31, EmailAddress = "[email protected]" },
new() { Key = 2, Name = "Geovanni Perez", Age = 31, EmailAddress = "[email protected]" },
new() { Key = 3, Name = "Luis Gonzalez", Age = 29, EmailAddress = "[email protected]" },
new() { Key = 4, Name = "Carlos Solorzano", Age = 22, EmailAddress = "[email protected]" }
};
];

[Route(HttpVerbs.Post, "/people")]
public GridDataResponse GetPeople([JsonGridDataRequest] GridDataRequest model) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<AssemblyTitle>Tubular with EmbedIO webserver sample</AssemblyTitle>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<OutputType>Exe</OutputType>
<PackageId>Unosquare.Tubular.EmbedioSample</PackageId>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
Expand Down
14 changes: 11 additions & 3 deletions src/Unosquare.Tubular/CommonTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
/// <summary>
/// Common property types supported by this library.
/// </summary>
internal class CommonTypes
internal static class CommonTypes
{
/// <summary>
/// Defines primitive types.
/// </summary>
public static readonly Type[] PrimitiveTypes =
{
[
typeof(string),
typeof(DateTime),
typeof(DateOnly),
typeof(DateTimeOffset),
typeof(TimeOnly),
typeof(bool),
typeof(byte),
typeof(sbyte),
Expand All @@ -21,13 +23,17 @@ internal class CommonTypes
typeof(double),
typeof(float),
typeof(int),
typeof(nint),
typeof(nuint),
typeof(uint),
typeof(long),
typeof(ulong),
typeof(short),
typeof(ushort),
typeof(DateTime?),
typeof(DateOnly?),
typeof(DateTimeOffset?),
typeof(TimeOnly?),
typeof(bool?),
typeof(byte?),
typeof(sbyte?),
Expand All @@ -36,12 +42,14 @@ internal class CommonTypes
typeof(double?),
typeof(float?),
typeof(int?),
typeof(nint?),
typeof(nuint?),
typeof(uint?),
typeof(long?),
typeof(ulong?),
typeof(short?),
typeof(ushort?),
typeof(Guid),
typeof(Guid?),
};
];
}
2 changes: 2 additions & 0 deletions src/Unosquare.Tubular/DataType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ public enum DataType
/// <summary>
/// String type
/// </summary>
#pragma warning disable CA1720 // Identifier contains type name
String,
#pragma warning restore CA1720 // Identifier contains type name

/// <summary>
/// Numeric type (int or float)
Expand Down
30 changes: 15 additions & 15 deletions src/Unosquare.Tubular/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ public static GridDataResponse CreateGridDataResponse(
IQueryable dataSource,
Func<IQueryable, IQueryable>? preProcessSubset = null)
{
if (request is null)
throw new ArgumentNullException(nameof(request));
ArgumentNullException.ThrowIfNull(request);
if (request.Columns is null)
throw new ArgumentNullException(nameof(request), $"The {nameof(request.Columns)} is null.");
if (dataSource is null)
throw new ArgumentNullException(nameof(dataSource));
if (!request.Columns.Any())
ArgumentNullException.ThrowIfNull(dataSource);
if (request.Columns.Length == 0)
throw new ArgumentOutOfRangeException(nameof(request), "Missing column information.");

var response = new GridDataResponse
Expand Down Expand Up @@ -104,14 +102,16 @@ public static GridDataResponse CreateGridDataResponse(
if (preProcessSubset != null)
subset = preProcessSubset(subset);

response.Payload = subset.CreateRowsPayload(columnMap, pageSize, request.TimezoneOffset);
response.Payload = subset.CreateRowsPayload(
columnMap, pageSize, request.TimezoneOffset);

return response;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static Dictionary<GridColumn, PropertyInfo> MapColumnsToProperties(
IReadOnlyCollection<GridColumn?> columns,
IReadOnlyDictionary<string, PropertyInfo> properties)
Dictionary<string, PropertyInfo> properties)
{
var columnMap = new Dictionary<GridColumn, PropertyInfo>(columns.Count);

Expand Down Expand Up @@ -167,8 +167,9 @@ private static Dictionary<GridColumn, PropertyInfo> MapColumnsToProperties(
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static Dictionary<string, object> CreateAggregationPayload(this IQueryable subset, IEnumerable<GridColumn?> columns)
{
var aggregateColumns = columns.Where(c => c?.Aggregate != AggregationFunction.None);
var payload = new Dictionary<string, object>(aggregateColumns.Count());
var cols = columns.ToArray();
var aggregateColumns = cols.Where(c => c?.Aggregate != AggregationFunction.None).ToArray();
var payload = new Dictionary<string, object>(aggregateColumns.Length);

foreach (var column in aggregateColumns)
{
Expand All @@ -186,7 +187,7 @@ private static Dictionary<string, object> CreateAggregationPayload(this IQueryab
return payload;
}

private static void AddAggregateColumn(this IDictionary<string, object> payload, GridColumn gridColumn, IQueryable subset)
private static void AddAggregateColumn(this Dictionary<string, object> payload, GridColumn gridColumn, IQueryable subset)
{
void Aggregate(GridColumn column,
Func<IQueryable<double>, double> doubleF,
Expand All @@ -195,8 +196,7 @@ void Aggregate(GridColumn column,
Func<IQueryable<string?>, string>? stringF,
Func<IQueryable<DateTime>, DateTime>? dateF)
{
if (column is null)
throw new ArgumentNullException(nameof(column));
ArgumentNullException.ThrowIfNull(column);

if (string.IsNullOrWhiteSpace(column.Name))
throw new ArgumentNullException(nameof(column), $"The column has an empty '{nameof(column.Name)}'");
Expand Down Expand Up @@ -253,10 +253,10 @@ void Aggregate(GridColumn column,
Aggregate(gridColumn, x => x.Average(), x => x.Average(), x => x.Sum() / x.Count(), null, null);
break;
case AggregationFunction.Max:
Aggregate(gridColumn, x => x.Max(), x => x.Max(), x => x.Max(), x => x.Max(), x => x.Max());
Aggregate(gridColumn, x => x.Max(), x => x.Max(), x => x.Max(), x => x.Max() ?? string.Empty, x => x.Max());
break;
case AggregationFunction.Min:
Aggregate(gridColumn, x => x.Min(), x => x.Min(), x => x.Min(), x => x.Min(), x => x.Min());
Aggregate(gridColumn, x => x.Min(), x => x.Min(), x => x.Min(), x => x.Min() ?? string.Empty, x => x.Min());
break;
case AggregationFunction.Count:
payload.Add(gridColumn.Name!, subset.Select(gridColumn.Name!).Count());
Expand Down Expand Up @@ -331,7 +331,7 @@ private static IQueryable ApplySearchAndColumnFilters(this GridDataResponse resp
private static void AppendColumnFilter(
this StringBuilder searchLambda,
GridColumn column,
ICollection<object?> searchParamArgs,
List<object?> searchParamArgs,
bool isDbQuery)
{
switch (column.FilterOperator)
Expand Down
4 changes: 2 additions & 2 deletions src/Unosquare.Tubular/GridDataResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class GridDataResponse
/// <summary>
/// A list of object's list with all the rows.
/// </summary>
public List<List<object?>>? Payload { get; set; }
public List<List<object?>> Payload { get; set; } = [];

/// <summary>
/// Set how many records are in the entire set.
Expand All @@ -39,5 +39,5 @@ public class GridDataResponse
/// <summary>
/// A dictionary with the aggregation functions.
/// </summary>
public Dictionary<string, object>? AggregationPayload { get; set; }
public Dictionary<string, object>? AggregationPayload { get; set; } = [];
}
9 changes: 5 additions & 4 deletions src/Unosquare.Tubular/Unosquare.Tubular.csproj
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<LangVersion>latest</LangVersion>
<TargetFramework>net7.0</TargetFramework>
<TargetFrameworks>net8.0;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<PackageId>Tubular.ServerSide</PackageId>
<Version>8.0.0</Version>
<Version>8.1.12</Version>
<Authors>mariodivece, geoperez, unosquare</Authors>
<Company>Unosquare</Company>
<Product>Unosquare Tubular Server-Side Library</Product>
<Description>A set of C# classes designed to rapidly build modern web applications to use with Tubular Angular library.</Description>
<Copyright>(c) 2016-2022 Unosquare, LLC</Copyright>
<Copyright>(c) 2016-2024 Unosquare, LLC</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageTags>tubular, rest, api, grid</PackageTags>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/unosquare/tubular-dotnet</RepositoryUrl>
<PackageReleaseNotes>Please review the examples in the repo for usage.</PackageReleaseNotes>
<PackageIcon>tubular.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<ImplicitUsings>true</ImplicitUsings>
<RepositoryType>git</RepositoryType>
<CodeAnalysisRuleSet>..\..\StyleCop.Analyzers.ruleset</CodeAnalysisRuleSet>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down

0 comments on commit fb55f4f

Please sign in to comment.