public void TestOverlappingEndEvent() { DateTime start = DateUtil.ParseDateToUtc("2007-07-30T13:00:00.000Z"); DateTimeRange window = new DateTimeRange(start.AddDays(-7), start.AddDays(7)); // Test overlapping events // - 13:30 - 14:00 in Exchange // - 13:00 - 14:00 in GCal // Should create an exchange event [13:00-14:00] AddEventExchange(start, start.AddMinutes(30)); AddEventGCal(start, start.AddHours(1)); EventFeed feed = createEventFeedFromEvents(_gcalEvents); FreeBusyCollection fb = createFreeBusyFromExistingEvents(_exchEvents); ExchangeUser user = createFauxUser("*****@*****.**", "*****@*****.**"); user.BusyTimes = fb; ExchangeGatewayMock gateway = new ExchangeGatewayMock(); this.SyncUser(user, feed, gateway, window); Assert.AreEqual(0, gateway.AppointmentsMock.Deleted.Count); Assert.AreEqual(1, gateway.AppointmentsMock.Written.Count); Assert.AreEqual(0, gateway.AppointmentsMock.Updated.Count); Assert.AreEqual(gateway.AppointmentsMock.Written[0].StartDate, start); Assert.AreEqual(gateway.AppointmentsMock.Written[0].EndDate, start.AddHours(1)); }
void dump(FreeBusyCollection fbc) { Console.WriteLine("Begin FreeBusyCollection"); foreach (KeyValuePair <DateTime, FreeBusyTimeBlock> pair in fbc) { DateTime dt = pair.Key; FreeBusyTimeBlock b = pair.Value; Console.WriteLine("{0}: {1} -> {2} [{3}]", dt, b.StartDate, b.EndDate, b.Appointments.Count); } Console.WriteLine("End FreeBusyCollection"); }
private FreeBusyCollection createFreeBusyFromEvents( List <DateTimeRange> syncEvents, List <DateTimeRange> exchEvents) { FreeBusyCollection result = new FreeBusyCollection(); foreach (DateTimeRange r in syncEvents) { AddFreeBusyBlock(result, r, true); } foreach (DateTimeRange r in exchEvents) { AddFreeBusyBlock(result, r, false); } return(result); }
/// <summary> /// Ctor for an Exchange user from an Active Directory ResultSet /// </summary> /// <param name="properties">Active Directory propertes</param> public ExchangeUser(ResultPropertyCollection properties) { this.accountName = GetFirstString(properties["sAMAccountName"]); this.mailnickname = GetFirstString(properties["mailnickname"]); this.proxyAddresses = GetPrimarySmtpAddress(properties); this.email = GetFirstString(properties["mail"]); this.commonName = GetFirstString(properties["CN"]); this.legacyExchangeDN = GetFirstString(properties["legacyExchangeDN"]); this.DN = GetFirstString(properties["distinguishedName"]); this.objectClasses = GetStringList(properties["objectclass"]); this.displayName = GetFirstString(properties["displayName"]); this.freeBusyCommonName = parseFreeBusyCommonName(legacyExchangeDN); this.busyTimesBlocks = new FreeBusyCollection(); AdjustAccountName(); Validate(); }
private void AddFreeBusyBlock( FreeBusyCollection result, DateTimeRange eventRange, bool existingEvent) { FreeBusyTimeBlock block = new FreeBusyTimeBlock(eventRange); Appointment appt = new Appointment(); appt.StartDate = eventRange.Start; appt.EndDate = eventRange.End; appt.BusyStatus = BusyStatus.Busy; if (existingEvent) { AssignOwnership(appt); } block.Appointments.Add(appt); result.Appointments.Add(appt); result[eventRange.Start] = block; }
public void TestMissingAppointmentDetail() { DateTime start = DateUtil.ParseDateToUtc("2007-07-30T13:00:00.000Z"); DateTimeRange window = new DateTimeRange(start.AddDays(-7), start.AddDays(7)); AddEventGCal(start, start.AddHours(1)); EventFeed feed = createEventFeedFromEvents(_gcalEvents); FreeBusyCollection fb = createFreeBusyFromExistingEvents(_exchEvents); ExchangeUser user = createFauxUser("*****@*****.**", "*****@*****.**"); user.BusyTimes = fb; user.HaveAppointmentDetail = false; ExchangeGatewayMock gateway = new ExchangeGatewayMock(); this.SyncUser(user, feed, gateway, window); Assert.AreEqual(0, gateway.AppointmentsMock.Deleted.Count); Assert.AreEqual(0, gateway.AppointmentsMock.Written.Count); Assert.AreEqual(0, gateway.AppointmentsMock.Updated.Count); }
private static void ConvertFreeBusyToBlocks( DateTimeRange window, List <DateTimeRange> ranges, FreeBusyCollection times, IntervalTree <FreeBusyTimeBlock> intervals) { foreach (DateTimeRange range in ranges) { /* If the free busy date is between the start and end dates request */ if (DateUtil.IsWithinRange(range.Start, window.Start, window.End) || DateUtil.IsWithinRange(range.End, window.Start, window.End)) { /* Add the a new FreeBusyTimeBlock to the collection, * Set the key to the start date of the block */ FreeBusyTimeBlock block = new FreeBusyTimeBlock(range); if (!times.ContainsKey(range.Start)) { times.Add(range.Start, block); intervals.Insert(range, block); } } } }
public void TestSyncUser() { DateTime start = _base; DateTimeRange window = new DateTimeRange(start, start.AddDays(30)); // Add Event to both AddEventBoth(start, start.AddHours(2)); // Add only to Google Calendar - i.e. Create in exchange start = start.AddDays(2).AddHours(3); AddEventGCal(start, start.AddHours(1)); // Add only to Exchange - i.e. Delete from exchange start = start.AddDays(3).AddHours(3); AddEventExchange(start, start.AddHours(1)); start = start.AddDays(1).AddHours(-5); AddEventExchange(start, start.AddMinutes(20)); // Add to Google Calendar start = start.AddDays(2).AddHours(3); AddEventGCal(start, start.AddHours(1)); // Add Event to both start = start.AddDays(2).AddHours(3); AddEventBoth(start, start.AddHours(2)); // Add only to Exchange start = start.AddDays(2).AddHours(3); AddEventExchange(start, start.AddHours(1)); // Add Event to both start = start.AddDays(2).AddHours(14); AddEventBoth(start, start.AddHours(1)); // Add to Google Calendar start = start.AddDays(2).AddHours(3); AddEventGCal(start, start.AddHours(1)); // Add Event to both start = start.AddDays(5).AddHours(12); AddEventBoth(start, start.AddHours(6)); EventFeed feed = createEventFeedFromEvents(_gcalEvents); FreeBusyCollection fb = createFreeBusyFromSyncEvents(_exchEvents); ExchangeUser user = createFauxUser("*****@*****.**", "*****@*****.**"); user.BusyTimes = fb; ExchangeGatewayMock gateway = new ExchangeGatewayMock(); this.SyncUser(user, feed, gateway, window); Assert.AreEqual(_deleteEvents.Count, gateway.AppointmentsMock.Deleted.Count); Assert.AreEqual(_createEvents.Count, gateway.AppointmentsMock.Written.Count); Assert.AreEqual(0, gateway.AppointmentsMock.Updated.Count); int idx = 0; foreach (DateTimeRange e in _deleteEvents) { Assert.AreEqual(e.Start, gateway.AppointmentsMock.Deleted[idx].StartDate); Assert.AreEqual(e.End, gateway.AppointmentsMock.Deleted[idx].EndDate); idx++; } idx = 0; foreach (DateTimeRange e in _createEvents) { Assert.AreEqual(e.Start, gateway.AppointmentsMock.Written[idx].StartDate); Assert.AreEqual(e.End, gateway.AppointmentsMock.Written[idx].EndDate); idx++; } }
/// <summary> /// Combines the free busy and appointment blocks supplied to the exchange user object /// If no appointments are supplied the user will still have free busy time blocks assigned /// to them, with a null appointment assigned to the free busy time. /// </summary> /// <param name="exchangeUser">Exchange users to apply freeBusy and appointments</param> /// <param name="freeBusy">The collection of FreeBusy blocks to assign to exchangeUser</param> /// <param name="appointments">The collection of appointment blocks to assign to exchangeUser</param> /// <param name="window">Window to merge for</param> protected void MergeFreeBusyWithAppointments( ExchangeUser exchangeUser, FreeBusy freeBusy, List <Appointment> appointments, DateTimeRange window) { using (BlockTimer bt = new BlockTimer("MergeFreeBusyWithAppointments")) { IntervalTree <FreeBusyTimeBlock> busyIntervals = new IntervalTree <FreeBusyTimeBlock>(); FreeBusyCollection busyTimes = new FreeBusyCollection(); int appointmentsCount = 0; List <DateTimeRange> combinedTimes = FreeBusyConverter.MergeFreeBusyLists(freeBusy.All, freeBusy.Tentative); /* Add the date ranges from each collection in the FreeBusy object */ ConvertFreeBusyToBlocks(window, combinedTimes, busyTimes, busyIntervals); if (appointments != null && appointments.Count > 0) { appointmentsCount = appointments.Count; foreach (Appointment appt in appointments) { log.DebugFormat("Appt \"{0}\" {1} {2} response = {3} status = {4} busy = {5}", appt.Subject, appt.Range, appt.StartDate.Kind, appt.ResponseStatus, appt.MeetingStatus, appt.BusyStatus); if (appt.BusyStatus == BusyStatus.Free) { continue; } DateTimeRange range = new DateTimeRange(appt.StartDate, appt.EndDate); List <FreeBusyTimeBlock> result = busyIntervals.FindAll(range, IntervalTreeMatch.Overlap); log.DebugFormat("Found {0} ranges overlap {1}", result.Count, range); foreach (FreeBusyTimeBlock block in result) { log.DebugFormat("Adding \"{0}\" to FB {1} {2}", appt.Subject, block.Range, block.StartDate.Kind); block.Appointments.Add(appt); } busyTimes.Appointments.Add(appt); } } foreach (FreeBusyTimeBlock block in busyTimes.Values) { block.Appointments.Sort(CompareAppointmentsByRanges); } log.InfoFormat("Merge Result of {0} + Appointment {1} -> {2}", combinedTimes.Count, appointmentsCount, busyTimes.Count); /* Assign the data structure to the exchange user */ exchangeUser.BusyTimes = busyTimes; } }