Mercurial > hg > orthanc-stone
diff 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 |
line wrap: on
line diff
--- a/Framework/Oracle/GenericOracleRunner.cpp Sat Oct 26 11:44:38 2019 +0200 +++ b/Framework/Oracle/GenericOracleRunner.cpp Sat Oct 26 16:43:08 2019 +0200 @@ -27,11 +27,15 @@ #include "HttpCommand.h" #include "OracleCommandExceptionMessage.h" #include "OrthancRestApiCommand.h" +#include "ReadFileCommand.h" #include <Core/Compression/GzipCompressor.h> #include <Core/HttpClient.h> #include <Core/OrthancException.h> #include <Core/Toolbox.h> +#include <Core/SystemToolbox.h> + +#include <boost/filesystem.hpp> namespace OrthancStone { @@ -178,6 +182,29 @@ } + static IMessage* Execute(const std::string& root, + const ReadFileCommand& command) + { + boost::filesystem::path a(root); + boost::filesystem::path b(command.GetPath()); + + boost::filesystem::path path; + if (b.is_absolute()) + { + path = b; + } + else + { + path = a / b; + } + + std::string content; + Orthanc::SystemToolbox::ReadFile(content, path.string(), true /* log */); + + return new ReadFileCommand::SuccessMessage(command, content); + } + + IMessage* GenericOracleRunner::Run(IOracleCommand& command) { try @@ -203,6 +230,9 @@ case IOracleCommand::Type_Custom: return dynamic_cast<CustomOracleCommand&>(command).Execute(*this); + case IOracleCommand::Type_ReadFile: + return Execute(rootDirectory_, dynamic_cast<const ReadFileCommand&>(command)); + default: throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); }