|
|
@ -2,6 +2,7 @@ using System; |
|
|
|
using System.Collections.Concurrent; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Diagnostics; |
|
|
|
using System.IO; |
|
|
|
using System.Linq; |
|
|
|
using System.Net; |
|
|
|
using System.Threading; |
|
|
@ -21,6 +22,7 @@ public class JobHostdService : BackgroundService, IApplicationService |
|
|
|
{ |
|
|
|
private readonly object _lockObj = new object(); |
|
|
|
private readonly IServiceProvider _serviceProvider; |
|
|
|
private FileSystemWatcher _watcher; |
|
|
|
private CancellationToken _stoppingToken; |
|
|
|
|
|
|
|
public JobHostdService(IServiceProvider serviceProvider) |
|
|
@ -28,6 +30,40 @@ public class JobHostdService : BackgroundService, IApplicationService |
|
|
|
this._serviceProvider = serviceProvider; |
|
|
|
} |
|
|
|
|
|
|
|
public override Task StartAsync(CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"); |
|
|
|
var filter = "*.js"; |
|
|
|
this._watcher = new FileSystemWatcher(path, filter); |
|
|
|
this._watcher.NotifyFilter = NotifyFilters.Attributes |
|
|
|
| NotifyFilters.CreationTime |
|
|
|
| NotifyFilters.DirectoryName |
|
|
|
| NotifyFilters.FileName |
|
|
|
| NotifyFilters.LastAccess |
|
|
|
| NotifyFilters.LastWrite |
|
|
|
| NotifyFilters.Security |
|
|
|
| NotifyFilters.Size; |
|
|
|
this._watcher.Created += _watcher_Created; |
|
|
|
this._watcher.Deleted += _watcher_Created; |
|
|
|
this._watcher.Changed += _watcher_Created; |
|
|
|
this._watcher.Renamed += _watcher_Created; |
|
|
|
this._watcher.IncludeSubdirectories = true; |
|
|
|
this._watcher.EnableRaisingEvents = true; |
|
|
|
return base.StartAsync(cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
private void _watcher_Created(object sender, FileSystemEventArgs e) |
|
|
|
{ |
|
|
|
using var scope = this._serviceProvider.CreateScope(); |
|
|
|
scope.ServiceProvider.GetRequiredService<IHubContext<PageHub>>().Clients.All.ServerToClient("Refresh", e.FullPath, ""); |
|
|
|
} |
|
|
|
|
|
|
|
public override Task StopAsync(CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
this._watcher?.Dispose(); |
|
|
|
return base.StopAsync(cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
public static List<Type> ServiceTypes { get; private set; } |
|
|
|
public ConcurrentDictionary<JobItem, Tuple<CancellationTokenSource, Thread>> Jobs { get; } = new(); |
|
|
|
|
|
|
|