Exemplo n.º 1
0
        private async Task <PayRequest> GetStoreRequest(string id)
        {
            var result        = new List <PayRequest>();
            var storeResponse = await StoreRequestClient.ApiStoreGetWithHttpMessagesAsync();

            var content = storeResponse.Response.Content.ReadAsStringAsync();

            if (string.IsNullOrEmpty(content.Result))
            {
                return(null);
            }

            result.AddRange(from pr in JsonConvert.DeserializeObject <List <PayRequest> >(content.Result)
                            where !string.IsNullOrEmpty(pr.TransactionId) && pr.TransactionId.Equals(id, StringComparison.CurrentCultureIgnoreCase) ||
                            !string.IsNullOrEmpty(pr.SourceAddress) && pr.SourceAddress.Equals(id, StringComparison.CurrentCultureIgnoreCase) ||
                            !string.IsNullOrEmpty(pr.DestinationAddress) && pr.DestinationAddress.Equals(id, StringComparison.CurrentCultureIgnoreCase)
                            select pr);
            return(result.FirstOrDefault());
        }
        public async Task ProcessAsync()
        {
            await _log.WriteInfoAsync(ComponentName, "Process started", null,
                                      $"ProcessAsync is rised");


            var response = await _storeClient.ApiStoreGetWithHttpMessagesAsync();

            var json = await response.Response.Content.ReadAsStringAsync();

            var requests = JsonConvert.DeserializeObject <List <MerchantPayRequest> >(json);

            await _log.WriteInfoAsync(ComponentName, "Process requests", null,
                                      $"Process requests");

            foreach (var request in requests)
            {
                var handler = RequestHandler.Create(request, _settings, _bitcoinRepo, _merchantPayRequestRepository, _bitcoinApi);
                await handler.Handle();
            }

            await _log.WriteInfoAsync(ComponentName, "Process requests", null,
                                      $"Order requests");

            var orderStr = await _storeClient.ApiStoreOrderGetWithHttpMessagesAsync();

            json = await orderStr.Response.Content.ReadAsStringAsync();

            var orders    = JsonConvert.DeserializeObject <List <MerchantOrderRequest> >(json);
            var addresses = from o in orders
                            group o by o.SourceAddress
                            into go
                            select new MerchantOrderAddress(go.Key, go.OrderBy(o => o.TransactionWaitingTime.GetRepoDateTime()).ToList());

            foreach (var address in addresses)
            {
                var handler = RequestHandler.Create(address, _settings, _merchantOrderRequestRepository, _generateAddressMicroService, _log,
                                                    _bitcoinAggRepository, _rpcClient, _ninjaSettings);
                await handler.Handle();
            }
        }
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task ApiStoreGetAsync(this ILykkePayServiceStoreRequestMicroService operations, CancellationToken cancellationToken = default(CancellationToken))
 {
     (await operations.ApiStoreGetWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false)).Dispose();
 }