xxe 2 anni fa
parent
commit
68f21dfd1e
9 ha cambiato i file con 268 aggiunte e 2 eliminazioni
  1. +1
    -1
      HKCardIN/HKCardIN.csproj
  2. +9
    -0
      HKCardOUT/HKCardOUT.csproj
  3. +17
    -0
      HKCardOUT/QuartzUtil/IQuartzCore.cs
  4. +22
    -0
      HKCardOUT/QuartzUtil/Job/QuartzJob.cs
  5. +145
    -0
      HKCardOUT/QuartzUtil/QuartzCore.cs
  6. +16
    -0
      HKCardOUT/QuartzUtil/QuartzCoreFactory.cs
  7. +44
    -0
      HKCardOUT/QuartzUtil/QuartzMap.cs
  8. +10
    -1
      HKCardOUT/Views/RootView.xaml.cs
  9. +4
    -0
      HKCardOUT/options.json

+ 1
- 1
HKCardIN/HKCardIN.csproj Vedi File

@@ -24,8 +24,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="HandyControls" Version="3.4.1" />
<PackageReference Include="SqlSugarCore" Version="5.1.2.7" />
<PackageReference Include="Stylet" Version="1.3.6" />
<PackageReference Include="SqlSugarCore" Version="5.1.2.7" />
<PackageReference Include="XExten.Advance" Version="1.2.4.2-preview" />
</ItemGroup>
<ItemGroup>


+ 9
- 0
HKCardOUT/HKCardOUT.csproj Vedi File

@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<UseWindowsForms>true</UseWindowsForms>
<TargetFramework>net6.0-windows</TargetFramework>
<SatelliteResourceLanguages>zh-Hans</SatelliteResourceLanguages>
<UseWPF>true</UseWPF>
@@ -20,6 +21,14 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="HandyControls" Version="3.4.1" />
<PackageReference Include="Quartz" Version="3.4.0" />
<PackageReference Include="Stylet" Version="1.3.6" />
<PackageReference Include="SqlSugarCore" Version="5.1.2.7" />
<PackageReference Include="XExten.Advance" Version="1.2.4.2-preview" />
</ItemGroup>
<ItemGroup>
<None Update="options.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

+ 17
- 0
HKCardOUT/QuartzUtil/IQuartzCore.cs Vedi File

@@ -0,0 +1,17 @@
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HKCardOUT.QuartzUtil
{
public interface IQuartzCore
{
void StopResumeJob(QuartzMap quartz);
void ResumeJob(QuartzMap quartz);
void StopJob();
Task<String> AddJob<T>(QuartzMap quartz) where T : IJob;
}
}

+ 22
- 0
HKCardOUT/QuartzUtil/Job/QuartzJob.cs Vedi File

@@ -0,0 +1,22 @@
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HKCardOUT.QuartzUtil.Job
{
public class QuartzJob : IJob
{
public async Task Execute(IJobExecutionContext context)
{
switch (context.JobDetail.Key.Group)
{
default:
await Task.CompletedTask;
break;
}
}
}
}

+ 145
- 0
HKCardOUT/QuartzUtil/QuartzCore.cs Vedi File

@@ -0,0 +1,145 @@
using Quartz.Impl;
using Quartz;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Org.BouncyCastle.Math.EC.ECCurve;

