Skip to content

Commit

Permalink
Merge branch 'dev/develop' into dev/snow
Browse files Browse the repository at this point in the history
  • Loading branch information
gmf520 committed Oct 2, 2023
2 parents 041cab4 + 0ae7a95 commit 5984d92
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 21 deletions.
8 changes: 4 additions & 4 deletions README.md
@@ -1,7 +1,8 @@
# OSharp Framework

[![Member project of .NET Core Community](https://img.shields.io/badge/member%20project%20of-NCC-9e20c9.svg)](https://github.com/dotnetcore)
[![depoly action](https://github.com/dotnetcore/osharp/workflows/Build/Test/MirrorToGitee/badge.svg)](https://github.com/dotnetcore/osharp/actions/workflows/ci.yml)
[![depoly action](https://img.shields.io/github/actions/workflow/status/dotnetcore/osharp/ci.yml
)](https://github.com/dotnetcore/osharp/actions/workflows/ci.yml)
[![NuGet Badge](https://buildstats.info/nuget/osharp.core)](https://www.nuget.org/packages/osharpns/)
[![GitHub license](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://raw.githubusercontent.com/i66soft/osharp-ns20/master/LICENSE)

Expand Down Expand Up @@ -67,6 +68,7 @@ OSharp 全称 OSharp Framework with .NetStandard2.x,是一个基于.NetStandar

|包名称|稳定版本|预览版本|下载数|
|----|----|----|----|
|[OSharp.Utils](https://www.nuget.org/packages/OSharp.Utils/)|[![OSharp.Utils](https://img.shields.io/nuget/v/OSharp.Utils.svg)](https://www.nuget.org/packages/OSharp.Utils/)|[![OSharp.Utils](https://img.shields.io/nuget/vpre/OSharp.Utils.svg)](https://www.nuget.org/packages/OSharp.Utils/)|[![OSharp.Utils](https://img.shields.io/nuget/dt/OSharp.Utils.svg)](https://www.nuget.org/packages/OSharp.Utils/)|
|[OSharp.Core](https://www.nuget.org/packages/OSharp.Core/)|[![OSharp.Core](https://img.shields.io/nuget/v/OSharp.Core.svg)](https://www.nuget.org/packages/OSharp.Core/)|[![OSharp.Core](https://img.shields.io/nuget/vpre/OSharp.Core.svg)](https://www.nuget.org/packages/OSharp.Core/)|[![OSharp.Core](https://img.shields.io/nuget/dt/OSharp.Core.svg)](https://www.nuget.org/packages/OSharp.Core/)|
|[OSharp.AspNetCore](https://www.nuget.org/packages/OSharp.AspNetCore/)|[![OSharp.AspNetCore](https://img.shields.io/nuget/v/OSharp.AspNetCore.svg)](https://www.nuget.org/packages/OSharp.AspNetCore/)|[![OSharp.AspNetCore](https://img.shields.io/nuget/vpre/OSharp.AspNetCore.svg)](https://www.nuget.org/packages/OSharp.AspNetCore/)|[![OSharp.AspNetCore](https://img.shields.io/nuget/dt/OSharp.AspNetCore.svg)](https://www.nuget.org/packages/OSharp.AspNetCore/)|
|[OSharp.Authorization.Datas](https://www.nuget.org/packages/OSharp.Authorization.Datas/)|[![OSharp.Authorization.Datas](https://img.shields.io/nuget/v/OSharp.Authorization.Datas.svg)](https://www.nuget.org/packages/OSharp.Authorization.Datas/)|[![OSharp.Authorization.Datas](https://img.shields.io/nuget/vpre/OSharp.Authorization.Datas.svg)](https://www.nuget.org/packages/OSharp.Authorization.Datas/)|[![OSharp.Authorization.Datas](https://img.shields.io/nuget/dt/OSharp.Authorization.Datas.svg)](https://www.nuget.org/packages/OSharp.Authorization.Datas/)|
Expand All @@ -79,8 +81,6 @@ OSharp 全称 OSharp Framework with .NetStandard2.x,是一个基于.NetStandar
|[OSharp.EntityFrameworkCore.PostgreSql](https://www.nuget.org/packages/OSharp.EntityFrameworkCore.PostgreSql/)|[![OSharp.EntityFrameworkCore.PostgreSql](https://img.shields.io/nuget/v/OSharp.EntityFrameworkCore.PostgreSql.svg)](https://www.nuget.org/packages/OSharp.EntityFrameworkCore.PostgreSql/)|[![OSharp.EntityFrameworkCore.PostgreSql](https://img.shields.io/nuget/vpre/OSharp.EntityFrameworkCore.PostgreSql.svg)](https://www.nuget.org/packages/OSharp.EntityFrameworkCore.PostgreSql/)|[![OSharp.EntityFrameworkCore.PostgreSql](https://img.shields.io/nuget/dt/OSharp.EntityFrameworkCore.PostgreSql.svg)](https://www.nuget.org/packages/OSharp.EntityFrameworkCore.PostgreSql/)|
|[OSharp.Hangfire](https://www.nuget.org/packages/OSharp.Hangfire/)|[![OSharp.Hangfire](https://img.shields.io/nuget/v/OSharp.Hangfire.svg)](https://www.nuget.org/packages/OSharp.Hangfire/)|[![OSharp.Hangfire](https://img.shields.io/nuget/vpre/OSharp.Hangfire.svg)](https://www.nuget.org/packages/OSharp.Hangfire/)|[![OSharp.Hangfire](https://img.shields.io/nuget/dt/OSharp.Hangfire.svg)](https://www.nuget.org/packages/OSharp.Hangfire/)||[OSharp.Identity](https://www.nuget.org/packages/OSharp.Identity/)|[![OSharp.Identity](https://img.shields.io/nuget/v/OSharp.Identity.svg)](https://www.nuget.org/packages/OSharp.Identity/)|
|[OSharp.Identity](https://www.nuget.org/packages/OSharp.Identity/)|[![OSharp.Identity](https://img.shields.io/nuget/v/OSharp.Identity.svg)](https://www.nuget.org/packages/OSharp.Identity/)|[![OSharp.Identity](https://img.shields.io/nuget/vpre/OSharp.Identity.svg)](https://www.nuget.org/packages/OSharp.Identity/)|[![OSharp.Identity](https://img.shields.io/nuget/dt/OSharp.Identity.svg)](https://www.nuget.org/packages/OSharp.Identity/)|
|[OSharp.IdentityServer](https://www.nuget.org/packages/OSharp.IdentityServer/)|[![OSharp.IdentityServer](https://img.shields.io/nuget/v/OSharp.IdentityServer.svg)](https://www.nuget.org/packages/OSharp.IdentityServer/)|[![OSharp.IdentityServer](https://img.shields.io/nuget/vpre/OSharp.IdentityServer.svg)](https://www.nuget.org/packages/OSharp.IdentityServer/)|[![OSharp.IdentityServer](https://img.shields.io/nuget/dt/OSharp.IdentityServer.svg)](https://www.nuget.org/packages/OSharp.IdentityServer/)|
|[OSharp.IdentityServer.EntityConfiguration](https://www.nuget.org/packages/OSharp.IdentityServer.EntityConfiguration/)|[![OSharp.IdentityServer.EntityConfiguration](https://img.shields.io/nuget/v/OSharp.IdentityServer.EntityConfiguration.svg)](https://www.nuget.org/packages/OSharp.IdentityServer.EntityConfiguration/)|[![OSharp.IdentityServer.EntityConfiguration](https://img.shields.io/nuget/vpre/OSharp.IdentityServer.EntityConfiguration.svg)](https://www.nuget.org/packages/OSharp.IdentityServer.EntityConfiguration/)|[![OSharp.IdentityServer.EntityConfiguration](https://img.shields.io/nuget/dt/OSharp.IdentityServer.EntityConfiguration.svg)](https://www.nuget.org/packages/OSharp.IdentityServer.EntityConfiguration/)|
|[OSharp.Log4Net](https://www.nuget.org/packages/OSharp.Log4Net/)|[![OSharp.Log4Net](https://img.shields.io/nuget/v/OSharp.Log4Net.svg)](https://www.nuget.org/packages/OSharp.Log4Net/)|[![OSharp.Log4Net](https://img.shields.io/nuget/vpre/OSharp.Log4Net.svg)](https://www.nuget.org/packages/OSharp.Log4Net/)|[![OSharp.Log4Net](https://img.shields.io/nuget/dt/OSharp.Log4Net.svg)](https://www.nuget.org/packages/OSharp.Log4Net/)|
|[OSharp.MiniProfiler](https://www.nuget.org/packages/OSharp.MiniProfiler/)|[![OSharp.MiniProfiler](https://img.shields.io/nuget/v/OSharp.MiniProfiler.svg)](https://www.nuget.org/packages/OSharp.MiniProfiler/)|[![OSharp.MiniProfiler](https://img.shields.io/nuget/vpre/OSharp.MiniProfiler.svg)](https://www.nuget.org/packages/OSharp.MiniProfiler/)|[![OSharp.MiniProfiler](https://img.shields.io/nuget/dt/OSharp.MiniProfiler.svg)](https://www.nuget.org/packages/OSharp.MiniProfiler/)|
|[OSharp.Redis](https://www.nuget.org/packages/OSharp.Redis/)|[![OSharp.Redis](https://img.shields.io/nuget/v/OSharp.Redis.svg)](https://www.nuget.org/packages/OSharp.Redis/)|[![OSharp.Redis](https://img.shields.io/nuget/vpre/OSharp.Redis.svg)](https://www.nuget.org/packages/OSharp.Redis/)|[![OSharp.Redis](https://img.shields.io/nuget/dt/OSharp.Redis.svg)](https://www.nuget.org/packages/OSharp.Redis/)|
Expand Down Expand Up @@ -328,4 +328,4 @@ OSharp 当前版本(6.0.0)使用了 `.net` 当前最新版本 `6.0.0`,所

## 感谢
[![](https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE1Mu3b?ver=5c31)](https://dotnet.microsoft.com/zh-cn/)
[![JetBrains Resharper](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)](https://www.jetbrains.com/resharper/)
[![JetBrains Resharper](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)](https://www.jetbrains.com/resharper/)
Expand Up @@ -229,7 +229,7 @@ public async Task<AjaxResult> Token(TokenDto dto)
User user = result.Data;
JsonWebToken token = await CreateJwtToken(user, dto.ClientType);
await unitOfWork.CommitAsync();
return new AjaxResult("登录成功", AjaxResultType.Success, token);
return new AjaxResult<JsonWebToken>("登录成功", AjaxResultType.Success, token);
}

if (grantType == GrantType.RefreshToken)
Expand Down
4 changes: 2 additions & 2 deletions samples/web/Liuliu.Demo.Web/Hangfire/HangfireJobRunner.cs
Expand Up @@ -36,8 +36,8 @@ public void Start()
BackgroundJob.Enqueue<UserManager<User>>(m => m.FindByIdAsync("1"));
string jobId = BackgroundJob.Schedule<UserManager<User>>(m => m.FindByIdAsync("2"), TimeSpan.FromMinutes(2));
BackgroundJob.ContinueJobWith<TestHangfireJob>(jobId, m => m.GetUserCount());
RecurringJob.AddOrUpdate<TestHangfireJob>(m => m.GetUserCount(), Cron.Minutely, TimeZoneInfo.Local);
RecurringJob.AddOrUpdate<TestHangfireJob>(m=>m.LockUser2(), Cron.Minutely, TimeZoneInfo.Local);
RecurringJob.AddOrUpdate<TestHangfireJob>("TestHangfireJob.GetUserCount", m => m.GetUserCount(), Cron.Minutely);
RecurringJob.AddOrUpdate<TestHangfireJob>("TestHangfireJob.LockUser2", m => m.LockUser2(), Cron.Minutely);
}
}

Expand Down
68 changes: 60 additions & 8 deletions src/OSharp.AspNetCore/UI/AjaxResult.cs
Expand Up @@ -24,10 +24,17 @@ public AjaxResult()
/// <summary>
/// 初始化一个<see cref="AjaxResult"/>类型的新实例
/// </summary>
public AjaxResult(string content, AjaxResultType type = AjaxResultType.Success, object data = null)
public AjaxResult(string content, AjaxResultType type = AjaxResultType.Success, object data = default)
: this(content, data, type)
{ }

/// <summary>
/// 初始化一个<see cref="AjaxResult"/>类型的新实例
/// </summary>
public AjaxResult(object data, AjaxResultType type = AjaxResultType.Success, string content = null)
: this(content ?? type.ToDescription(), data, type)
{ }

/// <summary>
/// 初始化一个<see cref="AjaxResult"/>类型的新实例
/// </summary>
Expand All @@ -38,13 +45,6 @@ public AjaxResult(string content, object data, AjaxResultType type = AjaxResultT
Data = data;
}

/// <summary>
/// 初始化一个<see cref="AjaxResult"/>类型的新实例
/// </summary>
public AjaxResult(object data, AjaxResultType type = AjaxResultType.Success, string content = null)
: this(content ?? type.ToDescription(), data, type)
{ }

/// <summary>
/// 获取或设置 Ajax操作结果类型
/// </summary>
Expand Down Expand Up @@ -84,3 +84,55 @@ public static AjaxResult Success(object data = null)
return new AjaxResult("操作执行成功", AjaxResultType.Success, data);
}
}



/// <summary>
/// 表示Ajax操作结果
/// </summary>
public class AjaxResult<T> : AjaxResult
{
/// <summary>
/// 初始化一个<see cref="AjaxResult"/>类型的新实例
/// </summary>
public AjaxResult()
: this(null)
{ }

/// <summary>
/// 初始化一个<see cref="AjaxResult"/>类型的新实例
/// </summary>
public AjaxResult(string content, AjaxResultType type = AjaxResultType.Success, T data = default)
: this(content, data, type)
{ }

/// <summary>
/// 初始化一个<see cref="AjaxResult"/>类型的新实例
/// </summary>
public AjaxResult(T data, AjaxResultType type = AjaxResultType.Success, string content = null)
: this(content ?? type.ToDescription(), data, type)
{ }

/// <summary>
/// 初始化一个<see cref="AjaxResult"/>类型的新实例
/// </summary>
public AjaxResult(string content, T data, AjaxResultType type = AjaxResultType.Success)
{
Type = type;
Content = content;
Data = data;
}

/// <summary>
/// 获取或设置 返回数据
/// </summary>
public new T Data { get; set; }

/// <summary>
/// 成功的AjaxResult
/// </summary>
public static AjaxResult<T> Success(T data = default)
{
return new AjaxResult<T>("操作执行成功", AjaxResultType.Success, data);
}
}
39 changes: 33 additions & 6 deletions src/OSharp.AspNetCore/UI/AjaxResultExtensions.cs
Expand Up @@ -17,12 +17,39 @@ public static class AjaxResultExtensions
/// <summary>
/// 将业务操作结果转ajax操作结果,并处理强类型的 OperationResult.Data
/// </summary>
public static AjaxResult ToAjaxResult<T>(this OperationResult<T> result, Func<T, object> dataFunc = null)
public static AjaxResult<T> ToAjaxResult<T>(this OperationResult<T> result, Func<T, T> dataFunc = null)
{
string content = result.Message ?? result.ResultType.ToDescription();
AjaxResultType type = result.ResultType.ToAjaxResultType();
object data = dataFunc == null ? result.Data : dataFunc(result.Data);
return new AjaxResult(content, type, data);
T data = dataFunc == null ? result.Data : dataFunc(result.Data);
return new AjaxResult<T>(content, type, data);
}

/// <summary>
/// 将业务操作结果转ajax操作结果,并处理强类型的 OperationResult.Data
/// </summary>
public static AjaxResult<TResult> ToAjaxResult<T, TResult>(this OperationResult<T> result, Func<T, TResult> dataFunc = null)
{
string content = result.Message ?? result.ResultType.ToDescription();
AjaxResultType type = result.ResultType.ToAjaxResultType();
TResult data;
if (dataFunc == null)
{
if (result.Data is TResult data2)
{
data = data2;
}
else
{
data = default;
}
}
else
{
data = dataFunc(result.Data);
}

return new AjaxResult<TResult>(content, type, data);
}

/// <summary>
Expand All @@ -41,19 +68,19 @@ public static AjaxResult ToAjaxResult(this OperationResult result, bool contains
/// <summary>
/// 将业务操作结果转ajax操作结果,会将 object 类型的 OperationResult.Data 转换为强类型 T,再通过 dataFunc 进行进一步处理
/// </summary>
public static AjaxResult ToAjaxResult<T>(this OperationResult result, Func<T, object> dataFunc)
public static AjaxResult<T> ToAjaxResult<T>(this OperationResult result, Func<T, T> dataFunc)
{
string content = result.Message ?? result.ResultType.ToDescription();
AjaxResultType type = result.ResultType.ToAjaxResultType();
object data = null;
T data = default;
if (result.Data != null)
{
if (dataFunc != null && result.Data is T resultData)
{
data = dataFunc(resultData);
}
}
return new AjaxResult(content, type, data);
return new AjaxResult<T>(content, type, data);
}

/// <summary>
Expand Down

0 comments on commit 5984d92

Please sign in to comment.