/// <summary>
 /// event handlers
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="request"></param>
 public void OnOutgoingRequest(object sender, Requests.Request request)
 {
     if (request.GetType() == typeof(Requests.OutgoingCallRequest))
     {
         RegisterOutgoingRequest(request as Requests.OutgoingCallRequest);
     }
 }
Esempio n. 2
0
 public void OnOutgoingCall(object sender, Requests.Request request)
 {
     if (request.GetType() == typeof(Requests.OutgoingCallRequest) && this.State == PortState.Free)
     {
         this.State = PortState.Busy;
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Check <see cref="t:Sdk.Api.IApiRequestSender"/>.
        /// </summary>
        /// <returns>Check <see cref="t:Sdk.Api.IApiRequestSender"/>.</returns>
        /// <param name="request">Check <see cref="t:Sdk.Api.IApiRequestSender"/>.</param>
        /// <typeparam name="T">Check <see cref="t:Sdk.Api.IApiRequestSender"/>.</typeparam>
        public async Task <T> SendRequestAsync <T>(Requests.Request <T> request)
        {
            if (request.Authenticated && !_credentials.AreValid())
            {
                await _semaphore.WaitAsync().ConfigureAwait(false);

                if (!_credentials.AreValid())
                {
                    try
                    {
                        await RefreshToken().ConfigureAwait(false);
                    }
                    finally
                    {
                        _semaphore.Release();
                    }
                }
            }

            var httpRequest    = CreateHttpRequest(request);
            var responseString = await _httpSender.SendHttpRequest(httpRequest).ConfigureAwait(false);

            if (!string.IsNullOrEmpty(responseString))
            {
                return(JsonConvert.DeserializeObject <T>(responseString));
            }

            return(default(T));
        }
Esempio n. 4
0
        private HttpRequestMessage CreateHttpRequest <T>(Requests.Request <T> request)
        {
            var parameters         = _queryDecoder.GetParameters(request.Query);
            var httpRequestMessage = HttpRequestMessageFactory.Create(
                _configuration.BaseUrl.ToString(),
                request.HTTPMethod,
                parameters,
                request.Path);

            if (request.Authenticated)
            {
                httpRequestMessage.Headers.Authorization =
                    new AuthenticationHeaderValue(_credentials.TokenType, _credentials.AccessToken);
            }

            return(httpRequestMessage);
        }
Esempio n. 5
0
 public Responses.Request Send(Requests.Request request)
 {
     return(client.PostBody <Responses.Request>("requests", request));
 }
Esempio n. 6
0
 public abstract IHttpAction Handle(Requests.Request request);
Esempio n. 7
0
 private void OnIncomingRequest(object sender, Requests.IncomingRequest request)
 {
     IncomingRequest?.Invoke(sender, request);
     CurrentRequest = request;
 }
 public IHttpAction Execute(Requests.Request request)
 {
     return(RequestHandler.Handle(request));
 }