Mercurial > hg > orthanc-stone
comparison Framework/Oracle/GenericOracleRunner.cpp @ 1104:98cdfe5768a4 broker
ReadFileCommand
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 26 Oct 2019 16:43:08 +0200 |
parents | 17660df24c36 |
children | b82b74d13830 |
comparison
equal
deleted
inserted
replaced
1103:f7759637cdfb | 1104:98cdfe5768a4 |
---|---|
25 #include "GetOrthancImageCommand.h" | 25 #include "GetOrthancImageCommand.h" |
26 #include "GetOrthancWebViewerJpegCommand.h" | 26 #include "GetOrthancWebViewerJpegCommand.h" |
27 #include "HttpCommand.h" | 27 #include "HttpCommand.h" |
28 #include "OracleCommandExceptionMessage.h" | 28 #include "OracleCommandExceptionMessage.h" |
29 #include "OrthancRestApiCommand.h" | 29 #include "OrthancRestApiCommand.h" |
30 #include "ReadFileCommand.h" | |
30 | 31 |
31 #include <Core/Compression/GzipCompressor.h> | 32 #include <Core/Compression/GzipCompressor.h> |
32 #include <Core/HttpClient.h> | 33 #include <Core/HttpClient.h> |
33 #include <Core/OrthancException.h> | 34 #include <Core/OrthancException.h> |
34 #include <Core/Toolbox.h> | 35 #include <Core/Toolbox.h> |
36 #include <Core/SystemToolbox.h> | |
37 | |
38 #include <boost/filesystem.hpp> | |
35 | 39 |
36 namespace OrthancStone | 40 namespace OrthancStone |
37 { | 41 { |
38 static void CopyHttpHeaders(Orthanc::HttpClient& client, | 42 static void CopyHttpHeaders(Orthanc::HttpClient& client, |
39 const Orthanc::HttpClient::HttpHeaders& headers) | 43 const Orthanc::HttpClient::HttpHeaders& headers) |
176 | 180 |
177 return command.ProcessHttpAnswer(answer); | 181 return command.ProcessHttpAnswer(answer); |
178 } | 182 } |
179 | 183 |
180 | 184 |
185 static IMessage* Execute(const std::string& root, | |
186 const ReadFileCommand& command) | |
187 { | |
188 boost::filesystem::path a(root); | |
189 boost::filesystem::path b(command.GetPath()); | |
190 | |
191 boost::filesystem::path path; | |
192 if (b.is_absolute()) | |
193 { | |
194 path = b; | |
195 } | |
196 else | |
197 { | |
198 path = a / b; | |
199 } | |
200 | |
201 std::string content; | |
202 Orthanc::SystemToolbox::ReadFile(content, path.string(), true /* log */); | |
203 | |
204 return new ReadFileCommand::SuccessMessage(command, content); | |
205 } | |
206 | |
207 | |
181 IMessage* GenericOracleRunner::Run(IOracleCommand& command) | 208 IMessage* GenericOracleRunner::Run(IOracleCommand& command) |
182 { | 209 { |
183 try | 210 try |
184 { | 211 { |
185 switch (command.GetType()) | 212 switch (command.GetType()) |
201 return Execute(orthanc_, dynamic_cast<const GetOrthancWebViewerJpegCommand&>(command)); | 228 return Execute(orthanc_, dynamic_cast<const GetOrthancWebViewerJpegCommand&>(command)); |
202 | 229 |
203 case IOracleCommand::Type_Custom: | 230 case IOracleCommand::Type_Custom: |
204 return dynamic_cast<CustomOracleCommand&>(command).Execute(*this); | 231 return dynamic_cast<CustomOracleCommand&>(command).Execute(*this); |
205 | 232 |
233 case IOracleCommand::Type_ReadFile: | |
234 return Execute(rootDirectory_, dynamic_cast<const ReadFileCommand&>(command)); | |
235 | |
206 default: | 236 default: |
207 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | 237 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
208 } | 238 } |
209 } | 239 } |
210 catch (Orthanc::OrthancException& e) | 240 catch (Orthanc::OrthancException& e) |