/// <summary> /// Updates the specified rule with the given schedule. /// </summary> /// <param name="rule">The rule.</param> /// <param name="updatedWeeklySchedule">The updated schedule.</param> public static void Update(this ScheduledAccessRule rule, IWeeklySchedule updatedWeeklySchedule) { Contract.Requires(rule != null); Contract.Requires(updatedWeeklySchedule != null); var source = updatedWeeklySchedule.DailyTimeRange.ToArray().OrderBy(x => x.Key).GetEnumerator(); var dest = rule.Entries.ToArray().OrderBy(x => x.Day).GetEnumerator(); while (dest.MoveNext() && source.MoveNext()) { dest.Current.FromTime = source.Current.Value.FromTime; dest.Current.ToTime = source.Current.Value.ToTime; } while (dest.MoveNext()) { rule.RemoveEntry(dest.Current); } while (source.MoveNext()) { rule.AddEntry(CreateEntry(source.Current)); } rule.TimeZone = updatedWeeklySchedule.TimeZone; }
public void Visit(ScheduledAccessRule rule) { var schedule = new WeeklySchedule(rule.TimeZone); rule.Entries.ForEach(x => schedule.DailyTimeRange.Add(x.Day, new TimeRange(x.FromTime, x.ToTime))); var dto = AccessRule.Scheduled(rule.AccessPoint.AccessPointId, schedule); Scheduled.Add(dto); }