public static void LoadNewHolidayDates(ILogger logger, ICoreCache targetClient) { Assembly assembly = Assembly.GetExecutingAssembly(); const string prefix = "Orion.Configuration.Config.HolidayDates"; Dictionary <string, string> chosenFiles = ResourceHelper.GetResources(assembly, prefix, "xml"); if (chosenFiles.Count == 0) { throw new InvalidOperationException("Missing Date Rules"); } foreach (KeyValuePair <string, string> file in chosenFiles) { // load daterules from file var calendarYears = XmlSerializerHelper.DeserializeFromString <LocationCalendarYears>(file.Value); var businessCenterList = new Dictionary <string, BusinessCenterCalendar>(); foreach (LocationCalendarYear locationCalendarYear in calendarYears.LocationCalendarYear) { BusinessCenterCalendar result; var contains = businessCenterList.TryGetValue(locationCalendarYear.BusinessCenter, out result); if (!contains) { var bc = new BusinessCenterCalendar { BusinessCenter = locationCalendarYear.BusinessCenter, Location = locationCalendarYear.RDMLocation, LocationName = locationCalendarYear.LocationName, Holidays = locationCalendarYear.Holidays }; businessCenterList.Add(bc.BusinessCenter, bc); } else { if (locationCalendarYear.Holidays != null)// && result.Holidays != null) { var holidays = new List <DateRule>(); if (result.Holidays != null) { holidays = new List <DateRule>(result.Holidays); } holidays.AddRange(locationCalendarYear.Holidays);//Test if null result.Holidays = holidays.ToArray(); } } } foreach (var center in businessCenterList) { ItemInfo itemInfo = BusinessCenterHolidayConfigProps(center.Value); targetClient.SaveObject(center.Value, itemInfo.ItemName, itemInfo.ItemProps); logger.LogDebug("Loaded business center holiday dates: {0}", itemInfo.ItemName); } } logger.LogDebug("Loaded business center holiday dates."); }
/// <summary> /// Creates a user defined calendar. /// </summary> /// <param name="calendarProperties">THe calendar properties must include a valid FpML business center name.</param> /// <param name="holidaysDates">The dates that are in the defined calendar.</param> /// <returns></returns> public static BusinessCenterCalendar CreateCalendar(NamedValueSet calendarProperties, List <DateTime> holidaysDates) { //Build the calendar. var bc = new BusinessCenterCalendar(); var center = calendarProperties.GetValue <string>("BusinessCenter", true); bc.BusinessCenter = center; //bc.Location = locationCalendarYear.RDMLocation; //bc.LocationName = locationCalendarYear.LocationName; bc.Holidays = holidaysDates.Select(date => new DateRule { Item = date }).ToArray(); return(bc); }
private static ItemInfo BusinessCenterHolidayConfigProps(BusinessCenterCalendar locationCalendarYear) { var itemProps = new NamedValueSet(); itemProps.Set("BusinessCenter", locationCalendarYear.BusinessCenter); itemProps.Set("Location", locationCalendarYear.Location); itemProps.Set(CurveProp.DataGroup, "Orion.Configuration.BusinessCenterHolidays"); itemProps.Set("SourceSystem", "Orion"); itemProps.Set("Function", "Configuration"); itemProps.Set("Type", "BusinessCenterHolidays"); string itemName = string.Format("Orion.ReferenceData.BusinessCenterHolidays.{0}", locationCalendarYear.BusinessCenter); itemProps.Set(CurveProp.UniqueIdentifier, itemName); return(new ItemInfo { ItemName = itemName, ItemProps = itemProps }); }
private static ItemInfo BusinessCenterHolidayConfigProps(BusinessCenterCalendar locationCalendarYear, string nameSpace) { var itemProps = new NamedValueSet(); itemProps.Set("BusinessCenter", locationCalendarYear.BusinessCenter); itemProps.Set("Location", locationCalendarYear.Location); itemProps.Set(EnvironmentProp.DataGroup, "Orion.V5r3.Reporting.ReferenceData.BusinessCenterHolidays"); itemProps.Set(EnvironmentProp.SourceSystem, "Orion"); itemProps.Set(EnvironmentProp.Function, FunctionProp.ReferenceData.ToString()); itemProps.Set(EnvironmentProp.Type, "BusinessCenterHolidays"); itemProps.Set(EnvironmentProp.Schema, "V5r3.Reporting"); itemProps.Set(EnvironmentProp.NameSpace, nameSpace); string identifier = $"ReferenceData.BusinessCenterHolidays.{locationCalendarYear.BusinessCenter}"; string itemName = nameSpace + "." + identifier; itemProps.Set(CurveProp.UniqueIdentifier, identifier); return(new ItemInfo { ItemName = itemName, ItemProps = itemProps }); }