namespace HKCardOUT.QuartzUtil
{
public class QuartzCore: IQuartzCore
{
private Task<IScheduler> instance;
/// <summary>
/// 初始化任务调度器
/// </summary>
public Task<IScheduler> Instance
{
get
{
if (instance != null)
return instance;
else
{
NameValueCollection props = new NameValueCollection { { "quartz.serializer.type", "binary" } };
instance = new StdSchedulerFactory(props).GetScheduler();
return instance;
}
}
}
/// <summary>
/// 创建简单任务
/// </summary>
/// <param name="quartz"></param>
/// <returns></returns>
protected ITrigger CreateSimpleTrigger(QuartzMap quartz)
{
if (quartz.RunTimes > 0)
{
return TriggerBuilder.Create().WithIdentity(quartz.JobName, quartz.JobGroup)
.StartAt(quartz.StartTime).EndAt(quartz.EndTime)
.WithSimpleSchedule(t => t.WithIntervalInSeconds(quartz.IntervalSecond)
.WithRepeatCount(quartz.RunTimes)).ForJob(quartz.JobName, quartz.JobGroup)
.WithDescription(quartz.JobDetail).Build();
}
else
{
//无限循环执行
return TriggerBuilder.Create().WithIdentity(quartz.JobName, quartz.JobGroup)
.StartAt(quartz.StartTime).EndAt(quartz.EndTime)
.WithSimpleSchedule(t => t.WithIntervalInSeconds(quartz.IntervalSecond)
.RepeatForever()).ForJob(quartz.JobName, quartz.JobGroup)
.WithDescription(quartz.JobDetail).Build();
}
}
/// <summary>
/// 创建表达式任务
/// </summary>
/// <param name="quartz"></param>
/// <returns></returns>
protected ITrigger CreateCronTrigger(QuartzMap quartz)
{
return TriggerBuilder.Create().WithIdentity(quartz.JobName, quartz.JobGroup)
.StartAt(quartz.StartTime).EndAt(quartz.EndTime)
.WithCronSchedule(quartz.Cron).ForJob(quartz.JobName, quartz.JobGroup)
.WithDescription(quartz.JobDetail).Build();
}
/// <summary>
/// 暂停指定任务
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="quartz"></param>
/// <returns></returns>
public async void StopResumeJob(QuartzMap quartz)
{
var key = new JobKey(quartz.JobName, quartz.JobGroup);
if (await Instance.Result.CheckExists(key))
await Instance.Result.PauseJob(key);
}
/// <summary>
/// 恢复运行已经暂停的指定任务
/// </summary>
/// <param name="quartz"></param>
public async void ResumeJob(QuartzMap quartz)
{
try
{
//检查任务是否存在
var key = new JobKey(quartz.JobName, quartz.JobGroup);
if (await Instance.Result.CheckExists(key))
await Instance.Result.ResumeJob(key);
}
catch (Exception)
{
throw new Exception("恢复任务失败!");
}
}
/// <summary>
/// 停止任务
/// </summary>
public async void StopJob()
{
try
{
//判断调度是否已经关闭
if (!Instance.Result.IsShutdown)
//等待任务运行完成
await Instance.Result.Shutdown();
}
catch (Exception)
{
throw new Exception("停止任务失败!");
}
}
/// <summary>
/// 添加任务指定实现IJob接口的类
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="quartz"></param>
/// <returns></returns>
public async Task<String> AddJob<T>(QuartzMap quartz) where T : IJob
{
try
{
await Instance.Result.Start();
JobKey key = new JobKey(quartz.JobName, quartz.JobGroup);
//任务存在则先删除
if (await Instance.Result.CheckExists(key))
await Instance.Result.DeleteJob(key);
IJobDetail job = JobBuilder.CreateForAsync<T>().WithIdentity(quartz.JobName, quartz.JobGroup).Build();
if (!string.IsNullOrEmpty(quartz.Cron) && CronExpression.IsValidExpression(quartz.Cron))
await Instance.Result.ScheduleJob(job, CreateCronTrigger(quartz));
else
await Instance.Result.ScheduleJob(job, CreateSimpleTrigger(quartz));
return "添加任务成功!";
}
catch (Exception)
{
throw new Exception("添加任务出错!");
}
}
}
}

+ 16
- 0
HKCardOUT/QuartzUtil/QuartzCoreFactory.cs Vedi File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HKCardOUT.QuartzUtil
{
public class QuartzCoreFactory
{
public static IQuartzCore QuartzCore()
{
return new QuartzCore();
}
}
}

+ 44
- 0
HKCardOUT/QuartzUtil/QuartzMap.cs Vedi File

@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HKCardOUT.QuartzUtil
{
public class QuartzMap
{
/// <summary>
/// 任务分组
/// </summary>
public string JobGroup { get; set; }
/// <summary>
/// 任务名称
/// </summary>
public string JobName { get; set; }
/// <summary>
/// 开始时间
/// </summary>
public DateTime StartTime { get; set; }
/// <summary>
/// 结束时间
/// </summary>
public DateTime? EndTime { get; set; }
/// <summary>
/// 执行任务间隔时间单位秒
/// </summary>
public int IntervalSecond { get; set; }
/// <summary>
/// 执行次数
/// </summary>
public int RunTimes { get; set; }
/// <summary>
/// 时间表达式
/// </summary>
public string Cron { get; set; }
/// <summary>
/// 任务描述
/// </summary>
public string JobDetail { get; set; }
}
}

+ 10
- 1
HKCardOUT/Views/RootView.xaml.cs Vedi File

@@ -1,5 +1,7 @@
using System.Windows;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Media;

namespace HKCardOUT.Views
@@ -9,6 +11,13 @@ namespace HKCardOUT.Views
public RootView()
{
InitializeComponent();
if (Screen.AllScreens.Count() >= 2)
{
Dispatcher.Invoke(() =>
{
//显示广告屏幕
});
}
}
}
}

+ 4
- 0
HKCardOUT/options.json Vedi File

@@ -0,0 +1,4 @@
{
"SaasRoute": "",
"Cron": ""
}

Caricamento…
Annulla
Salva