AlarmWorkflow.AlarmSource.Fax.FaxAlarmSource.ProcessNewImage C# (CSharp) Метод

ProcessNewImage() приватный Метод

private ProcessNewImage ( FileInfo file ) : void
file System.IO.FileInfo
Результат void
        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);
            }
        }