/// <summary>
        /// Initializes a new instance of the <see cref="FaxConfiguration"/> class.
        /// </summary>
        public FaxConfiguration()
        {
            this.FaxPath             = SettingsManager.Instance.GetSetting("FaxAlarmSource", "FaxPath").GetString();
            this.ArchivePath         = SettingsManager.Instance.GetSetting("FaxAlarmSource", "ArchivePath").GetString();
            this.AnalysisPath        = SettingsManager.Instance.GetSetting("FaxAlarmSource", "AnalysisPath").GetString();
            this.AlarmFaxParserAlias = SettingsManager.Instance.GetSetting("FaxAlarmSource", "AlarmfaxParser").GetString();

            string ocr = SettingsManager.Instance.GetSetting("FaxAlarmSource", "OCR.Software").GetString();

            this.OCRSoftware     = (OcrSoftware)Enum.Parse(typeof(OcrSoftware), ocr);
            this.OCRSoftwarePath = SettingsManager.Instance.GetSetting("FaxAlarmSource", "OCR.Path").GetString();

            this.RoutineInterval = SettingsManager.Instance.GetSetting("FaxAlarmSource", "Routine.Interval").GetInt32();
            this.TestFaxKeywords = new ReadOnlyCollection <string>(SettingsManager.Instance.GetSetting("FaxAlarmSource", "TestFaxKeywords").GetString().Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries));

            // Parse replace dictionary
            this.ReplaceDictionary = SettingsManager.Instance.GetSetting("FaxAlarmSource", "ReplaceDictionary").GetValue <ReplaceDictionary>();
        }
        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);
            }
        }