| 552 | /////////////////////////////////////////////////////////////////////////// |
| 553 | |
| 554 | bool RemoteBCL::downloadComponent(const std::string& uid) { |
| 555 | // Check for empty uid |
| 556 | if (uid.empty()) { |
| 557 | LOG(Error, "Error: No uid provided"); |
| 558 | return false; |
| 559 | } |
| 560 | |
| 561 | // can't start another request until last one is done |
| 562 | if (m_httpResponse && !m_httpResponse->is_done()) { |
| 563 | LOG(Debug, "Cannot get mutex lock"); |
| 564 | return false; |
| 565 | } |
| 566 | |
| 567 | m_downloadFile = std::make_unique<DownloadFile>(openstudio::filesystem::temp_directory_path() / toPath(uid + ".bcl")); |
| 568 | if (!m_downloadFile->open()) { |
| 569 | return false; |
| 570 | } |
| 571 | |
| 572 | m_downloadUid = uid; |
| 573 | // request.setRawHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.56 Safari/537.17"); |
| 574 | auto client = getClient(remoteUrl(), m_timeOutSeconds); |
| 575 | web::uri_builder builder(to_string_t("/api/component/download")); |
| 576 | |
| 577 | builder.append_query(to_string_t("uids"), to_string_t(uid)); |
| 578 | |
| 579 | web::http::http_request msg(web::http::methods::GET); |
| 580 | msg.headers().add(to_string_t("User-Agent"), |
| 581 | to_string_t("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.56 Safari/537.17")); |
| 582 | msg.set_request_uri(builder.to_string()); |
| 583 | |
| 584 | // LOG(Debug, m_remoteUrl << builder.to_string()); |
| 585 | |
| 586 | m_httpResponse = client.request(web::http::methods::GET, builder.to_string()) |
| 587 | .then([](web::http::http_response resp) { return resp.extract_vector(); }) |
| 588 | .then([this](const std::vector<unsigned char>& zip) { |
| 589 | m_downloadFile->write(zip); |
| 590 | m_downloadFile->flush(); |
| 591 | m_downloadFile->close(); |
| 592 | }) |
| 593 | .then([this]() { onDownloadComplete(); }); |
| 594 | |
| 595 | return true; |
| 596 | } |
| 597 | |
| 598 | bool RemoteBCL::downloadMeasure(const std::string& uid) { |
| 599 | return downloadComponent(uid); |