Ejemplo n.º 1
0
storage_uri::storage_uri(const web::http::uri& primary_uri, const web::http::uri& secondary_uri)
    : m_primary_uri(primary_uri), m_secondary_uri(secondary_uri)
{
    if (primary_uri.is_empty())
    {
        throw std::invalid_argument("primary_uri");
    }

    if (!secondary_uri.is_empty() &&
            (primary_uri.resource() != secondary_uri.resource()))
    {
        throw std::invalid_argument(utility::conversions::to_utf8string(protocol::error_storage_uri_mismatch));
    }
}
    web::http::uri generate_queue_uri(const web::http::uri& base_uri, const utility::string_t& prefix, bool get_metadata, int max_results, const continuation_token& continuation_token)
    {
        if (base_uri.is_empty())
        {
            return web::http::uri();
        }

        web::http::uri_builder builder(base_uri);

        if (!prefix.empty())
        {
            builder.append_query(U("prefix"), prefix);
        }

        if (get_metadata)
        {
            builder.append_query(U("include"), U("metadata"));
        }

        if (max_results >= 0)
        {
            builder.append_query(U("maxresults"), max_results);
        }

        if (!continuation_token.empty())
        {
            builder.append_query(continuation_token.next_marker());
        }

        return builder.to_uri();
    }
    web::http::uri generate_queue_uri(const web::http::uri& base_uri, const utility::string_t& prefix, bool get_metadata, int max_results, const continuation_token& token)
    {
        if (base_uri.is_empty())
        {
            return web::http::uri();
        }

        web::http::uri_builder builder(base_uri);

        if (!prefix.empty())
        {
            builder.append_query(core::make_query_parameter(uri_query_prefix, prefix));
        }

        if (get_metadata)
        {
            builder.append_query(core::make_query_parameter(uri_query_include, component_metadata, /* do_encoding */ false));
        }

        if (max_results > 0)
        {
            builder.append_query(core::make_query_parameter(uri_query_max_results, max_results, /* do_encoding */ false));
        }

        if (!token.empty())
        {
            builder.append_query(token.next_marker());
        }

        return builder.to_uri();
    }
    web::http::uri generate_queue_uri(const web::http::uri& base_uri, const cloud_queue& queue)
    {
        if (base_uri.is_empty())
        {
            return web::http::uri();
        }

        web::http::uri_builder builder(base_uri);
        builder.append_path(queue.name(), /* do_encoding */ true);
        return builder.to_uri();
    }
    web::http::uri generate_queue_message_uri(const web::http::uri& base_uri, const cloud_queue& queue, const utility::string_t& message_id)
    {
        if (base_uri.is_empty())
        {
            return web::http::uri();
        }

        web::http::uri_builder builder(base_uri);
        builder.append_path(queue.name(), /* do_encoding */ true);
        builder.append_path(_XPLATSTR("messages"));
        builder.append_path(message_id, /* do_encoding */ true);

        return builder.to_uri();
    }
    cloud_storage_account cloud_storage_account::get_development_storage_account(const web::http::uri& proxy_uri)
    {
        web::http::uri_builder builder;
        if (!proxy_uri.is_empty())
        {
            builder.set_scheme(proxy_uri.scheme());
            builder.set_host(proxy_uri.host());
        }
        else
        {
            builder.set_scheme(U("http"));
            builder.set_host(U("127.0.0.1"));
        }

        builder.set_path(devstore_account_name);

        builder.set_port(10000);
        auto blob_endpoint = storage_uri(builder.to_uri());

        builder.set_port(10001);
        auto queue_endpoint = storage_uri(builder.to_uri());

        builder.set_port(10002);
        auto table_endpoint = storage_uri(builder.to_uri());

        auto credentials = storage_credentials(devstore_account_name, devstore_account_key);
        auto account = cloud_storage_account(credentials, blob_endpoint, queue_endpoint, table_endpoint);
        
        account.m_is_development_storage_account = true;
        account.m_settings.insert(std::make_pair(use_development_storage_setting_string, use_development_storage_setting_value));
        if (!proxy_uri.is_empty())
        {
            account.m_settings.insert(std::make_pair(development_storage_proxy_uri_setting_string, proxy_uri.to_string()));
        }
        
        return account;
    }