private async Task InvokeOnFirstErrorHooksAsync(WatcherConfiguration watcherConfiguration, Exception exception) { watcherConfiguration.Hooks.OnFirstError.Execute(exception); await watcherConfiguration.Hooks.OnFirstErrorAsync.ExecuteAsync(exception); _configuration.GlobalWatcherHooks.OnFirstError.Execute(exception); await _configuration.GlobalWatcherHooks.OnFirstErrorAsync.ExecuteAsync(exception); }
private async Task InvokeOnStartHooksAsync(WatcherConfiguration watcherConfiguration, IWatcherCheck check) { watcherConfiguration.Hooks.OnStart.Execute(check); await watcherConfiguration.Hooks.OnStartAsync.ExecuteAsync(check); _configuration.GlobalWatcherHooks.OnStart.Execute(check); await _configuration.GlobalWatcherHooks.OnStartAsync.ExecuteAsync(check); }
private async Task InvokeOnCompletedHooksAsync(WatcherConfiguration watcherConfiguration, IWardenCheckResult checkResult) { watcherConfiguration.Hooks.OnCompleted.Execute(checkResult); await watcherConfiguration.Hooks.OnCompletedAsync.ExecuteAsync(checkResult); _configuration.GlobalWatcherHooks.OnCompleted.Execute(checkResult); await _configuration.GlobalWatcherHooks.OnCompletedAsync.ExecuteAsync(checkResult); }
private async Task InvokeOnFirstFailureHooksAsync(WatcherConfiguration watcherConfiguration, IWardenCheckResult checkResult) { watcherConfiguration.Hooks.OnFirstFailure.Execute(checkResult); await watcherConfiguration.Hooks.OnFirstFailureAsync.ExecuteAsync(checkResult); _configuration.GlobalWatcherHooks.OnFirstFailure.Execute(checkResult); await _configuration.GlobalWatcherHooks.OnFirstFailureAsync.ExecuteAsync(checkResult); }
private async Task InvokeOnStartHooksAsync(WatcherConfiguration watcherConfiguration, IWatcherCheck check) { _logger.Trace($"Executing Watcher: {check.WatcherName} hooks OnStart."); watcherConfiguration.Hooks.OnStart.Execute(check); _logger.Trace($"Executing Watcher: {check.WatcherName} hooks OnStartAsync."); await watcherConfiguration.Hooks.OnStartAsync.ExecuteAsync(check); _logger.Trace("Executing Global Watcher hooks OnStart."); _configuration.GlobalWatcherHooks.OnStart.Execute(check); _logger.Trace("Executing Global Watcher hooks OnStartAsync."); await _configuration.GlobalWatcherHooks.OnStartAsync.ExecuteAsync(check); }
private async Task InvokeOnFirstErrorHooksAsync(WatcherConfiguration watcherConfiguration, Exception exception) { _logger.Trace($"Executing Watcher: {watcherConfiguration.Watcher.Name} hooks OnFirstError."); watcherConfiguration.Hooks.OnFirstError.Execute(exception); _logger.Trace($"Executing Watcher: {watcherConfiguration.Watcher.Name} hooks OnFirstErrorAsync."); await watcherConfiguration.Hooks.OnFirstErrorAsync.ExecuteAsync(exception); _logger.Trace("Executing Global Watcher OnFirstError OnError."); _configuration.GlobalWatcherHooks.OnFirstError.Execute(exception); _logger.Trace("Executing Global Watcher OnFirstErrorAsync OnError."); await _configuration.GlobalWatcherHooks.OnFirstErrorAsync.ExecuteAsync(exception); }
private async Task InvokeOnCompletedHooksAsync(WatcherConfiguration watcherConfiguration, IWardenCheckResult checkResult) { _logger.Trace($"Executing Watcher: {checkResult.WatcherCheckResult.WatcherName} hooks OnCompleted."); watcherConfiguration.Hooks.OnCompleted.Execute(checkResult); _logger.Trace($"Executing Watcher: {checkResult.WatcherCheckResult.WatcherName} hooks OnCompletedAsync."); await watcherConfiguration.Hooks.OnCompletedAsync.ExecuteAsync(checkResult); _logger.Trace("Executing Global Watcher hooks OnCompleted."); _configuration.GlobalWatcherHooks.OnCompleted.Execute(checkResult); _logger.Trace("Executing Global Watcher hooks OnCompletedAsync."); await _configuration.GlobalWatcherHooks.OnCompletedAsync.ExecuteAsync(checkResult); }
private async Task <IList <WatcherExecutionResult> > TryExecuteWatcherCheckAndHooksAsync( WatcherConfiguration watcherConfiguration) { var startedAt = _configuration.DateTimeProvider(); var watcher = watcherConfiguration.Watcher; IWardenCheckResult wardenCheckResult = null; var results = new List <WatcherExecutionResult>(); try { await InvokeOnStartHooksAsync(watcherConfiguration, WatcherCheck.Create(watcher)); _logger.Info($"Executing Watcher: {watcher.Name}."); var watcherCheckResult = await watcher.ExecuteAsync(); _logger.Info($"Completed executing Watcher: {watcher.Name}. " + $"Is valid: {watcherCheckResult.IsValid}. " + $"Description: {watcherCheckResult.Description}"); var completedAt = _configuration.DateTimeProvider(); wardenCheckResult = WardenCheckResult.Create(watcherCheckResult, startedAt, completedAt); var watcherResults = await ExecuteWatcherCheckAsync(watcher, watcherCheckResult, wardenCheckResult, watcherConfiguration); results.AddRange(watcherResults); } catch (Exception exception) { _logger.Error($"There was an error while executing Watcher: {watcher.Name}.", exception); var completedAt = _configuration.DateTimeProvider(); wardenCheckResult = WardenCheckResult.Create(WatcherCheckResult.Create(watcher, false, exception.Message), startedAt, completedAt, exception); results.Add(new WatcherExecutionResult(watcher, WatcherResultState.Error, GetPreviousWatcherState(watcher), wardenCheckResult, exception)); await UpdateWatcherResultStateAndExecuteHooksPossibleAsync(watcher, WatcherResultState.Error, () => InvokeOnFirstErrorHooksAsync(watcherConfiguration, exception)); var wardenException = new WardenException("There was an error while executing Warden " + $"caused by watcher: '{watcher.Name}'.", exception); await InvokeOnErrorHooksAsync(watcherConfiguration, wardenException); } finally { await InvokeOnCompletedHooksAsync(watcherConfiguration, wardenCheckResult); } return(results); }
private async Task<IList<WatcherExecutionResult>> TryExecuteWatcherChecksAndHooksAsync( WatcherConfiguration watcherConfiguration) { var results = new List<WatcherExecutionResult>(); var intervals = _configuration.Watchers .OrderBy(x => x.Interval) .Select(x => x.Interval.TotalMilliseconds); var max = intervals.Max(); var numberOfExecutions = max/watcherConfiguration.Interval.TotalMilliseconds; for (var i = 0; i < numberOfExecutions; i++) { var watcherResults = await TryExecuteWatcherCheckAndHooksAsync(watcherConfiguration); results.AddRange(watcherResults); await Task.Delay(watcherConfiguration.Interval); } return results; }
/// <summary> /// Adds the watcher to the collection. /// Hooks for this particular watcher can be configured via the lambda expression. /// </summary> /// <param name="watcher">Instance of IWatcher.</param> /// <param name="hooks">Optional lambda expression for configuring the watcher hooks.</param> /// <returns>Instance of fluent builder for the WardenConfiguration.</returns> public Builder AddWatcher(IWatcher watcher, Action <WatcherHooksConfiguration.Builder> hooks = null) { var hooksConfiguration = WatcherHooksConfiguration.Empty; if (hooks != null) { var hooksConfigurationBuilder = new WatcherHooksConfiguration.Builder(); hooks(hooksConfigurationBuilder); hooksConfiguration = hooksConfigurationBuilder.Build(); } var watcherConfiguration = WatcherConfiguration.Create(watcher) .WithHooks(hooksConfiguration) .Build(); _configuration.Watchers.Add(watcherConfiguration); return(this); }
private async Task <IList <WatcherExecutionResult> > TryExecuteWatcherChecksAndHooksAsync( WatcherConfiguration watcherConfiguration) { var results = new List <WatcherExecutionResult>(); var intervals = _configuration.Watchers .OrderBy(x => x.Interval) .Select(x => x.Interval.TotalMilliseconds); var max = intervals.Max(); var numberOfExecutions = max / watcherConfiguration.Interval.TotalMilliseconds; for (var i = 0; i < numberOfExecutions; i++) { var watcherResults = await TryExecuteWatcherCheckAndHooksAsync(watcherConfiguration); results.AddRange(watcherResults); await Task.Delay(watcherConfiguration.Interval); } return(results); }
public SettingsForm( LoRConfiguration lorConfiguration, WatcherConfiguration watcherConfiguration, LoggerSettings loggerSettings, CancellationTokenSource tokenSource, NotifyIcon trayIcon) { this.lorConfiguration = lorConfiguration; this.watcherConfiguration = watcherConfiguration; this.loggerSettings = loggerSettings; this.cancellationTokenSource = tokenSource; this.trayIcon = trayIcon; InitializeComponent(); using (var stream = File.OpenRead($@"{Directory.GetCurrentDirectory()}\wwwroot\favicon.ico")) { this.Icon = new Icon(stream); } }
private async Task TryExecuteWatcherCheckAndHooksAsync(WatcherConfiguration watcherConfiguration, IList <WatcherExecutionResult> results) { var startedAt = _configuration.DateTimeProvider(); var watcher = watcherConfiguration.Watcher; IWardenCheckResult wardenCheckResult = null; try { await InvokeOnStartHooksAsync(watcherConfiguration, WatcherCheck.Create(watcher)); var watcherCheckResult = await watcher.ExecuteAsync(); var completedAt = _configuration.DateTimeProvider(); wardenCheckResult = WardenCheckResult.Create(watcherCheckResult, startedAt, completedAt); await ExecuteWatcherCheckAsync(watcher, watcherCheckResult, wardenCheckResult, watcherConfiguration, results); } catch (Exception exception) { var completedAt = _configuration.DateTimeProvider(); wardenCheckResult = WardenCheckResult.Create(WatcherCheckResult.Create(watcher, false), startedAt, completedAt, exception); results.Add(new WatcherExecutionResult(watcher, WatcherResultState.Error, GetPreviousWatcherState(watcher), wardenCheckResult, exception)); await UpdateWatcherResultStateAndExecuteHooksPossibleAsync(watcher, WatcherResultState.Error, () => InvokeOnFirstErrorHooksAsync(watcherConfiguration, exception)); var wardenException = new WardenException("There was an error while executing Warden " + $"caused by watcher: '{watcher.Name}'.", exception); await InvokeOnErrorHooksAsync(watcherConfiguration, wardenException); } finally { await InvokeOnCompletedHooksAsync(watcherConfiguration, wardenCheckResult); } }
private async Task<IList<WatcherExecutionResult>> TryExecuteWatcherCheckAndHooksAsync(WatcherConfiguration watcherConfiguration) { var startedAt = _configuration.DateTimeProvider(); var watcher = watcherConfiguration.Watcher; IWardenCheckResult wardenCheckResult = null; var results = new List<WatcherExecutionResult>(); try { await InvokeOnStartHooksAsync(watcherConfiguration, WatcherCheck.Create(watcher)); var watcherCheckResult = await watcher.ExecuteAsync(); var completedAt = _configuration.DateTimeProvider(); wardenCheckResult = WardenCheckResult.Create(watcherCheckResult, startedAt, completedAt); var watcherResults = await ExecuteWatcherCheckAsync(watcher, watcherCheckResult, wardenCheckResult, watcherConfiguration); results.AddRange(watcherResults); } catch (Exception exception) { var completedAt = _configuration.DateTimeProvider(); wardenCheckResult = WardenCheckResult.Create(WatcherCheckResult.Create(watcher, false), startedAt, completedAt, exception); results.Add(new WatcherExecutionResult(watcher, WatcherResultState.Error, GetPreviousWatcherState(watcher), wardenCheckResult, exception)); await UpdateWatcherResultStateAndExecuteHooksPossibleAsync(watcher, WatcherResultState.Error, () => InvokeOnFirstErrorHooksAsync(watcherConfiguration, exception)); var wardenException = new WardenException("There was an error while executing Warden " + $"caused by watcher: '{watcher.Name}'.", exception); await InvokeOnErrorHooksAsync(watcherConfiguration, wardenException); } finally { await InvokeOnCompletedHooksAsync(watcherConfiguration, wardenCheckResult); } return results; }
private async Task <IList <WatcherExecutionResult> > ExecuteWatcherCheckAsync(IWatcher watcher, IWatcherCheckResult watcherCheckResult, IWardenCheckResult wardenCheckResult, WatcherConfiguration watcherConfiguration) { var results = new List <WatcherExecutionResult>(); if (watcherCheckResult.IsValid) { var result = wardenCheckResult; results.Add(new WatcherExecutionResult(watcher, WatcherResultState.Success, GetPreviousWatcherState(watcher), result)); await UpdateWatcherResultStateAndExecuteHooksPossibleAsync(watcher, WatcherResultState.Success, () => InvokeOnFirstSuccessHooksAsync(watcherConfiguration, result), executeIfLatestStateIsNotSet : false); await InvokeOnSuccessHooksAsync(watcherConfiguration, wardenCheckResult); } else { var result = wardenCheckResult; results.Add(new WatcherExecutionResult(watcher, WatcherResultState.Failure, GetPreviousWatcherState(watcher), result)); await UpdateWatcherResultStateAndExecuteHooksPossibleAsync(watcher, WatcherResultState.Failure, () => InvokeOnFirstFailureHooksAsync(watcherConfiguration, result)); await InvokeOnFailureHooksAsync(watcherConfiguration, wardenCheckResult); } return(results); }
private async Task<IList<WatcherExecutionResult>> ExecuteWatcherCheckAsync(IWatcher watcher, IWatcherCheckResult watcherCheckResult, IWardenCheckResult wardenCheckResult, WatcherConfiguration watcherConfiguration) { var results = new List<WatcherExecutionResult>(); if (watcherCheckResult.IsValid) { var result = wardenCheckResult; results.Add(new WatcherExecutionResult(watcher, WatcherResultState.Success, GetPreviousWatcherState(watcher), result)); await UpdateWatcherResultStateAndExecuteHooksPossibleAsync(watcher, WatcherResultState.Success, () => InvokeOnFirstSuccessHooksAsync(watcherConfiguration, result), executeIfLatestStateIsNotSet: false); await InvokeOnSuccessHooksAsync(watcherConfiguration, wardenCheckResult); } else { var result = wardenCheckResult; results.Add(new WatcherExecutionResult(watcher, WatcherResultState.Failure, GetPreviousWatcherState(watcher), result)); await UpdateWatcherResultStateAndExecuteHooksPossibleAsync(watcher, WatcherResultState.Failure, () => InvokeOnFirstFailureHooksAsync(watcherConfiguration, result)); await InvokeOnFailureHooksAsync(watcherConfiguration, wardenCheckResult); } return results; }