public async Task <(decimal?, bool)> GetProductPrice(string shopID, string productID) { var productPriceQuery = @" query($shopId:Uuid!,$productType: String){shop(id: $shopId) {product(productType: $productType) { sellingPrice}}}"; var queryVariables = new { shopId = shopID, productType = productID }; try { var graphQLProductPriceData = await RetryUtils.RetryIfThrown <Exception, GraphQLResponse <GraphQLProductPriceData> >(async() => await SendQueryAsync <GraphQLProductPriceData>( _clientUrl, productPriceQuery, queryVariables ), 10, 250, 1000); if (graphQLProductPriceData.Errors != null) { _logger.LogWarning(ExceptionEvents.GenerateEventId(LoggerEventType.GraphQLClientQuery), $"Query error: {JsonConvert.SerializeObject(graphQLProductPriceData.Errors)}"); return(graphQLProductPriceData.Data?.Shop?.Product?.SellingPrice, false); } return(graphQLProductPriceData.Data?.Shop?.Product?.SellingPrice, true); } catch (Exception e) { var eventID = new EventId(0, $"Get Product Price: {shopID} , {productID}"); _logger.LogError(eventID, e, "Error while getting product price"); return(null, false); } }
private void LoadMostSearches() { try { ExceptionEvents.RetryOnException(3, TimeSpan.FromSeconds(2), () => { Program.Log.Info("Preparing to display most searches"); BackGroundWorker.RunWorkAsync <List <string> >(() => GetMostSearches(), (data) => { if (InvokeRequired) { Invoke(new LoadMostSearchesCallBack(LoadMostSearches), new object[] { }); } else { int count = 0; foreach (var tag in data) { if (count <= 100) { FlowPanelMostSearches.Controls.Add(ControlExtensions.LabelMostSearch(tag, count)); } } count++; Program.Log.Info("Completed most searches"); } }); }); } catch (Exception ex) { LabelMostSearches.Visible = false; FlowPanelMostSearches.Visible = false; Program.Log.Error("Unable to get most searches", ex); } // Error occurred, so hide controls and skip... }
public async Task <ShopsData> GetShopsData() { var shopsDataQuery = @"{ shops { id } productTypes { name }}"; _logger.LogInformation("Fetching shops data..."); try { var qraphQLShopsData = await RetryUtils.RetryIfThrown <Exception, GraphQLResponse <GraphQLShopsData> >(async() => await SendQueryAsync <GraphQLShopsData>(_clientUrl, shopsDataQuery), 10, 250, 1000); var shopsData = new ShopsData() { ProductsIDs = qraphQLShopsData.Data.ProductTypes.Select(x => x.Name).ToList(), ShopsIDs = qraphQLShopsData.Data.Shops.Select(x => x.Id).ToList() }; if (qraphQLShopsData.Errors != null) { _logger.LogWarning($"Fetched shops data with warnings: {qraphQLShopsData.Errors}"); return(shopsData); } _logger.LogInformation("Fetched shops data successfully"); return(shopsData); } catch (Exception e) { _logger.LogError(ExceptionEvents.GenerateEventId(LoggerEventType.GraphQLClient), e, "Error while getting shop data"); return(null); } }