private static void CheckProductAvailability(AppleHttpClient httpclient, string model, EmailConfig emailFromArg, string storeCode, string location) { var jsonString = httpclient.CheckiPhoneAvailability(model, location).Result; var json = JsonConvert.DeserializeObject(jsonString) as JObject; if (json == null) { Log.Error("Could not read the response data."); Console.WriteLine("Could not read Request data."); return; } var stores = json["body"]["stores"]; if (stores == null) { Log.Error("No stores found in the response json."); return; } var ourStore = storeCode != string.Empty ? stores.FirstOrDefault(x => x["storeNumber"].ToString() == storeCode) : stores.First(); if (ourStore == null) { Console.WriteLine("Store not found. "); return; } var modelDescription = ourStore["partsAvailability"][model]["storePickupProductTitle"].ToString(); var partsAvailabilityString = ourStore["partsAvailability"][model]["pickupSearchQuote"].ToString(); if (partsAvailabilityString != Constants.MensajeNoDisponible) { Log.Info($"iPhone {modelDescription} available."); var emailResult = Mailer.Notify(emailFromArg, modelDescription, ourStore["storeName"].ToString()).Result; if (emailResult) { return; } Console.WriteLine("Error sending e-mail."); Log.Error("Error sending e-mail."); } else { // retry later? Console.WriteLine($"iPhone {modelDescription} not available"); Log.Info($"iPhone {modelDescription} not available"); } }
static void Main() { var emailFromArg = ReadConfig(); var url = ConfigurationManager.AppSettings["RequestUrl"]; var productModels = ConfigurationManager.AppSettings["ProductModels"].Split(';'); var storeCode = ConfigurationManager.AppSettings["Store"]; var location = ConfigurationManager.AppSettings["Location"]; var httpclient = new AppleHttpClient(url); foreach (var model in productModels) { CheckProductAvailability(httpclient, model, emailFromArg, storeCode, location); } }