コード例 #1
0
ファイル: AbbcdnController.cs プロジェクト: MartinBG/Gva
        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;
        }
コード例 #2
0
        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;
        }