public DayTypeDto(DayTimeDto[] pDayTimePeriods, TimeOfDayPolicy pTODPolicy, bool pIsSelected, bool pIsPotentiallyUnknownDayPolicy) { IsSelected = pIsSelected; DayTimePeriods = pDayTimePeriods; TODPolicy = pTODPolicy; IsPotentiallyUnknownDayPolicy = pIsPotentiallyUnknownDayPolicy; }
bool validateTimePeriod(DayTimeDto pDayTimePeriod, TimeOfDayPolicy pTimeOfDayPolicy) { if (pDayTimePeriod.Start > pDayTimePeriod.Stop) { return(false); //throw new ArgumentException("Time Start cannot be grater then Time Stop. Start: [" + pDayTimePeriod.Start + "] ; Stop: [" + pDayTimePeriod.Stop + "]"); } if (pTimeOfDayPolicy == TimeOfDayPolicy.Flat) { if (pDayTimePeriod.TimeOfDay != TimeOfDay.BlockedFlat && pDayTimePeriod.TimeOfDay != TimeOfDay.Flat) { return(false); //throw new ArgumentException("Invalid DayTimePeriod.TimeOfDay: [" + pDayTimePeriod.TimeOfDay + "] for TimeOfDayPolicy: [" + pTimeOfDayPolicy + "]"); } } else if (pTimeOfDayPolicy == TimeOfDayPolicy.PeakOffPeak) { if (pDayTimePeriod.TimeOfDay != TimeOfDay.BlockedPeakOffPeak && pDayTimePeriod.TimeOfDay != TimeOfDay.Peak && pDayTimePeriod.TimeOfDay != TimeOfDay.OffPeak) { return(false); //throw new ArgumentException("Invalid DayTimePeriod.TimeOfDay: [" + pDayTimePeriod.TimeOfDay + "] for TimeOfDayPolicy: [" + pTimeOfDayPolicy + "]"); } } else if (pTimeOfDayPolicy == TimeOfDayPolicy.NightDayEve) { if (pDayTimePeriod.TimeOfDay != TimeOfDay.BlockedNightDayEve && pDayTimePeriod.TimeOfDay != TimeOfDay.Night && pDayTimePeriod.TimeOfDay != TimeOfDay.Day && pDayTimePeriod.TimeOfDay != TimeOfDay.Eve) { return(false); //throw new ArgumentException("Invalid DayTimePeriod.TimeOfDay: [" + pDayTimePeriod.TimeOfDay + "] for TimeOfDayPolicy: [" + pTimeOfDayPolicy + "]"); } } return(true); }
void setRates(TypeOfDayChoice pTypeOfDayChoice, TimeOfDayPolicy pTimeOfDayPolicy, DayTimeDto[] pDayTimePeriods, RateDto[] pRateList, bool pIsPotentiallyUnknownDayPolicy) { if (!validateTimePeriods(pDayTimePeriods, pTimeOfDayPolicy)) { throw new ArgumentException("Invalid TimePeriod(s) for TypeOfDayChoice: [" + pTypeOfDayChoice + "] TimeOfDayPolicy: [" + pTimeOfDayPolicy + "]"); } if (pTypeOfDayChoice == TypeOfDayChoice.RegularDay) { regularDay = new DayTypeDto(pDayTimePeriods, pTimeOfDayPolicy, true, pIsPotentiallyUnknownDayPolicy); regularDayRateEntry = new TypeOfDayRateEntryDto { TypeOfDayChoice = pTypeOfDayChoice, Rates = pRateList }; } if (pTypeOfDayChoice == TypeOfDayChoice.Weekend) { weekend = new DayTypeDto(pDayTimePeriods, pTimeOfDayPolicy, true, pIsPotentiallyUnknownDayPolicy); weekendRateEntry = new TypeOfDayRateEntryDto { TypeOfDayChoice = pTypeOfDayChoice, Rates = pRateList }; } if (pTypeOfDayChoice == TypeOfDayChoice.Holiday) { holiday = new DayTypeDto(pDayTimePeriods, pTimeOfDayPolicy, true, pIsPotentiallyUnknownDayPolicy); holidayRateEntry = new TypeOfDayRateEntryDto { TypeOfDayChoice = pTypeOfDayChoice, Rates = pRateList }; } }
bool validateTimePeriods(DayTimeDto[] pDayTimePeriods, TimeOfDayPolicy pTimeOfDayPolicy) { if (pDayTimePeriods == null || pDayTimePeriods.Length == 0) { return(false); //throw new ArgumentException("No Time periods provided"); } if (pDayTimePeriods.Length == 1 && (pDayTimePeriods[0].TimeOfDay == TimeOfDay.BlockedFlat || pDayTimePeriods[0].TimeOfDay == TimeOfDay.BlockedPeakOffPeak || pDayTimePeriods[0].TimeOfDay == TimeOfDay.BlockedNightDayEve)) { if (pDayTimePeriods[0].Start != 0 && pDayTimePeriods[0].Stop != 23) { return(false); //NOTE: if only one TimePeriod and if this TimePeriod is for Blocked* - it has to cover whole Day 0-23 hours } } var _sorted = new SortedList <int, DayTimeDto>(); foreach (DayTimeDto _dayTime in pDayTimePeriods) { if (!validateTimePeriod(_dayTime, pTimeOfDayPolicy)) { return(false); } if (_sorted.ContainsKey(_dayTime.Start)) { return(false); //throw new ArgumentException("Duplicates in Time Start. Start: [" + _dayTime.Start + "] ; Stop: [" + _dayTime.Stop + "]"); } _sorted.Add(_dayTime.Start, _dayTime); } int _lastStop = -1; foreach (DayTimeDto _dayTime in _sorted.Values) { if (_lastStop + 1 != _dayTime.Start) { return(false); //throw new ArgumentException("Gaps are not allowed in Time ranges. Start: [" + _dayTime.Start + "] ; Stop: [" + _dayTime.Stop + "]"); } _lastStop = _dayTime.Stop; } if (_lastStop != 23) { return(false); //throw new ArgumentException("Gaps are not allowed in Time ranges. Stop: [" + _lastStop + "]"); } return(true); }
TimeOfDay parseTimeOfDay(TimeOfDayPolicy pTimeOfDayPolicy, string pRouteLine) { string _timeOfDayString = pRouteLine.Split(AppConstants.ImportExport_FieldDelimiter)[RouteLineFields.TimeOfDay]; if (_timeOfDayString == "Blocked") { return((TimeOfDay)Enum.Parse(typeof(TimeOfDay), _timeOfDayString + pTimeOfDayPolicy)); } if (Enum.IsDefined(typeof(TimeOfDay), _timeOfDayString)) { return((TimeOfDay)Enum.Parse(typeof(TimeOfDay), _timeOfDayString)); } throw new ArgumentException("Invalid TimeOfDay in Route line: " + pRouteLine); }
bool parsePolicy(string[] pRouteLines, out TimeOfDayPolicy pTimeOfDayPolicy, out bool pIsPotentiallyUnknownDayPolicy) { pTimeOfDayPolicy = TimeOfDayPolicy.Flat; pIsPotentiallyUnknownDayPolicy = false; foreach (string _routeLine in pRouteLines) { string _timeOfDayString = _routeLine.Split(AppConstants.ImportExport_FieldDelimiter)[RouteLineFields.TimeOfDay]; if (_timeOfDayString == "Blocked") { if (pRouteLines.Length == 1) { pTimeOfDayPolicy = TimeOfDayPolicy.Flat; pIsPotentiallyUnknownDayPolicy = true; return(true); } continue; } var _timeOfDay = (TimeOfDay)Enum.Parse(typeof(TimeOfDay), _timeOfDayString); if (_timeOfDay == TimeOfDay.Flat) { pTimeOfDayPolicy = TimeOfDayPolicy.Flat; return(true); } if (_timeOfDay == TimeOfDay.Peak || _timeOfDay == TimeOfDay.OffPeak) { pTimeOfDayPolicy = TimeOfDayPolicy.PeakOffPeak; return(true); } if (_timeOfDay == TimeOfDay.Night || _timeOfDay == TimeOfDay.Day || _timeOfDay == TimeOfDay.Eve) { pTimeOfDayPolicy = TimeOfDayPolicy.NightDayEve; return(true); } badRouteLines.Add(_routeLine); //TODO: T.LogRbr(LogSeverity.Error, "RatingInfoDto.parsePolicy", string.Format("Cannot determine TimeOfDayPolicy and/or TypeOfDayChoice in Route line: {0}", _routeLine)); return(false); } badRouteLines.AddRange(pRouteLines); //TODO: T.LogRbr(LogSeverity.Error, "RatingInfoDto.parsePolicy", "Cannot determine" + " TimeOfDayPolicy and/or TypeOfDayChoice in any Route line. Lines Count: " + pRouteLines.Length); return(false); }