public async Task UpdateBankHolidaysAsync() { var client = new RestClient(_config.Url); var request = new RestRequest(); var response = await client.ExecuteTaskAsync <BankHolidays.BankHolidaysData>(request); if (!response.IsSuccessful) { throw new Exception($"Error getting list of bank holidays from url:{_config.Url}. Error:{response.ErrorMessage}"); } if (!response.Data.EnglandAndWales.Events.Any()) { throw new Exception($"Expected a non-empty list of bank holidays from url:{_config.Url}"); } var bankHolidays = new BankHolidays { Data = response.Data }; await _referenceDataWriter.UpsertReferenceData(bankHolidays); _logger.LogInformation($"Upserted bank holidays into ReferenceData store. Last England and Wales date:{bankHolidays.Data.EnglandAndWales.Events.Last().Date}"); }
private static void LocationPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) { string location = dependencyPropertyChangedEventArgs.NewValue as string; LocationEnum locationEnumValue; if (location != null && Enum.TryParse(location, true, out locationEnumValue)) { BankHolidays.Clear(); BankHolidays.AddRange(bankHolidayManager.GetHolidaysInLocation(locationEnumValue)); } }
// Using System.Net // NewtonSoft JSON.NET private BankHolidays GetUkGovBankHolidays() { string apiEndPoint = "https://www.gov.uk/bank-holidays.json"; BankHolidays apiHolidays = null; using (var wb = new WebClient()) { wb.Encoding = Encoding.UTF8; string response = wb.DownloadString(apiEndPoint); apiHolidays = JsonConvert.DeserializeObject <BankHolidays>(response); } return(apiHolidays); }
public void HandleNewBankHolidayEvent(NewBankHolidayEventPayload eventPayLoad) { if (log.IsDebugEnabled) { log.Debug("Received new bank holiday event from BankHolidayManager: " + eventPayLoad); } if (SelectedLocation != null && SelectedLocation == eventPayLoad.Location.ToString()) { BankHolidays.Add(new BankHolidayImpl() { HolidayDate = eventPayLoad.NewBankHolidayDate, Location = eventPayLoad.Location }); } }
private async Task <IEnumerable <DateTime> > GetBankHolidays() { List <BankHolidays> Holidays = new List <BankHolidays>(); string apiEndPoint = "https://www.gov.uk/bank-holidays.json"; BankHolidays apiHolidays = null; using (var wb = new WebClient()) { wb.Encoding = Encoding.UTF8; string response = wb.DownloadString(apiEndPoint); } apiHolidays = JsonConvert.DeserializeObject <BankHolidays>(response);//System.IO.File.ReadAllText(@"C:\Users\David Mimnagh\Documents\test.json")); List <DateTime> HolidayDates = new List <DateTime>(); HolidayDates = apiHolidays.EnglandAndWales.Events.Select(h => h.Date).ToList(); HolidayDates.AddRange(apiHolidays.NorthernIreland.Events.Select(h => h.Date).ToList()); HolidayDates.AddRange(apiHolidays.Scotland.Events.Select(h => h.Date).ToList()); HolidayDates = HolidayDates.Select(date => date).Where(date => date.Year >= DateTime.Now.Year).ToList(); return(HolidayDates); }
public void IsScotishBankHoliday(DateTime day, bool expected) { Assert.Equal(expected, BankHolidays.IsScotishBankHoliday(day)); }