Mercurial > hg > orthanc
diff UnitTests/FileStorage.cpp @ 224:4eb0c7ce86c9
refactoring for store
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 29 Nov 2012 22:22:00 +0100 |
parents | 6f0e4a8ebb0f |
children | 5368bbe813cf |
line wrap: on
line diff
--- a/UnitTests/FileStorage.cpp Thu Nov 29 18:07:50 2012 +0100 +++ b/UnitTests/FileStorage.cpp Thu Nov 29 22:22:00 2012 +0100 @@ -4,6 +4,7 @@ #include <glog/logging.h> #include "../Core/FileStorage.h" +#include "../OrthancServer/ServerIndex.h" #include "../Core/Toolbox.h" #include "../Core/OrthancException.h" #include "../Core/Uuid.h" @@ -130,8 +131,100 @@ ASSERT_NE(compressedData, r); #if defined(__linux) - // This tests is too slow on Windows + // This test is too slow on Windows accessor.SetCompressionForNextOperations(CompressionType_Zlib); ASSERT_THROW(accessor.Read(r, uncompressedId), OrthancException); #endif } + + + +#if 0 +// TODO REMOVE THIS STUFF +namespace Orthanc +{ + class ServerStorageAccessor : public StorageAccessor + { + private: + CompressedFileStorageAccessor composite_; + ServerIndex& index_; + AttachedFileType contentType_; + + protected: + virtual std::string WriteInternal(const void* data, + size_t size) + { + switch (contentType_) + { + case AttachedFileType_Json: + composite_.SetCompressionForNextOperations(CompressionType_None); + break; + + case AttachedFileType_Dicom: + // TODO GLOBAL PARAMETER + composite_.SetCompressionForNextOperations(CompressionType_Zlib); + break; + + default: + throw OrthancException(ErrorCode_InternalError); + } + + std::string fileUuid = composite_.Write(data, size); + + + } + + public: + ServerStorageAccessor(FileStorage& storage, + ServerIndex& index) : + composite_(storage), + index_(index) + { + contentType_ = AttachedFileType_Dicom; + } + + void SetAttachmentType(AttachedFileType type) + { + contentType_ = type; + } + + AttachedFileType GetAttachmentType() const + { + return contentType_; + } + + virtual void Read(std::string& content, + const std::string& uuid) + { + std::string fileUuid; + CompressionType compression; + + if (index_.GetFile(fileUuid, compression, uuid, contentType_)) + { + composite_.SetCompressionForNextOperations(compression); + composite_.Read(content, fileUuid); + } + else + { + throw OrthancException(ErrorCode_InternalError); + } + } + + virtual HttpFileSender* ConstructHttpFileSender(const std::string& uuid) + { + std::string fileUuid; + CompressionType compression; + + if (index_.GetFile(fileUuid, compression, uuid, contentType_)) + { + composite_.SetCompressionForNextOperations(compression); + return composite_.ConstructHttpFileSender(fileUuid); + } + else + { + throw OrthancException(ErrorCode_InternalError); + } + } + }; +} +#endif