Пример #1
0
        private void ProcessDocument(SharePointDocument document, string filePath)
        {
            TraceFactory.Logger.Debug("Found file: " + document.FileName);

            try
            {
                string         fileName   = Path.GetFileName(filePath);
                ScanFilePrefix filePrefix = ScanFilePrefix.Parse(fileName);

                // Create the log for this file
                DigitalSendJobOutputLogger log = new DigitalSendJobOutputLogger(fileName, filePrefix.ToString(), filePrefix.SessionId);
                log.FileSentDateTime = document.Created.LocalDateTime;
                log.FileLocation     = $@"{_library.SiteUrl.Host}\{_library.Name}";

                // Validate and analyze the file
                OutputProcessor  processor = new OutputProcessor(filePath);
                ValidationResult result    = null;
                Retry.WhileThrowing(
                    () => result = processor.Validate(Configuration),
                    10,
                    TimeSpan.FromSeconds(2),
                    new List <Type>()
                {
                    typeof(IOException)
                });

                // If the validation failed, there is a small chance that the HPS file arrived
                // a little later than the PDF and didn't get downloaded at the same time.
                // Check the server to see if that's the case - if so, run the validation again
                if (!result.Succeeded && result.Message.Contains("metadata", StringComparison.OrdinalIgnoreCase))
                {
                    if (FindMetadataFile(document))
                    {
                        result = processor.Validate(Configuration);
                    }
                }

                DocumentProperties properties = processor.GetProperties();
                log.FileSizeBytes = properties.FileSize;
                log.PageCount     = properties.Pages;
                log.SetErrorMessage(result);

                // Clean up the file
                processor.ApplyRetention(Configuration, result.Succeeded);

                // Send the output log
                new DataLogger(GetLogServiceHost(filePrefix.SessionId)).Submit(log);
            }
            catch (IOException ex)
            {
                LogProcessFileError(filePath, ex);
            }
            catch (FormatException ex)
            {
                LogProcessFileError(filePath, ex);
            }
        }
Пример #2
0
        /// <summary>
        /// Processes the located file.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <param name="createdEventTime">The created event time.</param>
        protected virtual void ProcessFile(string filePath, DateTime?createdEventTime = null)
        {
            TraceFactory.Logger.Debug("Found file: {0}".FormatWith(filePath));

            try
            {
                string         fileName   = Path.GetFileName(filePath);
                ScanFilePrefix filePrefix = ScanFilePrefix.Parse(fileName);

                // Create the log for this file
                DigitalSendJobOutputLogger log = new DigitalSendJobOutputLogger(fileName, filePrefix.ToString(), filePrefix.SessionId);
                log.FileSentDateTime     = System.IO.Directory.GetCreationTime(filePath);
                log.FileReceivedDateTime = createdEventTime;
                log.FileLocation         = "{0} - {1}".FormatWith(Environment.MachineName, Path.GetDirectoryName(filePath));

                // Validate and analyze the file
                OutputProcessor  processor = new OutputProcessor(filePath);
                ValidationResult result    = null;
                Retry.WhileThrowing(
                    () => result = processor.Validate(Configuration),
                    10,
                    TimeSpan.FromSeconds(2),
                    new Collection <Type>()
                {
                    typeof(IOException)
                });

                DocumentProperties properties = processor.GetProperties();
                log.FileSizeBytes = properties.FileSize;
                log.PageCount     = properties.Pages;
                log.SetErrorMessage(result);

                // Clean up the file
                processor.ApplyRetention(Configuration, result.Succeeded);

                // Send the output log
                new DataLogger(GetLogServiceHost(filePrefix.SessionId)).Submit(log);
            }
            catch (IOException ex)
            {
                LogProcessFileError(filePath, ex);
            }
            catch (FormatException ex)
            {
                LogProcessFileError(filePath, ex);
            }
        }
