Mercurial > hg > orthanc
comparison OrthancServer/ServerContext.cpp @ 226:8a26a8e85edf
refactoring to read files
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 30 Nov 2012 09:45:29 +0100 |
parents | 4eb0c7ce86c9 |
children | 209ca3f6db62 |
comparison
equal
deleted
inserted
replaced
225:03aa59ecf6d8 | 226:8a26a8e85edf |
---|---|
30 **/ | 30 **/ |
31 | 31 |
32 | 32 |
33 #include "ServerContext.h" | 33 #include "ServerContext.h" |
34 | 34 |
35 #include "../Core/HttpServer/FilesystemHttpSender.h" | |
36 | |
35 #include <glog/logging.h> | 37 #include <glog/logging.h> |
36 | 38 |
37 namespace Orthanc | 39 namespace Orthanc |
38 { | 40 { |
39 ServerContext::ServerContext(const boost::filesystem::path& path) : | 41 ServerContext::ServerContext(const boost::filesystem::path& path) : |
40 storage_(path.string()), | 42 storage_(path.string()), |
41 index_(storage_, path.string()) | 43 index_(*this, path.string()) |
42 { | 44 { |
43 } | 45 } |
44 | 46 |
45 StoreStatus ServerContext::Store(const char* dicomFile, | 47 StoreStatus ServerContext::Store(const char* dicomFile, |
46 size_t dicomSize, | 48 size_t dicomSize, |
73 break; | 75 break; |
74 } | 76 } |
75 | 77 |
76 return status; | 78 return status; |
77 } | 79 } |
80 | |
81 | |
82 void ServerContext::AnswerFile(RestApiOutput& output, | |
83 const std::string& instancePublicId, | |
84 AttachedFileType content) | |
85 { | |
86 CompressionType compressionType; | |
87 std::string fileUuid; | |
88 | |
89 if (index_.GetFile(fileUuid, compressionType, | |
90 instancePublicId, AttachedFileType_Dicom)) | |
91 { | |
92 assert(compressionType == CompressionType_None); | |
93 | |
94 FilesystemHttpSender sender(storage_, fileUuid); | |
95 sender.SetDownloadFilename(fileUuid + ".dcm"); | |
96 sender.SetContentType("application/dicom"); | |
97 output.AnswerFile(sender); | |
98 } | |
99 } | |
100 | |
101 | |
102 void ServerContext::ReadJson(Json::Value& result, | |
103 const std::string& instancePublicId) | |
104 { | |
105 CompressionType compressionType; | |
106 std::string fileUuid; | |
107 if (!index_.GetFile(fileUuid, compressionType, instancePublicId, AttachedFileType_Json)) | |
108 { | |
109 throw OrthancException(ErrorCode_InternalError); | |
110 } | |
111 | |
112 assert(compressionType == CompressionType_None); | |
113 | |
114 std::string s; | |
115 storage_.ReadFile(s, fileUuid); | |
116 | |
117 Json::Reader reader; | |
118 if (!reader.parse(s, result)) | |
119 { | |
120 throw OrthancException("Corrupted JSON file"); | |
121 } | |
122 } | |
78 } | 123 } |