diff --git a/src/c#/GeneralUpdate.MiniBowl/Jbos/CheckClientJob.cs b/src/c#/GeneralUpdate.MiniBowl/Jbos/CheckClientJob.cs deleted file mode 100644 index 653d463916cda2886f92ffca34a8c4939c58dd83..0000000000000000000000000000000000000000 --- a/src/c#/GeneralUpdate.MiniBowl/Jbos/CheckClientJob.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Quartz; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace GeneralUpdate.MiniBowl.Jbos -{ - internal class CheckClientJob : IJob - { - public async Task Execute(IJobExecutionContext context) - { - if (!IsChromeRunning()) - { - Process.Start("chrome.exe"); - } - - await Task.CompletedTask; - } - - private bool IsChromeRunning() - { - foreach (var process in Process.GetProcesses()) - { - if (process.ProcessName.ToLower().Contains("chrome")) - return true; - } - return false; - } - } -} diff --git a/src/c#/GeneralUpdate.MiniBowl/MiniBowlBootstrap.cs b/src/c#/GeneralUpdate.MiniBowl/MiniBowlBootstrap.cs deleted file mode 100644 index 5704938eb222f1ed92ed2e8bc56d7762d20c902d..0000000000000000000000000000000000000000 --- a/src/c#/GeneralUpdate.MiniBowl/MiniBowlBootstrap.cs +++ /dev/null @@ -1,16 +0,0 @@ -using GeneralUpdate.MiniBowl.Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace GeneralUpdate.MiniBowl -{ - internal class MiniBowlBootstrap - { - void WithConfig(ProcessInfo processInfo) { } - - void Launch() { } - } -} diff --git a/src/c#/GeneralUpdate.MiniBowl/Model/ProcessInfo.cs b/src/c#/GeneralUpdate.MiniBowl/Model/ProcessInfo.cs deleted file mode 100644 index cee5c438633147ea31c47abbefd2291fbb1ece64..0000000000000000000000000000000000000000 --- a/src/c#/GeneralUpdate.MiniBowl/Model/ProcessInfo.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace GeneralUpdate.MiniBowl.Model -{ - public enum ProcessStatus - { - Run, - None, - Down - } - - internal class ProcessInfo - { - public string Name { get; set; } - - public int Id { get; set; } - - public ProcessStatus Status { get; set; } - - public string Path { get; set; } - } -} diff --git a/src/c#/GeneralUpdate.ProtectService/GeneralUpdate.ProtectService.csproj b/src/c#/GeneralUpdate.ProtectService/GeneralUpdate.ProtectService.csproj deleted file mode 100644 index 2ad93a2710905aea706bb1d74e5c8836cb91b8d7..0000000000000000000000000000000000000000 --- a/src/c#/GeneralUpdate.ProtectService/GeneralUpdate.ProtectService.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - - net8.0 - enable - enable - true - true - - - - - - - diff --git a/src/c#/GeneralUpdate.ProtectService/GeneralUpdate.ProtectService.http b/src/c#/GeneralUpdate.ProtectService/GeneralUpdate.ProtectService.http deleted file mode 100644 index 6b0e9b5849221d6771c87729f74a05c4214b5408..0000000000000000000000000000000000000000 --- a/src/c#/GeneralUpdate.ProtectService/GeneralUpdate.ProtectService.http +++ /dev/null @@ -1,11 +0,0 @@ -@GeneralUpdate.ProtectService_HostAddress = http://localhost:5276 - -GET {{GeneralUpdate.ProtectService_HostAddress}}/protect/ -Accept: application/json - -### - -GET {{GeneralUpdate.ProtectService_HostAddress}}/protect/1 -Accept: application/json - -### \ No newline at end of file diff --git a/src/c#/GeneralUpdate.ProtectService/Program.cs b/src/c#/GeneralUpdate.ProtectService/Program.cs deleted file mode 100644 index 8b1fca5dbc2b8c5eadb088bada2202b507480570..0000000000000000000000000000000000000000 --- a/src/c#/GeneralUpdate.ProtectService/Program.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Newtonsoft.Json; - -namespace GeneralUpdate.ProtectService -{ - public class Program - { - public static void Main(string[] args) - { - var builder = WebApplication.CreateSlimBuilder(args); - var app = builder.Build(); - var protectApi = app.MapGroup("/protect"); - protectApi.MapGet("/{backupJson}/{targetDir}", Restore); - app.Run(); - } - - internal static string Restore(string backupJson,string targetDirectory) - { - var backupObj = JsonConvert.DeserializeObject>>(backupJson); - while (backupObj?.Count > 0) - { - List currentList = backupObj.Pop(); - foreach (var filePath in currentList) - { - string fileName = Path.GetFileName(filePath); - string destFile = Path.Combine(targetDirectory, fileName); - File.Copy(filePath, destFile, true); - } - } - return backupJson; - } - } -} diff --git a/src/c#/GeneralUpdate.MiniBowl/GeneralUpdate.MiniBowl.csproj b/src/c#/GeneralUpdate.SystemService/GeneralUpdate.SystemService.csproj similarity index 53% rename from src/c#/GeneralUpdate.MiniBowl/GeneralUpdate.MiniBowl.csproj rename to src/c#/GeneralUpdate.SystemService/GeneralUpdate.SystemService.csproj index afc6d21bd9279e57d13f2536dde88a30a89841b2..b71655e1d1973821f46eab2903af9d2b1eaff577 100644 --- a/src/c#/GeneralUpdate.MiniBowl/GeneralUpdate.MiniBowl.csproj +++ b/src/c#/GeneralUpdate.SystemService/GeneralUpdate.SystemService.csproj @@ -1,14 +1,14 @@ - + - Library net8.0 - enable enable + enable + dotnet-GeneralUpdate.SystemService-bedd09fc-af1b-4a6f-ab25-948dc94428ae + - diff --git a/src/c#/GeneralUpdate.SystemService/Jobs/WillMessageJob.cs b/src/c#/GeneralUpdate.SystemService/Jobs/WillMessageJob.cs new file mode 100644 index 0000000000000000000000000000000000000000..9adb6efc0d4bed4acc9ca81b30820430bb8d67c9 --- /dev/null +++ b/src/c#/GeneralUpdate.SystemService/Jobs/WillMessageJob.cs @@ -0,0 +1,35 @@ +using Quartz; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GeneralUpdate.SystemService.Jobs +{ + internal class WillMessageJob : IJob + { + internal const string GROUP = "WillMessageGroup"; + internal const string TRIGGER = "WillMessageTrigger"; + private readonly ISchedulerFactory _schedulerFactory; + private IJobExecutionContext _jobExecutionContext; + + public WillMessageJob(ISchedulerFactory schedulerFactory) + { + _schedulerFactory = schedulerFactory; + } + + public Task Execute(IJobExecutionContext context) + { + _jobExecutionContext = context; + return ScanWillMessage(); + } + + private async Task ScanWillMessage() + { + // 暂停任务 + var scheduler = await _schedulerFactory.GetScheduler(); + await scheduler.PauseJob(_jobExecutionContext.JobDetail.Key); + } + } +} diff --git a/src/c#/GeneralUpdate.SystemService/PersistenceObjects/ProcessPersistence.cs b/src/c#/GeneralUpdate.SystemService/PersistenceObjects/ProcessPersistence.cs new file mode 100644 index 0000000000000000000000000000000000000000..3f4dfc5c9100e400f6a1027dc873fcaf4c177474 --- /dev/null +++ b/src/c#/GeneralUpdate.SystemService/PersistenceObjects/ProcessPersistence.cs @@ -0,0 +1,31 @@ +namespace GeneralUpdate.SystemService.PersistenceObjects +{ + internal enum ProcessStatus + { + /// + /// Processing has not yet begun. + /// + NotStarted, + /// + /// Processing completed. + /// + Completed, + /// + /// Processing failure. + /// + Failed + } + + internal class ProcessPersistence + { + public required string Name { get; set; } + + public required string Path { get; set; } + + public required string BackupPath { get; set; } + + public ProcessStatus Status { get; set; } + + public DateTime CreateTime { get; set; } + } +} diff --git a/src/c#/GeneralUpdate.SystemService/PersistenceObjects/WillMessagePersistence.cs b/src/c#/GeneralUpdate.SystemService/PersistenceObjects/WillMessagePersistence.cs new file mode 100644 index 0000000000000000000000000000000000000000..6e9f78d043286fa13b42b2d8206efcfd58ab8298 --- /dev/null +++ b/src/c#/GeneralUpdate.SystemService/PersistenceObjects/WillMessagePersistence.cs @@ -0,0 +1,7 @@ +namespace GeneralUpdate.SystemService.PersistenceObjects +{ + internal class WillMessagePersistence where T : class + { + public required List Messages { get; set; } + } +} diff --git a/src/c#/GeneralUpdate.SystemService/Program.cs b/src/c#/GeneralUpdate.SystemService/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..c4eee17d84428a0651dcb013174975df84954f3b --- /dev/null +++ b/src/c#/GeneralUpdate.SystemService/Program.cs @@ -0,0 +1,15 @@ +using GeneralUpdate.SystemService.Services; + +namespace GeneralUpdate.SystemService +{ + public class Program + { + public static void Main(string[] args) + { + var builder = Host.CreateApplicationBuilder(args); + builder.Services.AddHostedService(); + var host = builder.Build(); + host.Run(); + } + } +} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.ProtectService/Properties/launchSettings.json b/src/c#/GeneralUpdate.SystemService/Properties/launchSettings.json similarity index 44% rename from src/c#/GeneralUpdate.ProtectService/Properties/launchSettings.json rename to src/c#/GeneralUpdate.SystemService/Properties/launchSettings.json index d05c63b6157c923331e35af37936cec2d6a94fbe..ab9db06fa0d92187e7f4e1ab8988c61b9e2af1a6 100644 --- a/src/c#/GeneralUpdate.ProtectService/Properties/launchSettings.json +++ b/src/c#/GeneralUpdate.SystemService/Properties/launchSettings.json @@ -1,14 +1,11 @@ -{ +{ "$schema": "http://json.schemastore.org/launchsettings.json", "profiles": { - "http": { + "GeneralUpdate.SystemService": { "commandName": "Project", - "dotnetRunMessages": false, - "launchBrowser": false, - "launchUrl": "protect", - "applicationUrl": "http://localhost:5276", + "dotnetRunMessages": true, "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" + "DOTNET_ENVIRONMENT": "Development" } } } diff --git a/src/c#/GeneralUpdate.SystemService/Services/QuartzService.cs b/src/c#/GeneralUpdate.SystemService/Services/QuartzService.cs new file mode 100644 index 0000000000000000000000000000000000000000..dc693be1ddc0113503c4da3079ea1df7d0306eb5 --- /dev/null +++ b/src/c#/GeneralUpdate.SystemService/Services/QuartzService.cs @@ -0,0 +1,46 @@ +using GeneralUpdate.SystemService.Jobs; +using Quartz; +using Quartz.Impl; + +namespace GeneralUpdate.SystemService.Services +{ + internal class QuartzService : BackgroundService + { + private readonly ILogger _logger; + private IJobDetail _job; + private ITrigger _trigger; + private IScheduler _scheduler; + + public QuartzService(ILogger logger) + { + _logger = logger; + } + + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + _scheduler = await new StdSchedulerFactory().GetScheduler(); + await _scheduler.Start(); + + var runTime = DateBuilder.EvenMinuteDate(DateTimeOffset.UtcNow); + + _job = JobBuilder.Create() + .WithIdentity(nameof(WillMessageJob), WillMessageJob.GROUP) + .Build(); + _trigger = TriggerBuilder.Create() + .WithIdentity(WillMessageJob.TRIGGER, WillMessageJob.GROUP) + .StartAt(runTime) + .WithSimpleSchedule(x => x + .WithIntervalInMinutes(2) + .RepeatForever()) + .Build(); + + await _scheduler.ScheduleJob(_job, _trigger); + } + + public override async Task StopAsync(CancellationToken cancellationToken) + { + await base.StopAsync(cancellationToken); + await _scheduler?.Shutdown(); + } + } +} diff --git a/src/c#/GeneralUpdate.ProtectService/appsettings.Development.json b/src/c#/GeneralUpdate.SystemService/appsettings.Development.json similarity index 61% rename from src/c#/GeneralUpdate.ProtectService/appsettings.Development.json rename to src/c#/GeneralUpdate.SystemService/appsettings.Development.json index 0c208ae9181e5e5717e47ec1bd59368aebc6066e..b2dcdb67421cdf46236defda1c6fbf1d9eead5ee 100644 --- a/src/c#/GeneralUpdate.ProtectService/appsettings.Development.json +++ b/src/c#/GeneralUpdate.SystemService/appsettings.Development.json @@ -2,7 +2,7 @@ "Logging": { "LogLevel": { "Default": "Information", - "Microsoft.AspNetCore": "Warning" + "Microsoft.Hosting.Lifetime": "Information" } } } diff --git a/src/c#/GeneralUpdate.ProtectService/appsettings.json b/src/c#/GeneralUpdate.SystemService/appsettings.json similarity index 52% rename from src/c#/GeneralUpdate.ProtectService/appsettings.json rename to src/c#/GeneralUpdate.SystemService/appsettings.json index 10f68b8c8b4f796baf8ddeee7551b6a52b9437cc..b2dcdb67421cdf46236defda1c6fbf1d9eead5ee 100644 --- a/src/c#/GeneralUpdate.ProtectService/appsettings.json +++ b/src/c#/GeneralUpdate.SystemService/appsettings.json @@ -2,8 +2,7 @@ "Logging": { "LogLevel": { "Default": "Information", - "Microsoft.AspNetCore": "Warning" + "Microsoft.Hosting.Lifetime": "Information" } - }, - "AllowedHosts": "*" + } } diff --git a/src/c#/GeneralUpdate.sln b/src/c#/GeneralUpdate.sln index 825847fc4afef5b451b7bfab6d04ea2a54c35d0a..0d5fd31e450b976b398573ecd7c4ebec962d0e62 100644 --- a/src/c#/GeneralUpdate.sln +++ b/src/c#/GeneralUpdate.sln @@ -43,7 +43,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GeneralUpdate.Maui.OSS", "G EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GeneralUpdate.OSSClient", "GeneralUpdate.OSSClient\GeneralUpdate.OSSClient.csproj", "{2877DCA1-7EA6-42E9-A1C2-399B51E24893}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GeneralUpdate.MiniBowl", "GeneralUpdate.MiniBowl\GeneralUpdate.MiniBowl.csproj", "{3CF53050-6A42-4ACE-8CF6-80FA3ACD92E6}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GeneralUpdate.SystemService", "GeneralUpdate.SystemService\GeneralUpdate.SystemService.csproj", "{8CE233CF-F337-4579-983D-7327567634FA}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -125,10 +125,10 @@ Global {2877DCA1-7EA6-42E9-A1C2-399B51E24893}.Release|Any CPU.ActiveCfg = Release|Any CPU {2877DCA1-7EA6-42E9-A1C2-399B51E24893}.Release|Any CPU.Build.0 = Release|Any CPU {2877DCA1-7EA6-42E9-A1C2-399B51E24893}.Release|Any CPU.Deploy.0 = Release|Any CPU - {3CF53050-6A42-4ACE-8CF6-80FA3ACD92E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3CF53050-6A42-4ACE-8CF6-80FA3ACD92E6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3CF53050-6A42-4ACE-8CF6-80FA3ACD92E6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3CF53050-6A42-4ACE-8CF6-80FA3ACD92E6}.Release|Any CPU.Build.0 = Release|Any CPU + {8CE233CF-F337-4579-983D-7327567634FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8CE233CF-F337-4579-983D-7327567634FA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8CE233CF-F337-4579-983D-7327567634FA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8CE233CF-F337-4579-983D-7327567634FA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -151,7 +151,7 @@ Global {9A28F525-124A-4019-8F09-BC48030E0E70} = {50B6BB53-63A9-414B-9BB0-79A69EEF6785} {C4BDA544-2A6E-442C-B7D0-32CD7A996933} = {91F059E6-7AD3-4FB7-9604-30A7849C6EFF} {2877DCA1-7EA6-42E9-A1C2-399B51E24893} = {74BE0282-A10D-4A81-A0F0-FAA79A6152B7} - {3CF53050-6A42-4ACE-8CF6-80FA3ACD92E6} = {91F059E6-7AD3-4FB7-9604-30A7849C6EFF} + {8CE233CF-F337-4579-983D-7327567634FA} = {91F059E6-7AD3-4FB7-9604-30A7849C6EFF} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {A7B2D0AD-E000-4749-BAC0-FF21B9872805}