static private Boolean isAlreadyTested(OutputArgs outputArgs, int date, string place, string format, string email) { Boolean isTested = false; foreach (OutputArg outputArg in outputArgs.Output) { if (outputArg.Date == date && outputArg.Place == place && outputArg.Format == format && outputArg.Email == email && outputArg.Found ) { isTested = true; } } return(isTested); }
static void Main(string[] args) { string inputArgsString = System.IO.File.ReadAllText(@"<path>\inputArgs.json"); string outputArgsString = System.IO.File.ReadAllText(@"<path>\outputArgs.json"); InputArgs inputArgs = JsonConvert.DeserializeObject <InputArgs>(inputArgsString); OutputArgs outputArgs = JsonConvert.DeserializeObject <OutputArgs>(outputArgsString); List <OutputArg> newoutputArgsList = new List <OutputArg>(); foreach (int date in inputArgs.Dates) { foreach (string place in inputArgs.Places) { foreach (string format in inputArgs.Formats) { string detailsString = getDetails(date, place, format); dynamic details = JsonConvert.DeserializeObject <dynamic>(detailsString); //dynamic details = JValue.Parse(detailsString); Boolean isShowPresent = details.BookMyShow.arrShows.Count != 0; string finalDetails = ""; if (isShowPresent) { string show = details.BookMyShow.arrEvent[0].Name + " " + details.BookMyShow.arrEvent[0].LanguageCode + " " + details.BookMyShow.arrEvent[0].Dimension; string venue = details.BookMyShow.arrVenue[0].VenueName; string finalDate; DateTime dt; if (DateTime.TryParseExact(date.ToString(), "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt)) { finalDate = dt.ToString(); } else { finalDate = date.ToString(); } string times = ""; for (int index = 0; index < details.BookMyShow.arrShows.Count; index++) { times += "\n" + "Show timings: " + details.BookMyShow.arrShows[index].ShowTimeDisplay; } finalDetails = show + "\n" + venue + "\n" + finalDate + "\n" + times; } foreach (string email in inputArgs.Emails) { if (!isAlreadyTested(outputArgs, date, place, format, email) && isShowPresent) { System.Console.WriteLine(finalDetails); sendMail(finalDetails, email); } if (isShowPresent) { OutputArg outpurArgs = new OutputArg(); outpurArgs.Date = date; outpurArgs.Email = email; outpurArgs.Format = format; outpurArgs.Place = place; outpurArgs.Found = true; newoutputArgsList.Add(outpurArgs); } } } } } OutputArgs newOutputArgs = new OutputArgs(); newOutputArgs.Output = newoutputArgsList.ToArray(); string newOutputString = JsonConvert.SerializeObject(newOutputArgs); string[] lines = { newOutputString }; System.IO.File.WriteAllLines(@"<path>\outputArgs.json", lines); }