| 24 | } |
| 25 | |
| 26 | void SourceProxy::loadSource(const std::string& source) |
| 27 | { |
| 28 | if (source.empty()) |
| 29 | { |
| 30 | throw std::runtime_error("No source selected."); |
| 31 | } |
| 32 | |
| 33 | std::pair<std::string, std::unordered_map<std::string, std::string>> deserialized_source(deserializeSource(source)); |
| 34 | std::string& source_path(deserialized_source.first); |
| 35 | std::unordered_map<std::string, std::string>& parameters(deserialized_source.second); |
| 36 | |
| 37 | try |
| 38 | { |
| 39 | fs::path potential_system_path(source_path); |
| 40 | if (fs::is_regular_file(potential_system_path) && checkParameters(parameters, FilelistSource::getRequiredParameterFields())) |
| 41 | { |
| 42 | m_source = std::unique_ptr<WorklistSourceInterface>(new FilelistSource(source_path)); |
| 43 | } |
| 44 | else if (fs::is_directory(potential_system_path) && checkParameters(parameters, DirectorySource::getRequiredParameterFields())) |
| 45 | { |
| 46 | m_source = std::unique_ptr<DirectorySource>(new DirectorySource(source_path)); |
| 47 | } |
| 48 | #ifdef BUILD_GRANDCHALLENGE_INTERFACE |
| 49 | else if (checkParameters(parameters, GrandChallengeSource::getRequiredParameterFields())) |
| 50 | { |
| 51 | web::http::client::http_client_config config; |
| 52 | config.set_validate_certificates(!static_cast<bool>(parameters.find("ignore_certificate")->second[0])); |
| 53 | |
| 54 | GrandChallengeURLInfo uri_info = GrandChallengeSource::getStandardURI(core::stringToWideString(source_path)); |
| 55 | DjangoConnection::Credentials credentials(DjangoConnection::CreateCredentials(core::stringToWideString(parameters.find("token")->second), L"")); |
| 56 | m_source = std::unique_ptr<WorklistSourceInterface>(new GrandChallengeSource(uri_info, m_temporary_directory, credentials, config)); |
| 57 | } |
| 58 | #endif |
| 59 | // Adds the new source to the previous sources. |
| 60 | m_current_source = source; |
| 61 | |
| 62 | auto already_added(std::find(m_previous_sources.begin(), m_previous_sources.end(), m_current_source)); |
| 63 | if (already_added != m_previous_sources.end()) |
| 64 | { |
| 65 | m_previous_sources.erase(already_added); |
| 66 | } |
| 67 | else if (m_previous_sources.size() == m_max_number_previous_sources) |
| 68 | { |
| 69 | m_previous_sources.pop_back(); |
| 70 | } |
| 71 | m_previous_sources.push_front(m_current_source); |
| 72 | } |
| 73 | catch (const std::exception& e) |
| 74 | { |
| 75 | throw std::runtime_error("Unable to open source: " + source_path + "\n" + e.what()); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | bool SourceProxy::isInitialized(void) |
| 80 | { |
no test coverage detected