public void Action() { try { List<int> pendingIncomingDocs = null; using (var unitOfWork = unitOfWorkFactory()) { pendingIncomingDocs = unitOfWork.Value.DbContext.Set<IncomingDoc>() .Where(e => e.IncomingDocStatus.Alias == "Pending") .Select(d => d.IncomingDocId) .ToList(); } using (var channelFactory = new ChannelFactory<IAbbcdn>("WSHttpBinding_IAbbcdn")) using (var abbcdnStorage = new AbbcdnStorage(channelFactory)) { foreach (int incomingDocId in pendingIncomingDocs) { using (var incomingDocProcessor = incomingDocProcessorFactory()) { incomingDocProcessor.Value.AbbcdnStorage = abbcdnStorage; incomingDocProcessor.Value.Process(incomingDocId); } } } } catch (Exception ex) { logger.Error("General error: " + Helper.GetDetailedExceptionInfo(ex)); } }
public HttpResponseMessage Get(Guid fileKey, string mimeType = null, string fileName = null) { DownloadFileInfo downloadFileInfo = null; using (var channelFactory = new ChannelFactory<IAbbcdn>("WSHttpBinding_IAbbcdn")) using (var abbcdnStorage = new AbbcdnStorage(channelFactory)) { downloadFileInfo = abbcdnStorage.DownloadFile(fileKey); } HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); result.Content = new PushStreamContent( (outputStream, httpContent, transportContext) => { using (outputStream) { outputStream.Write(downloadFileInfo.ContentBytes, 0, downloadFileInfo.ContentBytes.Length); } }); result.Content.Headers.ContentType = new MediaTypeHeaderValue(string.IsNullOrEmpty(mimeType) ? "application/octet-stream" : mimeType); result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = fileName }; return result; }
public DocumentInfo GetDocumentByTicketId(string ticketId) { Guid ticketIdGuid = Guid.Parse(ticketId); Ticket ticket = this.unitOfWork.DbContext.Set<Ticket>().Single(e => e.TicketId == ticketIdGuid); string xmlContent = null; string docTypeUri = null; if (ticket.DocFileId.HasValue) { DocFile docFile = this.unitOfWork.DbContext.Set<DocFile>().Include(e => e.Doc).Single(e => e.DocFileId == ticket.DocFileId); docTypeUri = this.unitOfWork.DbContext.Set<DocFileType>().Single(e => e.DocFileTypeId == docFile.DocFileTypeId).DocTypeUri; var fileContent = ReadFromBlob(ticket.BlobOldKey.Value); xmlContent = Utf8Utils.GetString(fileContent); } else { using (var channelFactory = new ChannelFactory<IAbbcdn>("AbbcdnEndpoint")) using (var abbcdnStorage = new AbbcdnStorage(channelFactory)) { docTypeUri = ticket.DocTypeUri; var fileContent = abbcdnStorage.DownloadFile(ticket.AbbcdnKey.Value).ContentBytes; xmlContent = Utf8Utils.GetString(fileContent); } } var documentMetaData = rioDocumentParser.GetDocumentMetadataFromXml(xmlContent); string signatureXPath = documentMetaData.SignatureXPath; Dictionary<string, string> signatureXPathNamespaces = new Dictionary<string, string>(documentMetaData.SignatureXPathNamespaces); DocumentInfo documentInfo = new DocumentInfo(); documentInfo.DocumentXml = xmlContent; documentInfo.DocumentTypeURI = docTypeUri; documentInfo.VisualizationMode = ticket.VisualizationMode.HasValue ? (VisualizationMode)ticket.VisualizationMode.Value : VisualizationMode.DisplayWithoutSignature; documentInfo.SignatureXPath = signatureXPath; documentInfo.SignatureXPathNamespaces = signatureXPathNamespaces; return documentInfo; }
private List<Rio.Data.Utils.RioObjectUtils.CompetenceContainerFile> GetCompetenceFilesByDocId(int? caseDocId) { List<Rio.Data.Utils.RioObjectUtils.CompetenceContainerFile> competenceFiles = new List<Rio.Data.Utils.RioObjectUtils.CompetenceContainerFile>(); if (caseDocId.HasValue) { var publicCaseDocs = docRepository.FindPublicLeafsByDocId(caseDocId.Value); if (publicCaseDocs.Count > 0) { using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DbContext"].ConnectionString)) using (var channelFactory = new ChannelFactory<IAbbcdn>("WSHttpBinding_IAbbcdn")) using (var abbcdnStorage = new AbbcdnStorage(channelFactory)) { connection.Open(); foreach (var doc in publicCaseDocs) { DocFile primaryDocFile = this.unitOfWork.DbContext.Set<DocFile>() .Include(d => d.DocFileType) .Where(d => d.DocId == doc.DocId && d.DocFileKind.Alias == "PublicAttachedFile") .OrderByDescending(d => d.IsPrimary) .ThenBy(d => d.DocFileId) .FirstOrDefault(); Rio.Data.Utils.RioObjectUtils.CompetenceContainerFile competenceContainerFile = new Rio.Data.Utils.RioObjectUtils.CompetenceContainerFile(); if (primaryDocFile == null) { competenceContainerFile.DocumentTypeName = doc.DocType.Name; competenceContainerFile.DocumentRegIndex = doc.RegIndex; competenceContainerFile.DocumentRegNumber = doc.RegNumber.ToString(); competenceContainerFile.DocumentRegDate = doc.RegDate; } else { byte[] fileContent = null; using (MemoryStream mStream = new MemoryStream()) using (var blobStream = new BlobReadStream(connection, "dbo", "Blobs", "Content", "Key", primaryDocFile.DocFileContentId)) { blobStream.CopyTo(mStream); fileContent = mStream.ToArray(); } var uploadFileInfo = abbcdnStorage.UploadFile(fileContent, primaryDocFile.DocFileName); if (!String.IsNullOrWhiteSpace(primaryDocFile.DocFileType.DocTypeUri)) { competenceContainerFile.DocumentTypeName = RioDocumentMetadata.GetMetadataByDocumentTypeURI(primaryDocFile.DocFileType.DocTypeUri).DocumentTypeName; } else { competenceContainerFile.DocumentTypeName = doc.DocType.Name; } competenceContainerFile.DocumentTypeUri = primaryDocFile.DocFileType.DocTypeUri; competenceContainerFile.DocumentRegIndex = doc.RegIndex; competenceContainerFile.DocumentRegNumber = doc.RegNumber.ToString(); competenceContainerFile.DocumentRegDate = doc.RegDate; //competenceContainerFile.Abbcdnconfig = SerializeAbbcdn(uploadFileInfo, primaryDocFile.DocFileName, primaryDocFile.DocFileType.MimeType); competenceContainerFile.Abbcdnconfig = new Abbcdnconfig() { AttachedDocumentUniqueIdentifier = uploadFileInfo.FileKey.ToString(), AttachedDocumentHash = uploadFileInfo.ContentHash, AttachedDocumentSize = uploadFileInfo.ContentSize.ToString(), AttachedDocumentFileName = primaryDocFile.DocFileName, AttachedDocumentFileType = primaryDocFile.DocFileType.MimeType }; } competenceFiles.Add(competenceContainerFile); } } } } return competenceFiles; }