# HG changeset patch # User Sebastien Jodogne # Date 1630070244 -7200 # Node ID 219d05f8d73c84b1a343dbcceaca3f5e318e3b58 # Parent cb0ace7b4994fd4714b4133f3b61fa98eb65f96c added a configuration section "Tcia" diff -r cb0ace7b4994 -r 219d05f8d73c Plugin/Plugin.cpp --- a/Plugin/Plugin.cpp Fri Aug 27 13:40:10 2021 +0200 +++ b/Plugin/Plugin.cpp Fri Aug 27 15:17:24 2021 +0200 @@ -301,49 +301,78 @@ } OrthancPluginSetDescription(context, "Interface with TCIA (The Cancer Imaging Archive)."); - OrthancPluginSetRootUri(context, "/tcia/app/index.html"); + try { - std::string explorer; - Orthanc::EmbeddedResources::GetFileResource( - explorer, Orthanc::EmbeddedResources::ORTHANC_EXPLORER_JS); - OrthancPluginExtendOrthancExplorer(OrthancPlugins::GetGlobalContext(), explorer.c_str()); - } - - OrthancPluginRegisterJobsUnserializer(context, TciaJobUnserializer); + static const char* const KEY_TCIA = "Tcia"; + + OrthancPlugins::OrthancConfiguration configuration; - OrthancPlugins::RegisterRestCallback("/tcia/app/index.html", true /* thread safe */); - OrthancPlugins::RegisterRestCallback("/tcia/app/app.js", true /* thread safe */); - OrthancPlugins::RegisterRestCallback("/tcia/clear-cache", true /* thread safe */); - OrthancPlugins::RegisterRestCallback("/tcia/proxy/(.*)", true /* thread safe */); - OrthancPlugins::RegisterRestCallback("/tcia/import", true /* thread safe */); + if (!configuration.IsSection(KEY_TCIA)) + { + LOG(WARNING) << "No available configuration for the TCIA plugin, disabling it"; + return 0; + } + + OrthancPlugins::OrthancConfiguration tcia; + configuration.GetSection(tcia, KEY_TCIA); - { - using namespace Orthanc; + if (!tcia.GetBooleanValue("Enable", false)) + { + LOG(WARNING) << "The TCIA index is currently disabled, set \"Enable\" " + << "to \"true\" in the \"" << KEY_TCIA << "\" section of the configuration file of Orthanc"; + return 0; + } - RegisterEmbeddedResource( - "/tcia/app/css/bootstrap.min.css"); + OrthancPluginSetRootUri(context, "/tcia/app/index.html"); - RegisterEmbeddedResource( - "/tcia/app/css/bootstrap.min.css.map"); + { + std::string explorer; + Orthanc::EmbeddedResources::GetFileResource( + explorer, Orthanc::EmbeddedResources::ORTHANC_EXPLORER_JS); + OrthancPluginExtendOrthancExplorer(OrthancPlugins::GetGlobalContext(), explorer.c_str()); + } + + OrthancPluginRegisterJobsUnserializer(context, TciaJobUnserializer); - RegisterEmbeddedResource( - "/tcia/app/js/axios.min.js"); + OrthancPlugins::RegisterRestCallback("/tcia/app/index.html", true /* thread safe */); + OrthancPlugins::RegisterRestCallback("/tcia/app/app.js", true /* thread safe */); + OrthancPlugins::RegisterRestCallback("/tcia/clear-cache", true /* thread safe */); + OrthancPlugins::RegisterRestCallback("/tcia/proxy/(.*)", true /* thread safe */); + OrthancPlugins::RegisterRestCallback("/tcia/import", true /* thread safe */); - RegisterEmbeddedResource( - "/tcia/app/js/axios.min.map"); + { + using namespace Orthanc; + + RegisterEmbeddedResource( + "/tcia/app/css/bootstrap.min.css"); - RegisterEmbeddedResource( - "/tcia/app/js/vue.min.js"); + RegisterEmbeddedResource( + "/tcia/app/css/bootstrap.min.css.map"); + + RegisterEmbeddedResource( + "/tcia/app/js/axios.min.js"); - RegisterEmbeddedResource( - "/tcia/app/images/tcia-logo.png"); + RegisterEmbeddedResource( + "/tcia/app/js/axios.min.map"); + + RegisterEmbeddedResource( + "/tcia/app/js/vue.min.js"); - RegisterEmbeddedResource( - "/tcia/app/images/orthanc-logo.png"); + RegisterEmbeddedResource( + "/tcia/app/images/tcia-logo.png"); + + RegisterEmbeddedResource( + "/tcia/app/images/orthanc-logo.png"); - RegisterEmbeddedResource( - "/tcia/app/images/nbia-export.png"); + RegisterEmbeddedResource( + "/tcia/app/images/nbia-export.png"); + } + } + catch (Orthanc::OrthancException& e) + { + LOG(ERROR) << "Exception while initializing the TCIA plugin: " << e.What(); + return -1; } return 0;