예제 #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
        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);
        }