/// <summary>
        /// Constructor
        /// </summary>
        /// <param name="authenticationCallback"> the authentication callback </param>
        /// <param name="sendRequestCallback"> the send request callback to log request that is sent </param>
        /// <param name="receiveResponseCallback"> the receive response callback to log response that is received </param>
        /// <param name="httpClient"> customized http client </param>
        /// <param name="setRequestUriCallback"> the callback to replace requst URI with a different URI </param>
        public KeyVaultClient(
            AuthenticationCallback authenticationCallback,
            SendRequestCallback sendRequestCallback         = null,
            ReceiveResponseCallback receiveResponseCallback = null,
            HttpClient httpClient = null,
            SetRequestUriCallback setRequestUriCallback = null)
            : this(httpClient)
        {
            if (authenticationCallback == null)
            {
                throw new ArgumentNullException("authenticationCallback");
            }

            OnAuthenticate    = authenticationCallback;
            OnSendRequest     = sendRequestCallback;
            OnReceiveResponse = receiveResponseCallback;
            OnSetRequestUri   = setRequestUriCallback;
        }
示例#2
0
        public ClientRequestHandle(ClientFactoryContext context, SendRequestCallback sendRequestCallback, CancellationToken cancellationToken = default,
                                   RequestTimeout timeout = default, Guid?requestId = default, TaskScheduler taskScheduler = default)
        {
            _context             = context;
            _sendRequestCallback = sendRequestCallback;
            _cancellationToken   = cancellationToken;

            var requestTimeout = timeout.HasValue ? timeout : _context.DefaultTimeout.HasValue ? _context.DefaultTimeout.Value : RequestTimeout.Default;

            _timeToLive = requestTimeout;

            _requestId = requestId ?? NewId.NextGuid();

            _taskScheduler = taskScheduler ??
                             (SynchronizationContext.Current == null
                    ? TaskScheduler.Default
                    : TaskScheduler.FromCurrentSynchronizationContext());

            _message                 = new TaskCompletionSource <TRequest>();
            _pipeConfigurator        = new PipeConfigurator <SendContext <TRequest> >();
            _sendContext             = TaskUtil.GetTask <SendContext <TRequest> >();
            _readyToSend             = TaskUtil.GetTask <bool>();
            _cancellationTokenSource = new CancellationTokenSource();
            _responseHandlers        = new Dictionary <Type, HandlerConnectHandle>();
            _accept = new List <string>();

            if (cancellationToken != default && cancellationToken.CanBeCanceled)
            {
                _registration = cancellationToken.Register(Cancel);
            }

            _timeoutTimer = new Timer(TimeoutExpired, this, (long)_timeToLive.Value.TotalMilliseconds, -1L);

            _send = SendRequest();

        #pragma warning disable 4014
            HandleFault();
        #pragma warning restore 4014
        }