private void SaveAtt(WorkFlow.SDK.Documents.Model.CurrentDocumentData currentDocument, byte[] newAttContent) { var sourceAttData = currentDocument.GetFieldValue(Configuration.AttConfig.AttTechnicalFieldID)?.ToString(); var sourceAtt = currentDocument.Attachments.GetByID(Convert.ToInt32(sourceAttData)); sourceAtt.Content = newAttContent; if (sourceAtt.FileExtension.Equals(".pdf", StringComparison.InvariantCultureIgnoreCase)) { sourceAtt.FileName = $"{Path.GetFileNameWithoutExtension(sourceAtt.FileName)}{Configuration.AttConfig.AttSufix}{sourceAtt.FileExtension}"; } else { sourceAtt.FileName = $"{Path.GetFileNameWithoutExtension(sourceAtt.FileName)}{Configuration.AttConfig.AttSufix}.pdf"; } if (!string.IsNullOrEmpty(Configuration.AttConfig.SaveCategory)) { sourceAtt.FileGroup = new AttachmentsGroup(Configuration.AttConfig.SaveCategory, null); } DocumentAttachmentsManager.UpdateAttachment(new UpdateAttachmentParams() { Attachment = sourceAtt }); }
private void SaveAtt(CurrentDocumentData currentDocument, byte[] newAttContent) { var sourceAttData = currentDocument.GetFieldValue(Configuration.AttConfig.AttTechnicalFieldID).ToString(); var sourceAtt = currentDocument.Attachments.GetByID(Convert.ToInt32(sourceAttData)); sourceAtt.Content = newAttContent; sourceAtt.FileName = $"{Path.GetFileNameWithoutExtension(sourceAtt.FileName)}{Configuration.AttConfig.AttSufix}{sourceAtt.FileExtension}"; if (!string.IsNullOrEmpty(Configuration.AttConfig.SaveCategory)) { sourceAtt.FileGroup = new AttachmentsGroup(Configuration.AttConfig.SaveCategory, null); } DocumentAttachmentsManager.UpdateAttachment(new UpdateAttachmentParams() { Attachment = sourceAtt }); }
private AttachmentData GetAttachment(ActionContextInfo context) { if (Configuration.AttConfig.InputAttType == InputType.Category) { _log.AppendLine("Downloading attachments by category"); var allAttachments = DocumentAttachmentsManager.GetAttachments(new GetAttachmentsParams() { DocumentId = context.CurrentDocument.ID, IncludeContent = true }); if (Configuration.AttConfig.CatType == CategoryType.ID) { return(allAttachments.FirstOrDefault(x => x.FileGroup.ID == Configuration.AttConfig.InputCategoryId.ToString() && (string.IsNullOrEmpty(Configuration.AttConfig.AttRegularExpression) || Regex.IsMatch(x.FileName, Configuration.AttConfig.AttRegularExpression)))); } else if (Configuration.AttConfig.CatType == CategoryType.None) { return(allAttachments.FirstOrDefault(x => x.FileGroup == null && (string.IsNullOrEmpty(Configuration.AttConfig.AttRegularExpression) || Regex.IsMatch(x.FileName, Configuration.AttConfig.AttRegularExpression)))); } else { return(allAttachments.First()); } } else { _log.AppendLine("Downloading attachments by SQL query"); var attId = SqlExecutionHelper.ExecSqlCommandScalar(Configuration.AttConfig.AttQuery, context); if (attId == null) { throw new Exception("Sql query not returning result"); } return(DocumentAttachmentsManager.GetAttachment(Convert.ToInt32(attId))); } }
private void SaveAtt(CurrentDocumentData currentDocument, byte[] newAttContent) { if (newAttContent == null) { throw new Exception("API returned empty document content!"); } int sourceAttData = Convert.ToInt32(currentDocument.GetFieldValue(Configuration.AttConfig.AttTechnicalFieldID)); var sourceAtt = currentDocument.Attachments.GetByID(sourceAttData); sourceAtt.Content = newAttContent; sourceAtt.FileName = $"{Path.GetFileNameWithoutExtension(sourceAtt.FileName)}{Configuration.AttConfig.AttSufix}{sourceAtt.FileExtension}"; if (!string.IsNullOrEmpty(Configuration.AttConfig.SaveCategory)) { sourceAtt.FileGroup = new WorkFlow.SDK.Documents.Model.Attachments.AttachmentsGroup(Configuration.AttConfig.SaveCategory, null); } DocumentAttachmentsManager.UpdateAttachment(new WorkFlow.SDK.Documents.Model.Attachments.UpdateAttachmentParams() { Attachment = sourceAtt }); }