/// <summary> /// Execute the job. /// </summary> public void Execute() { try { InitExecutionContext(); _moduleManager.OnStart(); var handlers = _handlerCreator.Create(_message); foreach (var handler in handlers) { handler.Handle(_message); if (_context.DoNotContinueDispatchingCurrentMessageToHandlers) { break; } } } catch (Exception ex) { _log.Error(string.Format("Error handling message {0}.", typeof(TMessage).Name), ex); _moduleManager.OnError(ex); } finally { _moduleManager.OnFinished(); } }
/// <summary> /// Thread delegate executing the jobs. /// </summary> private void ExecutionThread() { try { while (!_isDisposed) { try { IJob job = _jobs.Take(); job.Execute(); } catch (ObjectDisposedException) { // object has been disposed // we don't have anything to do, therefore leave lopp. break; } catch (Exception ex) { _log.Error(@"Execution of job failed.", ex); } } } finally { // this finally block will always get executed. _log.Info(@"Worker thread closed."); } }
/// <summary> /// Execute the job. /// </summary> public void Execute() { try { InitExecutionContext(); _moduleManager.OnStart(); _action.Invoke(); } catch (Exception ex) { _log.Error("Error execution action.", ex); _moduleManager.OnError(ex); } finally { _moduleManager.OnFinished(); } }
/// <summary> /// Scan the file, which may or may not be an actual assembly. /// </summary> private IEnumerable <Type> ScanPossibleAssembly(string fileName, Predicate <Type> targeType) { IEnumerable <Type> handlers = null; try { AssemblyName assemblyName = AssemblyName.GetAssemblyName(fileName); Assembly assembly = Assembly.Load(assemblyName); handlers = ScanAssembly(assembly, targeType); } catch (ReflectionTypeLoadException ex) { // assembly could not be scanned because of missing dependencies. _log.Error(@"Error scanning assembly.", ex); } catch (BadImageFormatException) { // file is not a .net assembly. _log.Info(@"Skip file scanning. File is not a .NET assembly: " + fileName); } return(handlers ?? new Type[0]); }