/// <summary>
        /// Lists chronological/historical representation of <see cref="ConfigurationSetting"/> from the configuration store that match the options selected in the <see cref="SettingSelector"/>.
        /// </summary>
        /// <remarks>Revisions are provided in descending order from their respective <see cref="ConfigurationSetting.LastModified"/> date.</remarks>
        /// <param name="selector">Set of options for selecting settings from the configuration store.</param>
        /// <param name="pageLink"></param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
        private Page <ConfigurationSetting> GetRevisionsPage(SettingSelector selector, string pageLink, CancellationToken cancellationToken = default)
        {
            using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.ApplicationModel.Configuration.ConfigurationClient.GetRevisionsPage");
            scope.Start();

            try
            {
                using Request request = CreateGetRevisionsRequest(selector, pageLink);
                Response response = _pipeline.SendRequest(request, cancellationToken);
                switch (response.Status)
                {
                case 200:
                case 206:
                    SettingBatch settingBatch = ConfigurationServiceSerializer.ParseBatch(response);
                    return(new Page <ConfigurationSetting>(settingBatch.Settings, settingBatch.NextBatchLink, response));

                default:
                    throw response.CreateRequestFailedException();
                }
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
Esempio n. 2
0
        public async Task <Response <SettingBatch> > GetRevisionsAsync(SettingSelector selector, CancellationToken cancellation = default)
        {
            using (var request = _pipeline.CreateRequest())
            {
                request.Method = HttpPipelineMethod.Get;
                BuildUriForRevisions(request.UriBuilder, selector);
                request.AddHeader(MediaTypeKeyValueApplicationHeader);
                if (selector.AsOf.HasValue)
                {
                    var dateTime = selector.AsOf.Value.UtcDateTime.ToString(AcceptDateTimeFormat);
                    request.AddHeader(AcceptDatetimeHeader, dateTime);
                }
                var response = await _pipeline.SendRequestAsync(request, cancellation).ConfigureAwait(false);

                if (response.Status == 200 || response.Status == 206 /* partial */)
                {
                    var batch = await ConfigurationServiceSerializer.ParseBatchAsync(response, selector, cancellation);

                    return(new Response <SettingBatch>(response, batch));
                }
                else
                {
                    throw new RequestFailedException(response);
                }
            }
        }
        static ReadOnlyMemory <byte> Serialize(ConfigurationSetting setting)
        {
            var writer = new ArrayBufferWriter <byte>();

            ConfigurationServiceSerializer.Serialize(setting, writer);
            return(writer.WrittenMemory);
        }
Esempio n. 4
0
        public async Task <Response <SettingBatch> > GetRevisionsAsync(BatchRequestOptions options, CancellationToken cancellation = default)
        {
            var uri = BuildUriForRevisions(options);

            using (var request = _pipeline.CreateRequest())
            {
                request.SetRequestLine(HttpVerb.Get, uri);

                request.AddHeader(MediaTypeKeyValueApplicationHeader);
                AddOptionsHeaders(options, request);

                var response = await _pipeline.SendRequestAsync(request, cancellation).ConfigureAwait(false);

                if (response.Status == 200 || response.Status == 206 /* partial */)
                {
                    var batch = await ConfigurationServiceSerializer.ParseBatchAsync(response, options, cancellation);

                    return(new Response <SettingBatch>(response, batch));
                }
                else
                {
                    throw new RequestFailedException(response);
                }
            }
        }
        /// <summary>
        /// Lists chronological/historical representation of <see cref="ConfigurationSetting"/> from the configuration store that match the options selected in the <see cref="SettingSelector"/>.
        /// </summary>
        /// <remarks>Revisions are provided in descending order from their respective <see cref="ConfigurationSetting.LastModified"/> date.</remarks>
        /// <param name="selector">Set of options for selecting settings from the configuration store.</param>
        /// <param name="pageLink"></param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
        private async Task <PageResponse <ConfigurationSetting> > GetRevisionsPageAsync(SettingSelector selector, string pageLink, CancellationToken cancellationToken = default)
        {
            using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("ConfigurationClient.Set");
            scope.Start();

            try
            {
                using Request request = CreateGetRevisionsRequest(selector, pageLink);
                Response response = await _pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);

                switch (response.Status)
                {
                case 200:
                case 206:
                    SettingBatch settingBatch = await ConfigurationServiceSerializer.ParseBatchAsync(response, cancellationToken).ConfigureAwait(false);

                    return(new PageResponse <ConfigurationSetting>(settingBatch.Settings, response, settingBatch.NextBatchLink));

                default:
                    throw await response.CreateRequestFailedExceptionAsync().ConfigureAwait(false);
                }
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Lists chronological/historical representation of <see cref="ConfigurationSetting"/> from the configuration store that match the options selected in the <see cref="SettingSelector"/>.
        /// </summary>
        /// <remarks>Revisions are provided in descending order from their respective <see cref="ConfigurationSetting.LastModified"/> date.</remarks>
        /// <param name="selector">Set of options for selecting settings from the configuration store.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
        private PageResponse <ConfigurationSetting> GetRevisionsPage(SettingSelector selector, string pageLink, CancellationToken cancellationToken = default)
        {
            using (Request request = CreateGetRevisionsRequest(selector, pageLink))
            {
                Response response = _pipeline.SendRequest(request, cancellationToken);
                switch (response.Status)
                {
                case 200:
                case 206:
                    SettingBatch settingBatch = ConfigurationServiceSerializer.ParseBatch(response);
                    return(new PageResponse <ConfigurationSetting>(settingBatch.Settings, response, settingBatch.NextBatchLink));

                default:
                    throw response.CreateRequestFailedException();
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Fetches the <see cref="ConfigurationSetting"/> from the configuration store that match the options selected in the <see cref="SettingSelector"/>.
        /// </summary>
        /// <param name="selector">Set of options for selecting settings from the configuration store.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
        public virtual Response <SettingBatch> GetBatch(SettingSelector selector, CancellationToken cancellationToken = default)
        {
            using (Request request = CreateBatchRequest(selector))
            {
                Response response = _pipeline.SendRequest(request, cancellationToken);

                switch (response.Status)
                {
                case 200:
                case 206:
                    return(new Response <SettingBatch>(response, ConfigurationServiceSerializer.ParseBatch(response, selector, cancellationToken)));

                default:
                    throw response.CreateRequestFailedException();
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Fetches the <see cref="ConfigurationSetting"/> from the configuration store that match the options selected in the <see cref="SettingSelector"/>.
        /// </summary>
        /// <param name="selector">Set of options for selecting settings from the configuration store.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
        public virtual async Task <Response <SettingBatch> > GetBatchAsync(SettingSelector selector, CancellationToken cancellationToken = default)
        {
            using (Request request = CreateBatchRequest(selector))
            {
                Response response = await _pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);

                switch (response.Status)
                {
                case 200:
                case 206:
                    return(new Response <SettingBatch>(response, await ConfigurationServiceSerializer.ParseBatchAsync(response, selector, cancellationToken)));

                default:
                    throw await response.CreateRequestFailedExceptionAsync();
                }
            }
        }
        static ReadOnlyMemory <byte> Serialize(ConfigurationSetting setting)
        {
            ReadOnlyMemory <byte> content = default;
            int size = 256;

            while (true)
            {
                byte[] buffer = new byte[size];
                if (ConfigurationServiceSerializer.TrySerialize(setting, buffer, out int written))
                {
                    content = buffer.AsMemory(0, written);
                    break;
                }
                size *= 2;
            }

            return(content);
        }
Esempio n. 10
0
        /// <summary>
        /// Lists chronological/historical representation of <see cref="ConfigurationSetting"/> from the configuration store that match the options selected in the <see cref="SettingSelector"/>.
        /// </summary>
        /// <remarks>Revisions are provided in descending order from their respective <see cref="ConfigurationSetting.LastModified"/> date.</remarks>
        /// <param name="selector">Set of options for selecting settings from the configuration store.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
        private async Task <PageResponse <ConfigurationSetting> > GetRevisionsPageAsync(SettingSelector selector, string pageLink, CancellationToken cancellationToken = default)
        {
            using (Request request = CreateGetRevisionsRequest(selector, pageLink))
            {
                Response response = await _pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);

                switch (response.Status)
                {
                case 200:
                case 206:
                    SettingBatch settingBatch = await ConfigurationServiceSerializer.ParseBatchAsync(response, cancellationToken).ConfigureAwait(false);

                    return(new PageResponse <ConfigurationSetting>(settingBatch.Settings, response, settingBatch.NextBatchLink));

                default:
                    throw await response.CreateRequestFailedExceptionAsync().ConfigureAwait(false);
                }
            }
        }
        static async Task <Response <ConfigurationSetting> > CreateResponse(Response response, CancellationToken cancellation)
        {
            ConfigurationSetting result = await ConfigurationServiceSerializer.DeserializeSettingAsync(response.ContentStream, cancellation);

            return(new Response <ConfigurationSetting>(response, result));
        }
 static Response <ConfigurationSetting> CreateResponse(Response response)
 {
     return(new Response <ConfigurationSetting>(response, ConfigurationServiceSerializer.DeserializeSetting(response.ContentStream)));
 }
Esempio n. 13
0
 static Response <ConfigurationSetting> CreateResponse(Response response, CancellationToken cancellation)
 {
     return(new Response <ConfigurationSetting>(response, ConfigurationServiceSerializer.DeserializeSetting(response.ContentStream, cancellation)));
 }