Example #1
0
        public virtual IBlobPackage FillBlobs(IBlobPackage blobPackage, string inputFilesXmlPath,
                                              string packageFolderPath)
        {
            if (!File.Exists(inputFilesXmlPath))
            {
                throw AppliedCodeException.Create(Resources.NoFilesInfoInPackage);
            }
            var fileDescriptionTagName = Constants.Module.DcsInputFilesTagNames.FileDescription;

            var filesXDoc    = System.Xml.Linq.XDocument.Load(inputFilesXmlPath);
            var fileElements = filesXDoc
                               .Element(Constants.Module.DcsInputFilesTagNames.InputFilesSection)
                               .Element(Constants.Module.DcsInputFilesTagNames.Files)
                               .Elements()
                               .ToList();

            if (!fileElements.Any())
            {
                throw AppliedCodeException.Create(Resources.NoFilesInfoInPackage);
            }

            var sentByEmail = blobPackage.SourceType == BlobPackage.SourceType.Mail;

            if (sentByEmail)
            {
                var mailBodyHtmlName = Constants.Module.DcsMailBodyName.Html;
                var mailBodyTxtName  = Constants.Module.DcsMailBodyName.Txt;

                // Тело письма.
                blobPackage.MailBodyBlob = this.GetMailBody(fileElements, packageFolderPath);

                // Фильтрация картинок из тела письма.
                var htmlBodyElement = fileElements
                                      .FirstOrDefault(x => string.Equals(x.Element(fileDescriptionTagName).Value, mailBodyHtmlName, StringComparison.InvariantCultureIgnoreCase));
                var hasHtmlBody = htmlBodyElement != null;

                // Убрать тело письма (body.html или body.txt).
                fileElements = fileElements
                               .Where(x => !string.Equals(x.Element(fileDescriptionTagName).Value, mailBodyHtmlName, StringComparison.InvariantCultureIgnoreCase) &&
                                      !string.Equals(x.Element(fileDescriptionTagName).Value, mailBodyTxtName, StringComparison.InvariantCultureIgnoreCase))
                               .ToList();

                if (blobPackage.MailBodyBlob != null && !string.IsNullOrEmpty(blobPackage.MailBodyBlob.FilePath) && hasHtmlBody)
                {
                    fileElements = this.FilterEmailBodyInlineImages(blobPackage.MailBodyBlob.FilePath, fileElements);
                }
            }

            // Получить файлы пакета документов из DCS.
            foreach (var fileElement in fileElements)
            {
                var blob = this.CreateBlobFromXelement(fileElement, packageFolderPath, sentByEmail);
                if (blob != null)
                {
                    blobPackage.Blobs.AddNew().Blob = blob;
                }
            }

            return(blobPackage);
        }
Example #2
0
        public virtual void ProcessPackageInArio(IBlobPackage blobPackage)
        {
            // Получение настроек.
            var smartProcessingSettings = Sungero.Docflow.PublicFunctions.SmartProcessingSetting.GetSettings();
            var firstPageClassifierId   = smartProcessingSettings.FirstPageClassifierId.ToString();
            var typeClassifierId        = smartProcessingSettings.TypeClassifierId.ToString();

            Logger.DebugFormat("First page classifier: name - \"{0}\", id - {1}.", smartProcessingSettings.FirstPageClassifierName, firstPageClassifierId);
            Logger.DebugFormat("Type classifier: name - \"{0}\", id - {1}.", smartProcessingSettings.TypeClassifierName, typeClassifierId);

            // Получить соответствие класса и наименования правила извлечения фактов.
            var processingRule = smartProcessingSettings.ProcessingRules
                                 .Where(x => !string.IsNullOrWhiteSpace(x.ClassName) && !string.IsNullOrWhiteSpace(x.GrammarName))
                                 .ToDictionary(x => x.ClassName, x => x.GrammarName);

            // Получение доп. классификаторов.
            var additionalClassifierIds = Sungero.Docflow.PublicFunctions.SmartProcessingSetting.GetAdditionalClassifierIds(smartProcessingSettings);

            // Обработка в Ario.
            var arioConnector = this.GetArioConnector();
            var blobs         = blobPackage.Blobs.Select(x => x.Blob);

            foreach (var blob in blobs)
            {
                var fileName = blob.OriginalFileName;
                var filePath = blob.FilePath;

                if (!this.CanArioProcessFile(filePath))
                {
                    Logger.DebugFormat("File extension is not supported by Ario; {0} will be uploaded as a simple document.", fileName);
                    continue;
                }

                try
                {
                    Logger.DebugFormat("Begin classification and facts extraction. File: {0}", fileName);
                    var arioResultJson = arioConnector.ClassifyAndExtractFacts(File.ReadAllBytes(filePath),
                                                                               fileName,
                                                                               typeClassifierId,
                                                                               firstPageClassifierId,
                                                                               processingRule,
                                                                               additionalClassifierIds);
                    Logger.DebugFormat("End classification and facts extraction. File: {0}", fileName);
                    blob.ArioResultJson = arioResultJson;
                    blob.Save();
                }
                catch (ExternalException ex)
                {
                    Logger.DebugFormat("An error has occurred during classification and facts extraction. File: {0}", ex, fileName);
                    throw ex;
                }
            }
        }
