public static FreeBusy CreateRequest(IDateTime fromInclusive, IDateTime toExclusive, Organizer organizer, IEnumerable <Attendee> contacts) { var fb = new FreeBusy { DtStamp = CalDateTime.Now, DtStart = fromInclusive, DtEnd = toExclusive }; if (organizer != null) { fb.Organizer = organizer; } if (contacts == null) { return(fb); } foreach (var attendee in contacts) { fb.Attendees.Add(attendee); } return(fb); }
public static FreeBusy Create(ICalendarObject obj, FreeBusy freeBusyRequest) { if (!(obj is IGetOccurrencesTyped)) { return(null); } var getOccurrences = (IGetOccurrencesTyped)obj; var occurrences = getOccurrences.GetOccurrences <CalendarEvent>(freeBusyRequest.Start, freeBusyRequest.End); var contacts = new List <string>(); var isFilteredByAttendees = false; if (freeBusyRequest.Attendees != null && freeBusyRequest.Attendees.Count > 0) { isFilteredByAttendees = true; var attendees = freeBusyRequest.Attendees .Where(a => a.Value != null) .Select(a => a.Value.OriginalString.Trim()); contacts.AddRange(attendees); } var fb = freeBusyRequest; fb.Uid = Guid.NewGuid().ToString(); fb.Entries.Clear(); fb.DtStamp = CalDateTime.Now; foreach (var o in occurrences) { var uc = o.Source as IUniqueComponent; if (uc == null) { continue; } var evt = uc as CalendarEvent; var accepted = false; var type = FreeBusyStatus.Busy; // We only accept events, and only "opaque" events. if (evt != null && evt.Transparency != TransparencyType.Transparent) { accepted = true; } // If the result is filtered by attendees, then // we won't accept it until we find an event // that is being attended by this person. if (accepted && isFilteredByAttendees) { accepted = false; var participatingAttendeeQuery = uc.Attendees .Where(attendee => attendee.Value != null && contacts.Contains(attendee.Value.OriginalString.Trim()) && attendee.ParticipationStatus != null) .Select(pa => pa.ParticipationStatus.ToUpperInvariant()); foreach (var participatingAttendee in participatingAttendeeQuery) { switch (participatingAttendee) { case EventParticipationStatus.Tentative: accepted = true; type = FreeBusyStatus.BusyTentative; break; case EventParticipationStatus.Accepted: accepted = true; type = FreeBusyStatus.Busy; break; } } } if (accepted) { // If the entry was accepted, add it to our list! fb.Entries.Add(new FreeBusyEntry(o.Period, type)); } } return(fb); }