Exemplo n.º 1
0
        private async Task WorkQueue()
        {
            if (queueRunning)
            {
                return;
            }

            queueRunning = true;

            foreach (var pending in _pendingQueues)
            {
                await SendQueue(pending);
            }

            if (_currentQueue != null)
            {
                var queueToSend = _currentQueue;
                lock (_lockObj)
                {
                    _currentQueue = null;
                }
                queueToSend.Rand     = this.rnd.Next(100, 9999999).ToString();
                queueToSend.Endpoint = await this.client.GetEndpointInfo();

                await SendQueue(queueToSend);
            }

            queueRunning = false;
        }
Exemplo n.º 2
0
 private async Task <EndpointMessageQueue> GetCurrentQueue()
 {
     if (_currentQueue == null)
     {
         lock (_lockObj)
         {
             _currentQueue         = new EndpointMessageQueue();
             _currentQueue.Content = new System.Collections.ObjectModel.ObservableCollection <EndpointMessage>();
         }
     }
     return(_currentQueue);
 }
Exemplo n.º 3
0
        private async Task SendQueue(EndpointMessageQueue queueToSend)
        {
            try
            {
                await this.client.SendQueue(queueToSend);

                if (this._pendingQueues.Contains(queueToSend))
                {
                    this._pendingQueues.Remove(queueToSend);
                }
            }
            catch (Exception ex)
            {
                if (!this._pendingQueues.Contains(queueToSend))
                {
                    this._pendingQueues.Add(queueToSend);
                }
            }
        }
        /// <returns>Success</returns>
        /// <exception cref="SwaggerException">A server side error occurred.</exception>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        public async System.Threading.Tasks.Task ApiByVersionEndpointByEndpointEventPostAsync(string endpoint, string x_Congether_SIGN, EndpointMessageQueue eventQueue, System.Threading.CancellationToken cancellationToken)
        {
            if (endpoint == null)
            {
                throw new System.ArgumentNullException("endpoint");
            }

            var urlBuilder_ = new System.Text.StringBuilder();

            urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/1.0/Endpoint/{endpoint}/event");
            urlBuilder_.Replace("{endpoint}", System.Uri.EscapeDataString(ConvertToString(endpoint, System.Globalization.CultureInfo.InvariantCulture)));

            var client_ = new System.Net.Http.HttpClient();

            try
            {
                using (var request_ = new System.Net.Http.HttpRequestMessage())
                {
                    if (x_Congether_SIGN != null)
                    {
                        request_.Headers.TryAddWithoutValidation("X-Congether-SIGN", ConvertToString(x_Congether_SIGN, System.Globalization.CultureInfo.InvariantCulture));
                    }
                    var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(eventQueue, _settings.Value));
                    content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json");
                    request_.Content             = content_;
                    request_.Method = new System.Net.Http.HttpMethod("POST");

                    //SIGN CONTENT
                    if (x_Congether_SIGN == null)
                    {
                        request_.Headers.TryAddWithoutValidation("X-Congether-SIGN", ConvertToString(GetHMACSHA256(await content_.ReadAsStreamAsync(), _apiSecret), System.Globalization.CultureInfo.InvariantCulture));
                    }
                    //END SIGN CONTENT

                    PrepareRequest(client_, request_, urlBuilder_);
                    var url_ = urlBuilder_.ToString();
                    request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
                    PrepareRequest(client_, request_, url_);

                    var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);

                    try
                    {
                        var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
                        if (response_.Content != null && response_.Content.Headers != null)
                        {
                            foreach (var item_ in response_.Content.Headers)
                            {
                                headers_[item_.Key] = item_.Value;
                            }
                        }

                        ProcessResponse(client_, response_);

                        var status_ = ((int)response_.StatusCode).ToString();
                        if (status_ == "200")
                        {
                            return;
                        }
                        else
                        if (status_ != "200" && status_ != "204")
                        {
                            var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);

                            throw new SwaggerException("The HTTP status code of the response was not expected (" + (int)response_.StatusCode + ").", (int)response_.StatusCode, responseData_, headers_, null);
                        }
                    }
                    finally
                    {
                        if (response_ != null)
                        {
                            response_.Dispose();
                        }
                    }
                }
            }
            finally
            {
                if (client_ != null)
                {
                    client_.Dispose();
                }
            }
        }
 /// <returns>Success</returns>
 /// <exception cref="SwaggerException">A server side error occurred.</exception>
 public System.Threading.Tasks.Task ApiByVersionEndpointByEndpointEventPostAsync(string endpoint, string x_Congether_SIGN, EndpointMessageQueue eventQueue)
 {
     return(ApiByVersionEndpointByEndpointEventPostAsync(endpoint, x_Congether_SIGN, eventQueue, System.Threading.CancellationToken.None));
 }
Exemplo n.º 6
0
 internal async Task SendQueue(EndpointMessageQueue queue)
 {
     await this._client.ApiByVersionEndpointByEndpointEventPostAsync(this._endpoint, null, queue);
 }