internal static IJobContext FromEventArgs(object sender, AlarmSourceEventArgs args) { IAlarmSource source = sender as IAlarmSource; Assertions.AssertNotNull(sender, "sender"); return new JobContext() { AlarmSourceName = source.GetType().Name, Parameters = args.Parameters, }; }
private void OnNewAlarm(AlarmSourceEventArgs e) { var copy = NewAlarm; if (copy != null) { copy(this, e); } }
private void AlarmSource_NewAlarm(object sender, AlarmSourceEventArgs e) { IAlarmSource source = (IAlarmSource)sender; // Sanity-checks if (e.Operation == null) { Logger.Instance.LogFormat(LogType.Warning, this, "Alarm Source '{0}' did not return an operation! This may indicate that parsing an operation has failed. Please check the log!", source.GetType().FullName); return; } try { // If there is no timestamp, use the current time. Not too good but better than MinValue :-/ if (e.Operation.Timestamp.Year == 1) { Logger.Instance.LogFormat(LogType.Warning, this, "Could not parse timestamp from the fax. Using the current time as the timestamp."); e.Operation.Timestamp = DateTime.Now; } // Download the route plan information (if data is meaningful) DownloadRoutePlan(e.Operation); // Grant the operation a new Id e.Operation.Id = _operationStore.GetNextOperationId(); foreach (IJob job in _jobs) { // Run the job. If the job fails, ignore that exception as well but log it too! try { job.DoJob(e.Operation); } catch (Exception ex) { // Be careful when processing the jobs, we don't want a malicious job to terminate the process! Logger.Instance.LogFormat(LogType.Warning, this, string.Format("An error occurred while processing job '{0}'!", job.GetType().Name)); Logger.Instance.LogException(this, ex); } } } catch (Exception ex) { Logger.Instance.LogFormat(LogType.Warning, this, "An exception occurred while processing the operation!"); Logger.Instance.LogException(this, ex); } }
private void ProcessNewImage(FileInfo file) { EnsureDirectoriesExist(); string analyseFileName = DateTime.Now.ToString("yyyyMMddHHmmss"); string archivedFilePath = Path.Combine(_archivePath.FullName, analyseFileName + ".tif"); // Moves the file to a different location, and throws if it failed. MoveFileTo(file, archivedFilePath); List<string> analyzedLines = new List<string>(); Stopwatch swParse = new Stopwatch(); string[] parsedLines = null; try { OcrProcessOptions options = new OcrProcessOptions(); options.SoftwarePath = _configuration.OCRSoftwarePath; options.AnalyzedFileDestinationPath = Path.Combine(_analysisPath.FullName, Path.GetFileNameWithoutExtension(file.FullName)); options.ImagePath = file.FullName; Logger.Instance.LogFormat(LogType.Trace, this, Properties.Resources.OcrSoftwareParseBegin, file.FullName); swParse.Start(); parsedLines = _ocrSoftware.ProcessImage(options); swParse.Stop(); Logger.Instance.LogFormat(LogType.Trace, this, Properties.Resources.OcrSoftwareParseEndSuccess, swParse.ElapsedMilliseconds); } catch (Exception ex) { swParse.Stop(); Logger.Instance.LogFormat(LogType.Error, this, Properties.Resources.OcrSoftwareParseEndFail); Logger.Instance.LogException(this, ex); // Abort parsing // TODO: Introduce own exception for this! return; } // After the file has been parsed, read it back in ... // ... fetch all lines ... foreach (string preParsedLine in parsedLines) { // ... and add it to the list ( analyzedLines.Add(_configuration.ReplaceDictionary.ReplaceInString(preParsedLine)); } Operation operation = null; Stopwatch sw = Stopwatch.StartNew(); try { // Try to parse the operation. If parsing failed, ignore this but write to the log file! Logger.Instance.LogFormat(LogType.Trace, this, "Begin parsing incoming operation..."); string[] lines = analyzedLines.ToArray(); // Find out if the fax is a test-fax if (IsTestFax(lines)) { sw.Stop(); Logger.Instance.LogFormat(LogType.Trace, this, "Operation is a test-fax. Parsing is skipped."); } else { operation = _parser.Parse(lines); sw.Stop(); Logger.Instance.LogFormat(LogType.Trace, this, "Parsed operation in '{0}' milliseconds.", sw.ElapsedMilliseconds); // If there is no timestamp, use the current time. Not too good but better than MinValue :-/ if (operation.Timestamp == DateTime.MinValue) { Logger.Instance.LogFormat(LogType.Warning, this, "Could not parse timestamp from the fax. Using the current time as the timestamp."); operation.Timestamp = DateTime.Now; } Dictionary<string, object> ctxParameters = new Dictionary<string, object>(); ctxParameters["ArchivedFilePath"] = archivedFilePath; ctxParameters["ImagePath"] = file.FullName; AlarmSourceEventArgs args = new AlarmSourceEventArgs(operation); args.Parameters = ctxParameters; // Raise event... OnNewAlarm(args); } } catch (Exception ex) { sw.Stop(); Logger.Instance.LogFormat(LogType.Warning, this, "An exception occurred while processing the alarmfax!"); Logger.Instance.LogException(this, ex); } }
private void AlarmSource_NewAlarm(object sender, AlarmSourceEventArgs e) { IAlarmSource source = (IAlarmSource)sender; // Sanity-checks if (e.Operation == null) { Logger.Instance.LogFormat(LogType.Warning, this, "Alarm Source '{0}' did not return an operation! This may indicate that parsing an operation has failed. Please check the log!", source.GetType().FullName); return; } try { // If there is no timestamp, use the current time. Not too good but better than MinValue :-/ if (e.Operation.Timestamp.Year == 1) { Logger.Instance.LogFormat(LogType.Warning, this, "Could not parse timestamp from the fax. Using the current time as the timestamp."); e.Operation.Timestamp = DateTime.Now; } DownloadRoutePlan(e.Operation); Operation storedOperation = StoreOperation(e.Operation); if (storedOperation == null) { return; } IJobContext context = JobContext.FromEventArgs(sender, e); _jobManager.ExecuteJobs(context, storedOperation); } catch (Exception ex) { Logger.Instance.LogFormat(LogType.Warning, this, "An exception occurred while processing the operation!"); Logger.Instance.LogException(this, ex); } }