Example #3
0
        public virtual void FillMailInfo(IBlobPackage blobPackage, string instanceInfosXmlPath)
        {
            if (!File.Exists(instanceInfosXmlPath))
            {
                throw AppliedCodeException.Create(Resources.FileNotFoundFormat(instanceInfosXmlPath));
            }

            var infoXDoc = System.Xml.Linq.XDocument.Load(instanceInfosXmlPath);

            if (infoXDoc == null)
            {
                return;
            }

            var mailCaptureInstanceInfoElement = infoXDoc
                                                 .Element(DcsInstanceInfosTagNames.CaptureInstanceInfoList)
                                                 .Element(DcsInstanceInfosTagNames.MailCaptureInstanceInfo);

            if (mailCaptureInstanceInfoElement == null)
            {
                return;
            }

            // Тема письма.
            var subject = this.GetAttributeStringValue(mailCaptureInstanceInfoElement, DcsInstanceInfosTagNames.Subject);

            if (subject.Length > blobPackage.Info.Properties.Subject.Length)
            {
                subject = subject.Substring(0, blobPackage.Info.Properties.Subject.Length);
            }
            blobPackage.Subject = subject;

            // Отправитель.
            var fromElement = mailCaptureInstanceInfoElement.Element(DcsInstanceInfosTagNames.From);

            if (fromElement != null)
            {
                blobPackage.FromAddress = this.GetAttributeStringValue(fromElement, DcsInstanceInfosTagNames.ContactAttributes.Address);
                blobPackage.FromName    = this.GetAttributeStringValue(fromElement, DcsInstanceInfosTagNames.ContactAttributes.Name);
            }

            // Получатели.
            var mailToElement = mailCaptureInstanceInfoElement.Element(DcsInstanceInfosTagNames.To);

            if (mailToElement != null)
            {
                var recipients = mailToElement.Elements(DcsInstanceInfosTagNames.Recipient);
                foreach (var recipient in recipients)
                {
                    var mailToRecipient = blobPackage.To.AddNew();
                    mailToRecipient.Name    = this.GetAttributeStringValue(recipient, DcsInstanceInfosTagNames.ContactAttributes.Name);
                    mailToRecipient.Address = this.GetAttributeStringValue(recipient, DcsInstanceInfosTagNames.ContactAttributes.Address);
                }
            }

            // Получатели копии.
            var copyElement = mailCaptureInstanceInfoElement.Element(DcsInstanceInfosTagNames.CC);

            if (copyElement != null)
            {
                var recipients = copyElement.Elements(DcsInstanceInfosTagNames.Recipient);
                foreach (var recipient in recipients)
                {
                    var copyRecipient = blobPackage.CC.AddNew();
                    copyRecipient.Name    = this.GetAttributeStringValue(recipient, DcsInstanceInfosTagNames.ContactAttributes.Name);
                    copyRecipient.Address = this.GetAttributeStringValue(recipient, DcsInstanceInfosTagNames.ContactAttributes.Address);
                }
            }

            blobPackage.Save();
        }