Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/WalkingTec.Mvvm.Core/BaseBatchVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public virtual bool DoBatchDelete()
DC!.UpdateProperty(Entity, "IsValid");
if (isBasePoco)
{
(Entity as IBasePoco)!.UpdateTime = DateTime.Now;
(Entity as IBasePoco)!.UpdateTime = Wtm!.TimeProvider.GetLocalNow().DateTime;
(Entity as IBasePoco)!.UpdateBy = LoginUserInfo?.ITCode;
DC!.UpdateProperty(Entity, "UpdateTime");
DC!.UpdateProperty(Entity, "UpdateBy");
Expand Down Expand Up @@ -350,7 +350,7 @@ public virtual bool DoBatchEdit()
IBasePoco ent = (entity as IBasePoco)!;
if (ent.UpdateTime == null)
{
ent.UpdateTime = DateTime.Now;
ent.UpdateTime = Wtm!.TimeProvider.GetLocalNow().DateTime;
DC!.UpdateProperty(entity, nameof(ent.UpdateTime));
}
if (string.IsNullOrEmpty(ent.UpdateBy))
Expand Down
6 changes: 3 additions & 3 deletions src/WalkingTec.Mvvm.Core/BaseImportVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ public virtual void SetEntityData()

if (typeof(IBasePoco).IsAssignableFrom(SubTypeEntity.GetType()))
{
(SubTypeEntity as IBasePoco)!.CreateTime = DateTime.Now;
(SubTypeEntity as IBasePoco)!.CreateTime = Wtm!.TimeProvider.GetLocalNow().DateTime;
(SubTypeEntity as IBasePoco)!.CreateBy = LoginUserInfo?.ITCode;
}
if (typeof(ITenant).IsAssignableFrom(SubTypeEntity.GetType()))
Expand Down Expand Up @@ -1032,7 +1032,7 @@ public virtual bool BatchSaveData(IProgress<ImportProgress>? progress = null)
{
if (typeof(IBasePoco).IsAssignableFrom(exist.GetType()))
{
(exist as IBasePoco)!.UpdateTime = DateTime.Now;
(exist as IBasePoco)!.UpdateTime = Wtm!.TimeProvider.GetLocalNow().DateTime;
DC!.UpdateProperty(exist, "UpdateTime");
}
}
Expand Down Expand Up @@ -1071,7 +1071,7 @@ public virtual bool BatchSaveData(IProgress<ImportProgress>? progress = null)
//进行添加操作
if (typeof(IBasePoco).IsAssignableFrom(item.GetType()))
{
(item as IBasePoco)!.CreateTime = DateTime.Now;
(item as IBasePoco)!.CreateTime = Wtm!.TimeProvider.GetLocalNow().DateTime;
(item as IBasePoco)!.CreateBy = LoginUserInfo?.ITCode;
}
if (typeof(ITenant).IsAssignableFrom(ModelType))
Expand Down
8 changes: 4 additions & 4 deletions src/WalkingTec.Mvvm.Core/BasePagedListVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
else
{
Guid g = Guid.NewGuid();
var FileName = typeof(TModel).Name + "_" + DateTime.Now.ToString("yyyyMMddHHmmssffff");
var FileName = typeof(TModel).Name + "_" + Wtm!.TimeProvider.GetLocalNow().DateTime.ToString("yyyyMMddHHmmssffff");
//文件根目录
string RootPath = $"{Wtm!.ConfigInfo.HostRoot}\\export{g}";

Expand Down Expand Up @@ -1133,7 +1133,7 @@
IBasePoco ent = (IBasePoco)newitem;
if (ent.UpdateTime == null)
{
ent.UpdateTime = DateTime.Now;
ent.UpdateTime = Wtm!.TimeProvider.GetLocalNow().DateTime;
}
if (string.IsNullOrEmpty(ent.UpdateBy))
{
Expand Down Expand Up @@ -1211,7 +1211,7 @@
(item as IPersistPoco)!.IsValid = false;
if (typeof(IBasePoco).IsAssignableFrom(ftype))
{
(item as IBasePoco)!.UpdateTime = DateTime.Now;
(item as IBasePoco)!.UpdateTime = Wtm!.TimeProvider.GetLocalNow().DateTime;
(item as IBasePoco)!.UpdateBy = LoginUserInfo?.ITCode;
}
dynamic i = item;
Expand All @@ -1238,7 +1238,7 @@
IBasePoco ent = (IBasePoco)item;
if (ent.CreateTime == null)
{
ent.CreateTime = DateTime.Now;
ent.CreateTime = Wtm!.TimeProvider.GetLocalNow().DateTime;
}
if (string.IsNullOrEmpty(ent.CreateBy))
{
Expand All @@ -1254,7 +1254,7 @@
}
}

public List<FrameworkWorkflow> GetMyApproves(string? flowname = null)

Check warning on line 1257 in src/WalkingTec.Mvvm.Core/BasePagedListVM.cs

View workflow job for this annotation

GitHub Actions / build-and-test

'FrameworkWorkflow' is obsolete: 'WTM's built-in Elsa workflow integration has been removed. This member will be deleted in the next major version. See CHANGELOG.md for migration guidance.'
{
var mt = ModelType.GetParentWorkflowPoco();
if (mt != null)
Expand Down
3 changes: 2 additions & 1 deletion src/WalkingTec.Mvvm.Core/BaseTemplateVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public byte[] GenerateTemplate(out string displayName)
{
//设置导出的文件名称
string SheetName = !string.IsNullOrEmpty(FileDisplayName) ? FileDisplayName : this.GetType().Name;
displayName = SheetName + "_" + DateTime.Now.ToString("yyyy-MM-dd") + "_" + DateTime.Now.ToString("hh^mm^ss") + ".xlsx";
var now = (Wtm?.TimeProvider ?? TimeProvider.System).GetLocalNow().DateTime;
displayName = SheetName + "_" + now.ToString("yyyy-MM-dd") + "_" + now.ToString("hh^mm^ss") + ".xlsx";

//1.声明Excel文档
IWorkbook workbook = new XSSFWorkbook();
Expand Down
22 changes: 12 additions & 10 deletions src/WalkingTec.Mvvm.Mvc/Auth/JwtAuth/TokenService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ public class TokenService : ITokenService
{
private readonly JwtOption _jwtOptions;
private readonly IServiceProvider _sp;
private readonly TimeProvider _timeProvider;
private const int RefreshTokenExpiryDays = 7;

public TokenService(IOptionsMonitor<Configs> configs, IServiceProvider sp)
public TokenService(IOptionsMonitor<Configs> configs, IServiceProvider sp, TimeProvider? timeProvider = null)
{
_jwtOptions = configs.CurrentValue.JwtOptions;
_sp = sp;
_timeProvider = timeProvider ?? TimeProvider.System;
}

public async Task<Token> IssueTokenAsync(
Expand Down Expand Up @@ -61,13 +63,13 @@ public async Task<Token> RefreshTokenAsync(
if (existing is { IsRevoked: true, ReplacedByToken: not null })
{
await RevokeDescendantsAsync(dbSet, existing, ipAddress,
"Attempted reuse of revoked token");
"Attempted reuse of revoked token", _timeProvider);
await dc.SaveChangesAsync();
}
return null;
}
var newTokenString = GenerateRefreshTokenString();
existing.RevokedUtc = DateTime.UtcNow;
existing.RevokedUtc = _timeProvider.GetUtcNow().UtcDateTime;
existing.RevokedByIp = ipAddress;
existing.ReplacedByToken = newTokenString;
existing.RevokeReason = "Rotated";
Expand All @@ -76,7 +78,7 @@ await RevokeDescendantsAsync(dbSet, existing, ipAddress,
Token = newTokenString,
ITCode = existing.ITCode,
TenantCode = existing.TenantCode,
ExpiresUtc = DateTime.UtcNow.AddDays(RefreshTokenExpiryDays),
ExpiresUtc = _timeProvider.GetUtcNow().UtcDateTime.AddDays(RefreshTokenExpiryDays),
CreatedByIp = ipAddress
};
await dbSet.AddAsync(newEntity);
Expand All @@ -102,7 +104,7 @@ public async Task RevokeTokenAsync(
var existing = await dc.Set<RefreshTokenEntity>()
.FirstOrDefaultAsync(x => x.Token == refreshToken);
if (existing == null || !existing.IsActive) return;
existing.RevokedUtc = DateTime.UtcNow;
existing.RevokedUtc = _timeProvider.GetUtcNow().UtcDateTime;
existing.RevokedByIp = ipAddress;
existing.RevokeReason = reason ?? "Explicit revocation";
await dc.SaveChangesAsync();
Expand All @@ -128,7 +130,7 @@ private string GenerateAccessToken(LoginUserInfo info)
issuer: _jwtOptions.Issuer,
audience: _jwtOptions.Audience,
claims: claims,
expires: DateTime.UtcNow.AddSeconds(_jwtOptions.Expires),
expires: _timeProvider.GetUtcNow().UtcDateTime.AddSeconds(_jwtOptions.Expires),
signingCredentials: creds);
return new JwtSecurityTokenHandler().WriteToken(jwt);
}
Expand All @@ -142,7 +144,7 @@ private async Task<RefreshTokenEntity> CreateRefreshTokenAsync(
{
Token = GenerateRefreshTokenString(),
ITCode = itCode, TenantCode = tenantCode,
ExpiresUtc = DateTime.UtcNow.AddDays(RefreshTokenExpiryDays),
ExpiresUtc = _timeProvider.GetUtcNow().UtcDateTime.AddDays(RefreshTokenExpiryDays),
CreatedByIp = ipAddress
};
if (dc != null)
Expand All @@ -161,21 +163,21 @@ private static string GenerateRefreshTokenString()

private static async Task RevokeDescendantsAsync(
DbSet<RefreshTokenEntity> dbSet, RefreshTokenEntity token,
string ipAddress, string reason)
string ipAddress, string reason, TimeProvider timeProvider)
{
if (string.IsNullOrEmpty(token.ReplacedByToken)) return;
var child = await dbSet.FirstOrDefaultAsync(
x => x.Token == token.ReplacedByToken);
if (child == null) return;
if (child.IsActive)
{
child.RevokedUtc = DateTime.UtcNow;
child.RevokedUtc = timeProvider.GetUtcNow().UtcDateTime;
child.RevokedByIp = ipAddress;
child.RevokeReason = reason;
}
else
{
await RevokeDescendantsAsync(dbSet, child, ipAddress, reason);
await RevokeDescendantsAsync(dbSet, child, ipAddress, reason, timeProvider);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/WalkingTec.Mvvm.Mvc/Filters/FrameworkFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public override void OnActionExecuting(ActionExecutingContext context)
context.SetWtmContext();
if (context.HttpContext.Items.ContainsKey("actionstarttime") == false)
{
context.HttpContext.Items.Add("actionstarttime", DateTime.Now);
context.HttpContext.Items.Add("actionstarttime", ctrl.Wtm.TimeProvider.GetLocalNow().DateTime);
}
var ctrlActDesc = context.ActionDescriptor as ControllerActionDescriptor;
var log = new SimpleLog();// 初始化log备用
Expand Down Expand Up @@ -377,7 +377,7 @@ public override void OnResultExecuted(ResultExecutedContext context)
var postDes = ctrlActDesc.MethodInfo.GetCustomAttributes(typeof(HttpPostAttribute), false).Cast<HttpPostAttribute>().FirstOrDefault();

log.LogType = context.Exception == null ? ActionLogTypesEnum.Normal : ActionLogTypesEnum.Exception;
log.ActionTime = DateTime.Now;
log.ActionTime = ctrl.Wtm?.TimeProvider.GetLocalNow().DateTime ?? DateTime.Now;
log.ITCode = ctrl.Wtm?.LoginUserInfo?.ITCode ?? string.Empty;
// 给日志的多语言属性赋值
log.ModuleName = ctrlDes?.GetDescription(ctrl) ?? ctrlActDesc.ControllerName;
Expand All @@ -392,7 +392,7 @@ public override void OnResultExecuted(ResultExecutedContext context)
var starttime = context.HttpContext.Items["actionstarttime"] as DateTime?;
if (starttime != null)
{
log.Duration = DateTime.Now.Subtract(starttime.Value).TotalSeconds;
log.Duration = (ctrl.Wtm?.TimeProvider.GetLocalNow().DateTime ?? DateTime.Now).Subtract(starttime.Value).TotalSeconds;
}
try
{
Expand Down
3 changes: 2 additions & 1 deletion src/WalkingTec.Mvvm.Mvc/Helper/FileExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public static class FileExtension
var data = self.GenerateExcel();
string ContentType = self.ExportExcelCount > 1 ? "application/x-zip-compresse" : "application/vnd.ms-excel";
ExportName = string.IsNullOrEmpty(ExportName) ? typeof(T).Name : ExportName;
ExportName = self.ExportExcelCount > 1 ? $"Export_{ExportName}_{DateTime.Now.ToString("yyyyMMddHHmmssffff")}.zip" : $"Export_{ExportName}_{DateTime.Now.ToString("yyyyMMddHHmmssffff")}.xlsx";
var now = self.Wtm!.TimeProvider.GetLocalNow().DateTime;
ExportName = self.ExportExcelCount > 1 ? $"Export_{ExportName}_{now.ToString("yyyyMMddHHmmssffff")}.zip" : $"Export_{ExportName}_{now.ToString("yyyyMMddHHmmssffff")}.xlsx";
FileContentResult Result = new FileContentResult(data, ContentType);
Result.FileDownloadName = ExportName;
return Result;
Expand Down
4 changes: 2 additions & 2 deletions src/WalkingTec.Mvvm.Mvc/_AnalysisController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public IActionResult SaveQuery([FromBody] SaveQueryRequest? req)
ConfigJson = configJson,
OwnerCode = userCode,
IsPublic = req.IsPublic,
CreateTime = DateTime.Now,
CreateTime = Wtm!.TimeProvider.GetLocalNow().DateTime,
CreateBy = userCode
};

Expand Down Expand Up @@ -442,7 +442,7 @@ private void WriteAnalysisActionLog(
var log = new ActionLog
{
LogType = ActionLogTypesEnum.Normal,
ActionTime = DateTime.Now,
ActionTime = Wtm!.TimeProvider.GetLocalNow().DateTime,
ITCode = Wtm?.LoginUserInfo?.ITCode ?? string.Empty,
ModuleName = "Analysis",
ActionName = actionName,
Expand Down
13 changes: 7 additions & 6 deletions src/WalkingTec.Mvvm.Mvc/_FrameworkController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,10 @@ public IActionResult GetExportExcel(string _DONOT_USE_VMNAME, string _DONOT_USE_
return StatusCode(422, new { message = MvcProgram._localizer?["Sys.NoData"] ?? "No data" });
}

HttpContext.Response.Cookies.Append("DONOTUSEDOWNLOADING", "0", new Microsoft.AspNetCore.Http.CookieOptions() { Path = "/", Expires = DateTime.Now.AddDays(2) });
var now = Wtm.TimeProvider.GetLocalNow().DateTime;
HttpContext.Response.Cookies.Append("DONOTUSEDOWNLOADING", "0", new Microsoft.AspNetCore.Http.CookieOptions() { Path = "/", Expires = now.AddDays(2) });

return File(data, "application/vnd.ms-excel", $"Export_{instanceType.Name}_{DateTime.Now.ToString("yyyy-MM-dd")}.xls");
return File(data, "application/vnd.ms-excel", $"Export_{instanceType.Name}_{now.ToString("yyyy-MM-dd")}.xls");
}
else
{
Expand All @@ -280,7 +281,7 @@ public IActionResult GetExcelTemplate(string _DONOT_USE_VMNAME, string _DONOT_US
}
importVM.SetParms(qs);
var data = importVM.GenerateTemplate(out string fileName);
HttpContext.Response.Cookies.Append("DONOTUSEDOWNLOADING", "0", new Microsoft.AspNetCore.Http.CookieOptions() { Domain = "/", Expires = DateTime.Now.AddDays(2) });
HttpContext.Response.Cookies.Append("DONOTUSEDOWNLOADING", "0", new Microsoft.AspNetCore.Http.CookieOptions() { Domain = "/", Expires = Wtm.TimeProvider.GetLocalNow().DateTime.AddDays(2) });
return File(data, "application/vnd.ms-excel", fileName);
}

Expand All @@ -293,7 +294,7 @@ public IActionResult Error()
var ex = HttpContext.Features.Get<IExceptionHandlerPathFeature>();
ActionLog log = new ActionLog();
log.LogType = ActionLogTypesEnum.Exception;
log.ActionTime = DateTime.Now;
log.ActionTime = Wtm.TimeProvider.GetLocalNow().DateTime;
log.ITCode = Wtm.LoginUserInfo?.ITCode ?? string.Empty;

var controllerDes = ex.Error.TargetSite.DeclaringType.GetCustomAttributes(typeof(ActionDescriptionAttribute), false).Cast<ActionDescriptionAttribute>().FirstOrDefault();
Expand All @@ -316,7 +317,7 @@ public IActionResult Error()
DateTime? starttime = HttpContext.Items["actionstarttime"] as DateTime?;
if (starttime != null)
{
log.Duration = DateTime.Now.Subtract(starttime.Value).TotalSeconds;
log.Duration = Wtm.TimeProvider.GetLocalNow().DateTime.Subtract(starttime.Value).TotalSeconds;
}
var logger = HttpContext.RequestServices.GetRequiredService<ILogger<ActionLog>>();
if (logger != null)
Expand Down Expand Up @@ -655,7 +656,7 @@ public IActionResult UploadForLayUIUEditor([FromServices] WtmFileProvider fp, st
//通过Base64方式上传附件
var FileData = Convert.FromBase64String(Request.Form["FileID"]);
MemoryStream MS = new MemoryStream(FileData);
file = fp.Upload("SCRAWL_" + DateTime.Now.ToString("yyyyMMddHHmmssttt") + ".jpg", FileData.Length, MS, groupName, subdir, dc: Wtm.CreateDC(cskey: _DONOT_USE_CS));
file = fp.Upload("SCRAWL_" + Wtm.TimeProvider.GetLocalNow().DateTime.ToString("yyyyMMddHHmmssttt") + ".jpg", FileData.Length, MS, groupName, subdir, dc: Wtm.CreateDC(cskey: _DONOT_USE_CS));
MS.Dispose();
}

Expand Down
Loading