public class AwesomeFolderWatcher<TContext>
{
private readonly FileSystemWatcher watcher;
private readonly IHttpApplication<TContext> application;
private readonly IFeatureCollection features;
public AwesomeFolderWatcher(IHttpApplication<TContext> application,
IFeatureCollection features)
{
var path = features.Get<IServerAddressesFeature>().Addresses.
FirstOrDefault();
this.watcher = new FileSystemWatcher(path);
this.watcher.EnableRaisingEvents = true;
this.application = application;
this.features = features;
}
public void Watch()
{
watcher.Created += async (sender, e) =>
{
var context = (HostingApplication.Context)(object)application.
CreateContext(features);
context.HttpContext = new AwesomeHttpContext(features,
e.FullPath);
await application.ProcessRequestAsync((TContext)(object)context);
context.HttpContext.Response.OnCompleted(null, null);
};
Task.Run(() => watcher.WaitForChanged(WatcherChangeTypes.All));
}
}
When AwesomeServer starts up, a new instance of AwesomeFolderWatcher is created that is responsible for watching a specific folder. To put things in perspective, AwesomeFolderWatcher to AwesomeServer is the same as Libuv is to Kestrel.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.