Beispiel #1
0
        /// <summary>
        /// Creates and initializes a retryable read operation context.
        /// </summary>
        /// <param name="binding">The binding.</param>
        /// <param name="retryRequested">if set to <c>true</c> [retry requested].</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A retryable read context.</returns>
        public static async Task <RetryableReadContext> CreateAsync(IReadBinding binding, bool retryRequested, CancellationToken cancellationToken)
        {
            var context = new RetryableReadContext(binding, retryRequested);

            try
            {
                await context.InitializeAsync(cancellationToken).ConfigureAwait(false);

                if (ChannelPinningHelper.PinChannelSourceAndChannelIfRequired(
                        context.ChannelSource,
                        context.Channel,
                        context.Binding.Session,
                        out var pinnedChannelSource,
                        out var pinnedChannel))
                {
                    context.ReplaceChannelSource(pinnedChannelSource);
                    context.ReplaceChannel(pinnedChannel);
                }
                return(context);
            }
            catch
            {
                context.Dispose();
                throw;
            }
        }
Beispiel #2
0
        // public static methods
        /// <summary>
        /// Creates and initializes a retryable write operation context.
        /// </summary>
        /// <param name="binding">The binding.</param>
        /// <param name="retryRequested">if set to <c>true</c> [retry requested].</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A retryable write context.</returns>
        public static RetryableWriteContext Create(IWriteBinding binding, bool retryRequested, CancellationToken cancellationToken)
        {
            var context = new RetryableWriteContext(binding, retryRequested);

            try
            {
                context.Initialize(cancellationToken);

                if (context.Binding.Session.IsInTransaction &&
                    ChannelPinningHelper.PinChannelSourceAndChannelIfRequired(
                        context.ChannelSource,
                        context.Channel,
                        context.Binding.Session,
                        out var pinnedChannelSource,
                        out var pinnedChannel))
                {
                    context.ReplaceChannelSource(pinnedChannelSource);
                    context.ReplaceChannel(pinnedChannel);
                }

                return(context);
            }
            catch
            {
                context.Dispose();
                throw;
            }
        }