-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from EasyOC/TimerEventUseSiteTimeZone
Timer event use site time zone
- Loading branch information
Showing
21 changed files
with
393 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="wwwroot\" /> | ||
<Folder Include="Localization\" /> | ||
</ItemGroup> | ||
|
||
<!-- Watcher include and excludes --> | ||
<ItemGroup> | ||
<Watch Include="**\*.cs" Exclude="Recipes\**;Assets\**;node_modules\**\*;**\*.js.map;obj\**\*;bin\**\*" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="OrchardCore.Logging.NLog" Version="1.5.0" /> | ||
<PackageReference Include="OrchardCore.Application.Cms.Targets" Version="1.5.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Modules\EasyOC.ReplaceAction\EasyOC.ReplaceAction.csproj" /> | ||
<ProjectReference Include="..\Modules\EasyOC.SwaggerUI\EasyOC.SwaggerUI.csproj" /> | ||
<ProjectReference Include="..\Modules\EasyOC.Users\EasyOC.Users.csproj" /> | ||
<ProjectReference Include="..\Modules\EasyOC.Workflows\EasyOC.Workflows.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
�� |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
autoReload="true" | ||
internalLogLevel="Warn" | ||
internalLogFile="App_Data/logs/internal-nlog.txt"> | ||
|
||
<extensions> | ||
<add assembly="NLog.Web.AspNetCore"/> | ||
<add assembly="OrchardCore.Logging.NLog"/> | ||
</extensions> | ||
|
||
<targets> | ||
<!-- file target --> | ||
<target xsi:type="File" name="file" | ||
fileName="${var:configDir}/App_Data/logs/orchard-log-${shortdate}.log" | ||
layout="${longdate}|${orchard-tenant-name}|${aspnet-traceidentifier}|${event-properties:item=EventId.Id}|${logger}|${uppercase:${level}}|${message} ${exception:format=ToString,StackTrace}" | ||
/> | ||
|
||
<!-- console target --> | ||
<target xsi:type="Console" name="console" /> | ||
|
||
</targets> | ||
|
||
<rules> | ||
<!-- all warnings and above go to the file target --> | ||
<logger name="*" minlevel="Warn" writeTo="file" /> | ||
|
||
<!-- the hosting lifetime events go to the console and file targets --> | ||
<logger name="Microsoft.Hosting.Lifetime" minlevel="Info" writeTo="file, console" /> | ||
</rules> | ||
</nlog> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using OrchardCore.Logging; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.Host.UseNLogHost(); | ||
|
||
builder.Services | ||
.AddOrchardCms() | ||
// // Orchard Specific Pipeline | ||
// .ConfigureServices( services => { | ||
// }) | ||
// .Configure( (app, routes, services) => { | ||
// }) | ||
; | ||
|
||
var app = builder.Build(); | ||
|
||
if (!app.Environment.IsDevelopment()) | ||
{ | ||
app.UseExceptionHandler("/Error"); | ||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. | ||
app.UseHsts(); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
app.UseStaticFiles(); | ||
|
||
app.UseOrchardCore(); | ||
|
||
app.Run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:8080", | ||
"sslPort": 44300 | ||
} | ||
}, | ||
"profiles": { | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"EasyOC.CMS.Web": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"applicationUrl": "https://localhost:5001;http://localhost:5000", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"IncludeScopes": false, | ||
"LogLevel": { | ||
"Default": "Warning", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
�� |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace EasyOC.Workflows | ||
{ | ||
public class Constants | ||
{ | ||
public const string TimersFeautreId = "EasyOC.Workflows.Timers"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Razor"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<AddRazorSupportForMvc>true</AddRazorSupportForMvc> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
|
||
<PackageReference Include="OrchardCore.Module.Targets" Version="1.5.0" /> | ||
<PackageReference Include="OrchardCore.ContentManagement" Version="1.5.0" /> | ||
<PackageReference Include="OrchardCore.ContentTypes.Abstractions" Version="1.5.0" /> | ||
<PackageReference Include="OrchardCore.DisplayManagement" Version="1.5.0" /> | ||
<PackageReference Include="OrchardCore.Workflows" Version="$(OrchardCoreVersion)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Shared\EasyOC.Constants\EasyOC.Constants.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using OrchardCore.Modules.Manifest; | ||
using static EasyOC.Constants.ManifestConstants; | ||
[assembly: Module( | ||
Author = Author, | ||
Website = Website, | ||
Version = CurrentVersion, | ||
Description = "EasyOC.Workflows", | ||
Category = "Workflows" | ||
)] | ||
[assembly: Feature( | ||
Id = EasyOC.Workflows.Constants.TimersFeautreId, | ||
//Name = "Timer Workflow Activty (Support site time zone)", | ||
Dependencies = new[] { | ||
"OrchardCore.Workflows.Timers" }, | ||
Description = "Make Timer Workflow Activty support site time zone.", | ||
Category = "Workflows" | ||
)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using EasyOC.Workflows.Timers; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using OrchardCore.Modules; | ||
using OrchardCore.Workflows.Options; | ||
using OCTimerEvent = OrchardCore.Workflows.Timers.TimerEvent; | ||
namespace EasyOC.Workflows | ||
{ | ||
public class Startup : StartupBase | ||
{ | ||
public override void ConfigureServices(IServiceCollection services) | ||
{ | ||
|
||
} | ||
|
||
} | ||
[Feature(Constants.TimersFeautreId)] | ||
[RequireFeatures("OrchardCore.Workflows.Timers")] | ||
public class TimerStartup : StartupBase | ||
{ | ||
public override void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.Configure<WorkflowOptions>(options => | ||
{ | ||
if (options.IsActivityRegistered<OCTimerEvent>()) | ||
{ | ||
options.UnregisterActivityType<OCTimerEvent>(); | ||
} | ||
options.RegisterActivity<TimerEvent, TimerEventDisplayDriver>(); | ||
}); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using Microsoft.Extensions.Localization; | ||
using NCrontab; | ||
using OrchardCore.Modules; | ||
using OrchardCore.Settings; | ||
using OrchardCore.Workflows.Abstractions.Models; | ||
using OrchardCore.Workflows.Activities; | ||
using OrchardCore.Workflows.Models; | ||
|
||
namespace EasyOC.Workflows.Timers | ||
{ | ||
public class TimerEvent : EventActivity | ||
{ | ||
public static string EventName => nameof(TimerEvent); | ||
private readonly IClock _clock; | ||
private readonly IStringLocalizer S; | ||
private readonly ISiteService _siteService; | ||
|
||
public TimerEvent(IClock clock, IStringLocalizer<TimerEvent> localizer, ISiteService siteService) | ||
{ | ||
_clock = clock; | ||
S = localizer; | ||
_siteService = siteService; | ||
} | ||
|
||
public override string Name => EventName; | ||
|
||
public override LocalizedString DisplayText => S["Timer Event"]; | ||
|
||
public override LocalizedString Category => S["Background"]; | ||
|
||
public string CronExpression | ||
{ | ||
get => GetProperty(() => "*/5 * * * *"); | ||
set => SetProperty(value); | ||
} | ||
public bool UseSiteTimeZone | ||
{ | ||
get => GetProperty(() => false); | ||
set => SetProperty(value); | ||
} | ||
|
||
private DateTime? StartedTime | ||
{ | ||
get => GetProperty<DateTime?>(); | ||
set => SetProperty(value); | ||
} | ||
|
||
public override async Task<bool> CanExecuteAsync(WorkflowExecutionContext workflowContext, ActivityContext activityContext) | ||
{ | ||
return StartedTime == null || await IsExpired(); | ||
} | ||
|
||
public override IEnumerable<Outcome> GetPossibleOutcomes(WorkflowExecutionContext workflowContext, ActivityContext activityContext) | ||
{ | ||
return Outcomes(S["Done"]); | ||
} | ||
|
||
public override async Task<ActivityExecutionResult> ResumeAsync(WorkflowExecutionContext workflowContext, ActivityContext activityContext) | ||
{ | ||
if (await IsExpired()) | ||
{ | ||
workflowContext.LastResult = "TimerEvent"; | ||
return Outcomes("Done"); | ||
} | ||
|
||
return Halt(); | ||
} | ||
|
||
private async Task<bool> IsExpired() | ||
{ | ||
DateTime when; | ||
var now = _clock.UtcNow; | ||
if (UseSiteTimeZone) | ||
{ | ||
var timeZoneId = (await _siteService.GetSiteSettingsAsync()).TimeZoneId; | ||
now = _clock.ConvertToTimeZone(new DateTimeOffset(now), _clock.GetTimeZone(timeZoneId)).DateTime; | ||
} | ||
StartedTime ??= now; | ||
|
||
var schedule = CrontabSchedule.Parse(CronExpression); | ||
when = schedule.GetNextOccurrence(StartedTime.Value); | ||
return now >= when; | ||
} | ||
} | ||
} |
Oops, something went wrong.