public async Task <Protocol> GetProtocolAsync(Guid idProtocol) { try { return(await _webApiClient.GetProtocolAsync(idProtocol)); } catch (Exception ex) { _logger.WriteError(ex, LogCategories); throw ex; } }
public async Task ExecuteAsync(ICommandBuildPECMail command) { PECMail pecMail = new PECMail { UniqueId = Guid.NewGuid(), Direction = PECMailDirection.Outgoing, IsActive = DocSuiteWeb.Entity.PECMails.PECMailActiveType.Active, }; PECMailBuildModel pecMailBuildModel = command.ContentType.ContentTypeValue; PECMailModel pecMailModel = pecMailBuildModel.PECMail; IdWorkflowActivity = pecMailBuildModel.IdWorkflowActivity; try { if (RetryPolicyEvaluation != null && !string.IsNullOrEmpty(RetryPolicyEvaluation.ReferenceModel)) { pecMailModel = JsonConvert.DeserializeObject <PECMailModel>(RetryPolicyEvaluation.ReferenceModel, _serializerSettings); } else { RetryPolicyEvaluation = new EvaluationModel(); } #region Creazione Documeti Allegati (Attachments OPTIONAL) if (!RetryPolicyEvaluation.Steps.Any(f => f.Name == "CREATE_ATTACHMENTS") && pecMailModel.Attachments.Any()) { Archive pecMailArchive = _biblosArchives.Single(f => f.Name.Equals(pecMailModel.PECMailBox.Location.ProtocolArchive, StringComparison.InvariantCultureIgnoreCase)); _logger.WriteDebug(new LogMessage($"biblos attachment archive name is {pecMailArchive.Name}"), LogCategories); List <BiblosDS.BiblosDS.Attribute> attachmentAttributes = _biblosClient.Document.GetAttributesDefinition(pecMailArchive.Name); //CREO CATENA IDENTIFICATIVA Guid?attachmentChainId = pecMailModel.IDAttachments; if (!attachmentChainId.HasValue) { attachmentChainId = _biblosClient.Document.CreateDocumentChain(pecMailArchive.Name, new List <AttributeValue>()); pecMailModel.IDAttachments = attachmentChainId; } pecMail.IDAttachments = attachmentChainId.Value; List <AttributeValue> attachmentAttributeValues; Content documentContent; Dictionary <Guid, long> sizes = new Dictionary <Guid, long>(); foreach (DocumentModel attachment in pecMailModel.Attachments.Where(f => !f.DocumentId.HasValue && f.DocumentToStoreId.HasValue)) { attachmentAttributeValues = new List <AttributeValue>() { new AttributeValue() { Attribute = attachmentAttributes.Single(f => f.Name.Equals(AttributeHelper.AttributeName_Filename, StringComparison.InvariantCultureIgnoreCase)), Value = attachment.FileName, }, new AttributeValue() { Attribute = attachmentAttributes.Single(f => f.Name.Equals(AttributeHelper.AttributeName_Signature, StringComparison.InvariantCultureIgnoreCase)), Value = attachment.Segnature, }, }; attachment.ChainId = attachmentChainId; _logger.WriteInfo(new LogMessage($"reading document content {attachment.DocumentToStoreId} ..."), LogCategories); documentContent = RetryingPolicyAction(() => _biblosClient.Document.GetDocumentContentById(attachment.DocumentToStoreId.Value)); //CREO IL DOCUMENTO Document attachmentPECMailDocument = new Document { Archive = pecMailArchive, Content = new Content { Blob = documentContent.Blob }, Name = attachment.FileName, IsVisible = true, AttributeValues = attachmentAttributeValues }; //ASSOCIO IL DOCUMENTO ALLA SUA CATENA DI COMPETENZA attachmentPECMailDocument = _biblosClient.Document.AddDocumentToChain(attachmentPECMailDocument, attachmentChainId, ContentFormat.Binary); _logger.WriteInfo(new LogMessage($"inserted document {attachmentPECMailDocument.IdDocument} in archive {pecMailArchive.IdArchive} with size {documentContent.Blob.LongLength}"), LogCategories); attachment.DocumentId = attachmentPECMailDocument.IdDocument; sizes.Add(attachmentPECMailDocument.IdDocument, documentContent.Blob.LongLength); } //Assegno gli allegati all'entita foreach (DocumentModel attachment in pecMailModel.Attachments.Where(f => f.DocumentId.HasValue)) { PECMailAttachment pecMailAttachment = new PECMailAttachment { IDDocument = attachment.DocumentId, AttachmentName = attachment.FileName, Parent = null, IsMain = false, Size = sizes[attachment.DocumentId.Value] }; pecMail.Attachments.Add(pecMailAttachment); } RetryPolicyEvaluation.Steps.Add(new StepModel() { Name = "CREATE_ATTACHMENTS", LocalReference = JsonConvert.SerializeObject(pecMail, _serializerSettings) }); } else { StepModel pecMailStatus = RetryPolicyEvaluation.Steps.First(f => f.Name == "CREATE_ATTACHMENTS"); pecMail = JsonConvert.DeserializeObject <PECMail>(pecMailStatus.LocalReference); } #endregion #region Creazione PECMail con stato attivo if (!RetryPolicyEvaluation.Steps.Any(f => f.Name == "ENTITY")) { pecMail.InvoiceStatus = !pecMailModel.InvoiceStatus.HasValue || pecMailModel.InvoiceStatus.Value == DocSuiteWeb.Model.Entities.PECMails.InvoiceStatus.None ? default(InvoiceStatus?) : (InvoiceStatus)pecMailModel.InvoiceStatus; pecMail.MailBody = pecMailModel.MailBody; pecMail.MailPriority = pecMailModel.MailPriority.HasValue ? (PECMailPriority)pecMailModel.MailPriority.Value : PECMailPriority.Normal; pecMail.MailRecipients = pecMailModel.MailRecipients; pecMail.MailRecipientsCc = pecMailModel.MailRecipientsCc; pecMail.MailSenders = pecMailModel.MailSenders; pecMail.MailSubject = pecMailModel.MailSubject; pecMail.PECType = null; pecMail.MailType = "invio"; pecMail.SplittedFrom = 0; pecMail.ProcessStatus = 0; pecMail.MultipleType = DocSuiteWeb.Entity.PECMails.PECMailMultipleType.NoSplit; pecMail.IsValidForInterop = false; pecMail.Location = new Location() { EntityShortId = pecMailModel.PECMailBox.Location.IdLocation.Value }; pecMail.PECMailBox = new PECMailBox() { EntityShortId = (short)pecMailModel.PECMailBox.PECMailBoxId.Value }; pecMail.IsActive = DocSuiteWeb.Entity.PECMails.PECMailActiveType.Active; WorkflowActionDocumentUnitLinkModel workflowActionDocumentUnitLinkModel = null; Protocol protocol = null; if ((workflowActionDocumentUnitLinkModel = pecMailBuildModel.WorkflowActions .OfType <WorkflowActionDocumentUnitLinkModel>() .FirstOrDefault(f => f.GetDestinationLink().Environment == (int)DocSuiteWeb.Entity.Commons.DSWEnvironmentType.PECMail)) != null && (protocol = await _webApiClient.GetProtocolAsync(workflowActionDocumentUnitLinkModel.GetReferenced().UniqueId)) != null) { pecMail.Year = protocol.Year; pecMail.Number = protocol.Number; pecMail.DocumentUnit = new DocSuiteWeb.Entity.DocumentUnits.DocumentUnit() { UniqueId = protocol.UniqueId }; pecMail.RecordedInDocSuite = null; } pecMail.WorkflowName = pecMailBuildModel.WorkflowName; pecMail.IdWorkflowActivity = pecMailBuildModel.IdWorkflowActivity; pecMail.WorkflowAutoComplete = pecMailBuildModel.WorkflowAutoComplete; foreach (IWorkflowAction workflowAction in pecMailBuildModel.WorkflowActions) { pecMail.WorkflowActions.Add(workflowAction); } pecMail = await _webApiClient.PostEntityAsync(pecMail); } else { StepModel pecMailStatus = RetryPolicyEvaluation.Steps.First(f => f.Name == "ENTITY"); pecMail = JsonConvert.DeserializeObject <PECMail>(pecMailStatus.LocalReference); } #endregion #region [ EventCompletePECMailBuild ] pecMailBuildModel.PECMail = pecMailModel; IEventCompletePECMailBuild eventCompletePECMailBuild = new EventCompletePECMailBuild(Guid.NewGuid(), pecMailBuildModel.UniqueId, command.TenantName, command.TenantId, command.TenantAOOId, command.Identity, pecMailBuildModel, null); if (!await _webApiClient.PushEventAsync(eventCompletePECMailBuild)) { _logger.WriteError(new LogMessage($"EventCompletePECMailBuild {pecMail.EntityId} has not been sended"), LogCategories); throw new Exception("IEventCompletePECMailBuild not sended"); } _logger.WriteInfo(new LogMessage($"IEventCompletePECMailBuild {eventCompletePECMailBuild.Id} has been sended"), LogCategories); #endregion #region Detach documenti archivio workflow foreach (DocumentModel attachment in pecMailModel.Attachments.Where(f => f.DocumentToStoreId.HasValue)) { _logger.WriteInfo(new LogMessage($"detaching workflow document {attachment.DocumentToStoreId} ..."), LogCategories); RetryingPolicyAction(() => _biblosClient.Document.DocumentDetach(new Document() { IdDocument = attachment.DocumentToStoreId.Value })); } #endregion } catch (Exception ex) { RetryPolicyEvaluation.ReferenceModel = JsonConvert.SerializeObject(pecMailModel, _serializerSettings); _logger.WriteError(ex, LogCategories); throw new ServiceBusEvaluationException(RetryPolicyEvaluation); } }