Пример #3
0
        /// <summary>
        /// Processes the located file.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <param name="createdEventTime">The created event time.</param>
        protected override void ProcessFile(string filePath, DateTime?createdEventTime = null)
        {
            string fileName = Path.GetFileName(filePath);

            TraceFactory.Logger.Debug("Found file: {0}".FormatWith(fileName));

            // Check to see if we have the associated HPF file - without it, we can't process this file
            string hpfFile = Path.ChangeExtension(filePath, ".hpf");

            if (!Retry.UntilTrue(() => File.Exists(filePath), 30, TimeSpan.FromSeconds(2)))
            {
                TraceFactory.Logger.Debug("No associated HPF file - cannot process.");
                return;
            }

            // Extract the file prefix from the HPF metadata file
            ScanFilePrefix filePrefix = null;

            try
            {
                Retry.WhileThrowing(
                    () => filePrefix = ExtractFileName(hpfFile),
                    10,
                    TimeSpan.FromSeconds(2),
                    new Collection <Type>()
                {
                    typeof(IOException)
                });
            }
            catch (IOException ex)
            {
                LogProcessFileError(fileName + " HPF file ", ex);
                return;
            }
            catch (FormatException ex)
            {
                LogProcessFileError(fileName + " HPF file ", ex);
                return;
            }

            try
            {
                // Create the log for this file
                DigitalSendJobOutputLogger log = new DigitalSendJobOutputLogger(filePrefix, Path.GetExtension(filePath));
                log.FileName             = Path.GetFileName(filePath);
                log.FileSentDateTime     = System.IO.Directory.GetCreationTime(filePath);
                log.FileReceivedDateTime = createdEventTime;
                log.FileLocation         = "{0} - {1}".FormatWith(Environment.MachineName, Path.GetDirectoryName(filePath));

                // Validate and analyze the file
                OutputProcessor  processor = new OutputProcessor(filePath);
                ValidationResult result    = null;
                Retry.WhileThrowing(
                    () => result = processor.Validate(Options),
                    10,
                    TimeSpan.FromSeconds(2),
                    new Collection <Type>()
                {
                    typeof(IOException)
                });

                DocumentProperties properties = processor.GetProperties();
                log.FileSizeBytes = properties.FileSize;
                log.PageCount     = properties.Pages;
                log.SetErrorMessage(result);

                // Clean up the file
                Options.RetentionFileName = filePrefix.ToString();
                processor.ApplyRetention(Options, result.Succeeded);

                // Send the output log
                new DataLogger(GetLogServiceHost(filePrefix.SessionId)).Submit(log);
            }
            catch (IOException ex)
            {
                LogProcessFileError(fileName, ex);
            }
            catch (FormatException ex)
            {
                LogProcessFileError(fileName, ex);
            }

            // Create a notification file for the fax
            try
            {
                CreateNotificationFile(hpfFile, filePrefix);
            }
            catch (IOException ex)
            {
                TraceFactory.Logger.Error(ex);
            }
        }
Пример #4
0
        protected virtual bool ProcessMessage(EmailMessage message)
        {
            EmailAttachment attachment = message.Attachments.FirstOrDefault();

            if (attachment != null)
            {
                // Determine if we need to pull the file name from the subject
                string fileName = attachment.FileName;
                if (!ScanFilePrefix.MatchesPattern(attachment.FileName))
                {
                    fileName = message.Subject + Path.GetExtension(attachment.FileName);
                }
                TraceFactory.Logger.Debug("Found attachment: " + fileName);

                try
                {
                    ScanFilePrefix filePrefix = ScanFilePrefix.Parse(Path.GetFileName(fileName));

                    // Create the log for this file
                    DigitalSendJobOutputLogger log = new DigitalSendJobOutputLogger(fileName, filePrefix.ToString(), filePrefix.SessionId);
                    log.FileSentDateTime     = message.DateTimeSent;
                    log.FileReceivedDateTime = message.DateTimeReceived;
                    log.FileLocation         = _emailAddress.ToString();

                    // Save the attachment locally
                    FileInfo file = attachment.Save(_tempPath, fileName);

                    // Validate and analyze the file
                    OutputProcessor  processor = new OutputProcessor(file.FullName);
                    ValidationResult result    = null;
                    Retry.WhileThrowing(
                        () => result = processor.Validate(base.Configuration),
                        10,
                        TimeSpan.FromSeconds(2),
                        new Collection <Type>()
                    {
                        typeof(IOException)
                    });

                    DocumentProperties properties = processor.GetProperties();
                    log.FileSizeBytes = properties.FileSize;
                    log.PageCount     = properties.Pages;
                    log.SetErrorMessage(result);

                    // Clean up the file
                    processor.ApplyRetention(base.Configuration, result.Succeeded);

                    // One last check - if there was more than one attachment, flag this as an error
                    if (message.Attachments.Count > 1)
                    {
                        log.ErrorMessage += " {0} attachments with one email.".FormatWith(message.Attachments.Count);
                    }

                    // Send the output log
                    new DataLogger(GetLogServiceHost(filePrefix.SessionId)).Submit(log);
                }
                catch (Exception ex)
                {
                    LogProcessFileError(fileName, ex);
                    return(false);
                }
            }
            else
            {
                TraceFactory.Logger.Debug("Found email with subject {0} but no attachments.".FormatWith(message.Subject));
            }

            return(true);
        }