internal JobContext(IAlarmSource source, AlarmSourceEventArgs args) { Assertions.AssertNotNull(source, "source"); Assertions.AssertNotNull(args, "args"); AlarmSourceName = source.GetType().Name; Parameters = args.Parameters; }
private void OnNewAlarm(AlarmSourceEventArgs args) { var copy = NewAlarm; if (copy != null) { copy(this, args); } }
private void AlarmSource_NewAlarm(object sender, AlarmSourceEventArgs e) { IAlarmSource source = (IAlarmSource)sender; Operation operation = e.Operation; if (operation == null) { Logger.Instance.LogFormat(LogType.Warning, this, Resources.AlarmSourceNoOperation, source.GetType().FullName); return; } Logger.Instance.LogFormat(LogType.Info, this, Resources.AlarmSourceReceivedOperation, operation.ToString(), sender.GetType().Name); try { if (!ShouldStoreOperation(operation)) { Logger.Instance.LogFormat(LogType.Info, this, Resources.NewAlarmIgnoringAlreadyPresentOperation, operation.OperationNumber); return; } // If there is no timestamp, use the current time. if (operation.Timestamp.Year == 1) { Logger.Instance.LogFormat(LogType.Warning, this, Resources.NewAlarmInvalidTimestamp); operation.Timestamp = DateTime.Now; } JobContext context = new JobContext(source, e); context.Phase = JobPhase.OnOperationSurfaced; _jobManager.ExecuteJobs(context, operation); operation = StoreOperation(operation); if (operation == null) { return; } Logger.Instance.LogFormat(LogType.Info, this, Resources.NewAlarmStored, operation.Id); context.Phase = JobPhase.AfterOperationStored; _jobManager.ExecuteJobs(context, operation); Logger.Instance.LogFormat(LogType.Info, this, Resources.NewAlarmHandlingFinished, operation.Id); } catch (Exception ex) { Logger.Instance.LogFormat(LogType.Warning, this, Resources.NewAlarmHandlingException); 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; } // 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(AnalyzedFileNameFormat); string archivedFilePath = Path.Combine(_archivePath.FullName, analyseFileName + ArchivedFilePathExtension); MoveFileTo(file, archivedFilePath); 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); Stopwatch swParse = Stopwatch.StartNew(); parsedLines = _ocrSoftware.ProcessImage(options); swParse.Stop(); Logger.Instance.LogFormat(LogType.Trace, this, Properties.Resources.OcrSoftwareParseEndSuccess, swParse.ElapsedMilliseconds); } catch (Exception ex) { Logger.Instance.LogFormat(LogType.Error, this, Properties.Resources.OcrSoftwareParseEndFail); Logger.Instance.LogException(this, ex); return; } IList <string> analyzedLines = new List <string>(); ReplaceDictionary replDict = _configuration.ReplaceDictionary; foreach (string preParsedLine in parsedLines) { analyzedLines.Add(replDict.ReplaceInString(preParsedLine)); } Operation operation = null; try { Logger.Instance.LogFormat(LogType.Trace, this, Properties.Resources.BeginParsingIncomingOperation); string[] lines = analyzedLines.ToArray(); if (!IsOnWhitelist(lines)) { Logger.Instance.LogFormat(LogType.Info, this, Properties.Resources.FaxIsNotOnWhitelist); return; } if (IsOnBlacklist(lines)) { Logger.Instance.LogFormat(LogType.Trace, this, Properties.Resources.FaxIsOnBlacklist); return; } Stopwatch sw = Stopwatch.StartNew(); operation = _parser.Parse(lines); sw.Stop(); Logger.Instance.LogFormat(LogType.Trace, this, Properties.Resources.ParsingOperationCompleted, 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, Properties.Resources.ParsingTimestampFailedUsingCurrentTime); operation.Timestamp = DateTime.Now; } IDictionary <string, object> ctxParameters = new Dictionary <string, object>(); ctxParameters[ContextParameterKeys.ArchivedFilePath] = archivedFilePath; ctxParameters[ContextParameterKeys.ImagePath] = file.FullName; AlarmSourceEventArgs args = new AlarmSourceEventArgs(operation); args.Parameters = ctxParameters; OnNewAlarm(args); } catch (Exception ex) { Logger.Instance.LogFormat(LogType.Warning, this, Properties.Resources.ProcessNewImageError); Logger.Instance.LogException(this, ex); } }
private void ProcessNewImage(FileInfo file) { EnsureDirectoriesExist(); string analyseFileName = DateTime.Now.ToString("yyyyMMddHHmmssffff"); 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 return; } ReplaceDictionary replDict = _configuration.ReplaceDictionary; foreach (string preParsedLine in parsedLines) { analyzedLines.Add(replDict.ReplaceInString(preParsedLine)); } Operation operation = null; Stopwatch sw = Stopwatch.StartNew(); try { Logger.Instance.LogFormat(LogType.Trace, this, "Begin parsing incoming operation..."); string[] lines = analyzedLines.ToArray(); 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 ProcessNewImage(FileInfo file) { EnsureDirectoriesExist(); string analyseFileName = DateTime.Now.ToString(AnalyzedFileNameFormat); string archivedFilePath = Path.Combine(_archivePath.FullName, analyseFileName + ArchivedFilePathExtension); MoveFileTo(file, archivedFilePath); 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); Stopwatch swParse = Stopwatch.StartNew(); parsedLines = _ocrSoftware.ProcessImage(options); swParse.Stop(); Logger.Instance.LogFormat(LogType.Trace, this, Properties.Resources.OcrSoftwareParseEndSuccess, swParse.ElapsedMilliseconds); } catch (Exception ex) { Logger.Instance.LogFormat(LogType.Error, this, Properties.Resources.OcrSoftwareParseEndFail); Logger.Instance.LogException(this, ex); return; } IList<string> analyzedLines = new List<string>(); ReplaceDictionary replDict = _configuration.ReplaceDictionary; foreach (string preParsedLine in parsedLines) { analyzedLines.Add(replDict.ReplaceInString(preParsedLine)); } Operation operation = null; try { Logger.Instance.LogFormat(LogType.Trace, this, Properties.Resources.BeginParsingIncomingOperation); string[] lines = analyzedLines.ToArray(); if (!_serviceProvider.GetService<IAlarmFilter>().QueryAcceptSource(string.Join(" ", lines))) { return; } Stopwatch sw = Stopwatch.StartNew(); operation = _parser.Parse(lines); sw.Stop(); Logger.Instance.LogFormat(LogType.Trace, this, Properties.Resources.ParsingOperationCompleted, 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, Properties.Resources.ParsingTimestampFailedUsingCurrentTime); operation.Timestamp = DateTime.Now; } IDictionary<string, object> ctxParameters = new Dictionary<string, object>(); ctxParameters[ContextParameterKeys.ArchivedFilePath] = archivedFilePath; ctxParameters[ContextParameterKeys.ImagePath] = file.FullName; AlarmSourceEventArgs args = new AlarmSourceEventArgs(operation); args.Parameters = ctxParameters; OnNewAlarm(args); } catch (Exception ex) { Logger.Instance.LogFormat(LogType.Warning, this, Properties.Resources.ProcessNewImageError); Logger.Instance.LogException(this, ex); } }
private void ProcessNewImage(FileInfo file) { EnsureDirectoriesExist(); string analyseFileName = DateTime.Now.ToString("yyyyMMddHHmmssffff"); 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 return; } ReplaceDictionary replDict = _configuration.ReplaceDictionary; foreach (string preParsedLine in parsedLines) { analyzedLines.Add(replDict.ReplaceInString(preParsedLine)); } Operation operation = null; Stopwatch sw = Stopwatch.StartNew(); try { Logger.Instance.LogFormat(LogType.Trace, this, "Begin parsing incoming operation..."); string[] lines = analyzedLines.ToArray(); 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 OnNewAlarm(AlarmSourceEventArgs args) { NewAlarm?.Invoke(this, args); }
private void OnNewAlarm(AlarmSourceEventArgs e) { var copy = NewAlarm; copy?.Invoke(this, e); }