public static void Main(string[] args) { var options = new CommandlineOptions { }; var parser = new Parser((settings) => { settings.HelpWriter = Console.Out; }); var result = parser.ParseArguments <CommandlineOptions>(args); if (result.Tag == ParserResultType.Parsed) { result.WithParsed((opts) => { options = opts; }); CreateProcessor(options); CreateWatcher(options); ScanDirectories(options); Console.WriteLine($"start watching for files is {options.Path} {options.Filter}"); CreateWebHostBuilder(args).Build().Run(); Console.WriteLine($"stop watching for files is {options.Path} {options.Filter}"); watcher.Dispose(); processor.Dispose(); } }
static void Main(string[] args) { IWatcher watcher = null; try { IConfigurator configurator = new MainConfigurator(); watcher = configurator.GetWatcher(); watcher.Start(); Console.WriteLine("FileWatcher started."); Console.WriteLine("Press 'q' to end."); while (Console.ReadKey().KeyChar != 'q') { ; } } catch (ArgumentException ex) { ExceptionHandle(ex); } catch (UnauthorizedAccessException ex) { ExceptionHandle(ex); } catch (DirectoryNotFoundException ex) { ExceptionHandle(ex); } finally { watcher?.Dispose(); } }
protected virtual void Dispose(bool disposing) { if (!disposed) { if (disposing) { _watcher.Dispose(); } disposed = true; } }
public void SetUp() { _scheduler = new TestScheduler(); _source = new SourceCache <Person, string>(p => p.Key); _watcher = _source.Connect().AsWatcher(_scheduler); _results = new ChangeSetAggregator <SelfObservingPerson, string> ( _source.Connect() .Transform(p => new SelfObservingPerson(_watcher.Watch(p.Key).Select(w => w.Current))) .DisposeMany() ); _cleanUp = Disposable.Create(() => { _results.Dispose(); _source.Dispose(); _watcher.Dispose(); }); }
public void SetUp() { _scheduler = new TestScheduler(); _source = new SourceCache<Person, string>(p => p.Key); _watcher = _source.Connect().AsWatcher(_scheduler); _results = new ChangeSetAggregator<SelfObservingPerson, string> ( _source.Connect() .Transform(p => new SelfObservingPerson(_watcher.Watch(p.Key).Select(w => w.Current))) .DisposeMany() ); _cleanUp = Disposable.Create(() => { _results.Dispose(); _source.Dispose(); _watcher.Dispose(); }); }
protected override void OnStop() { _folderWatcher?.Dispose(); }
static int Main(string[] args) { var app = new CommandLineApplication(); bool watching = false; IWatcher watcher = null; IServiceCollection services = new ServiceCollection(); app.HelpOption(); var optionFilePath = app.Option("-f|--file <FILEPATH>", "The relative or absolute path to the integration package file.", CommandOptionType.SingleValue) .IsRequired(errorMessage: "Filepath is required to run Integreat."); var optionWatch = app.Option("-w|--watch", "Optional. Set up file watcher for filepath.", CommandOptionType.NoValue); var optionWatchDuration = app.Option <int>("-wd|--watch-duration <DURATION_IN_SECONDS>", "Optional. How long (in seconds) the file watcher should be active.", CommandOptionType.SingleValue); app.OnExecute(() => { var filePath = optionFilePath.Value(); watching = optionWatch.HasValue(); var file = new Integreat.File(filePath); if (!watching && !file.Exists) { Console.WriteLine($"File '{file.FullPath}' not found."); return(1); } services.AddIntegreat() .AddBatchExecutable() .AddPowershellExecutable() .AddCSharpPluginExecutable() .AddSQLExecutable() .AddSettings(new IntegrationSettings() { DropDirectory = file.Directory, DropFileName = file.FileName }); IServiceProvider serviceProvider = services.BuildServiceProvider(); if (watching) { Console.WriteLine($"Watching for file '{file.FileName}' in directory '{file.Directory}'..."); watcher = serviceProvider.GetRequiredService <IWatcher>(); watcher.Initialize(); } else { Console.WriteLine($"Executing Integreat using file at '{filePath}'..."); serviceProvider.GetRequiredService <IProcessFactory>() .Create() .Execute(filePath); } return(0); }); var result = app.Execute(args); if (result == 0) { if (watching) { if (optionWatchDuration.HasValue() && optionWatchDuration.ParsedValue > 0) { Console.WriteLine($"Watching for {optionWatchDuration.ParsedValue} seconds..."); new AutoResetEvent(false).WaitOne(optionWatchDuration.ParsedValue * 1000); } else { Console.WriteLine($"Watching until dismissed..."); new AutoResetEvent(false).WaitOne(); } Console.WriteLine("Watcher dismissed."); watcher?.Dispose(); } } Console.WriteLine($"Integreat process ended with result {result}."); return(result); }
public void Dispose() { _watcher.Dispose(); _commander.Dispose(); }
public void Stop() { _watcher.ItemRead -= WatcherItemRead; _watcher.Dispose(); }