/// <inheritdoc/>
        public async Task <TextResource> Get(string org, string app, string language, EnvironmentModel environmentModel)
        {
            Uri uri = CreateGetAndPutUri(environmentModel, org, app, language);

            HttpClientHelper.AddSubscriptionKeys(_httpClient, uri, _platformSettings);
            HttpRequestMessage  request  = new HttpRequestMessage(HttpMethod.Get, uri);
            HttpResponseMessage response = await _httpClient.SendAsync(request);

            return(await response.Content.ReadAsAsync <TextResource>());
        }
        /// <inheritdoc/>
        public async Task Update(string org, string app, TextResource textResource, EnvironmentModel environmentModel)
        {
            Uri uri = CreateGetAndPutUri(environmentModel, org, app, textResource.Language);

            HttpClientHelper.AddSubscriptionKeys(_httpClient, uri, _platformSettings);
            string             stringContent = JsonSerializer.Serialize(textResource);
            HttpRequestMessage request       = new HttpRequestMessage(HttpMethod.Put, uri)
            {
                Content = new StringContent(stringContent, Encoding.UTF8, "application/json"),
            };
            await _httpClient.SendAsync(request);
        }
        /// <inheritdoc />
        public async Task <Application> GetApplicationMetadata(string org, string app, EnvironmentModel environmentModel)
        {
            Uri uri = new Uri($"{CreateUri(environmentModel)}{org}/{app}");

            HttpClientHelper.AddSubscriptionKeys(_httpClient, uri, _platformSettings);

            /*
             * Have to create a HttpRequestMessage instead of using helper extension methods like _httpClient.PostAsync(...)
             * because the base address can change on each request and after HttpClient gets initial base address,
             * it is not advised (and not allowed) to change base address.
             */
            HttpRequestMessage  request  = new HttpRequestMessage(HttpMethod.Get, uri);
            HttpResponseMessage response = await _httpClient.SendAsync(request);

            return(await response.Content.ReadAsAsync <Application>());
        }
예제 #4
0
        /// <inheritdoc />
        public async Task SavePolicy(string org, string app, string policyFile, EnvironmentModel environmentModel)
        {
            string uriString = $"https://{environmentModel.PlatformPrefix}.{environmentModel.Hostname}/{_platformSettings.ApiAuthorizationPolicyUri}";
            Uri    uri       = new Uri($"{uriString}?org={org}&app={app}");

            HttpClientHelper.AddSubscriptionKeys(_httpClient, uri, _platformSettings);

            /*
             * Have to create a HttpRequestMessage instead of using helper extension methods like _httpClient.PostAsync(...)
             * because the base address can change on each request and after HttpClient gets initial base address,
             * it is not advised (and not allowed) to change base address.
             */
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, uri)
            {
                Content = new StringContent(policyFile, Encoding.UTF8, "application/xml"),
            };

            await _httpClient.SendAsync(request);
        }
        /// <inheritdoc />
        public async Task UpdateApplicationMetadata(
            string org,
            string app,
            Application applicationMetadata,
            EnvironmentModel environmentModel)
        {
            Uri uri = new Uri($"{CreateUri(environmentModel)}{org}/{app}");

            HttpClientHelper.AddSubscriptionKeys(_httpClient, uri, _platformSettings);
            string stringContent = JsonSerializer.Serialize(applicationMetadata);

            /*
             * Have to create a HttpRequestMessage instead of using helper extension methods like _httpClient.PostAsync(...)
             * because the base address can change on each request and after HttpClient gets initial base address,
             * it is not advised (and not allowed) to change base address.
             */
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, uri)
            {
                Content = new StringContent(stringContent, Encoding.UTF8, "application/json"),
            };
            await _httpClient.SendAsync(request);
        }