public static IFreeBusy Create(ICalendarObject obj, IFreeBusy freeBusyRequest) { if (obj is IGetOccurrencesTyped) { var getOccurrences = (IGetOccurrencesTyped)obj; var occurrences = getOccurrences.GetOccurrences <IEvent>(freeBusyRequest.Start, freeBusyRequest.End); var contacts = new List <string>(128); 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.Copy <IFreeBusy>(); fb.Uid = new UidFactory().Build(); fb.Entries.Clear(); fb.DtStamp = CalDateTime.Now; foreach (var o in occurrences) { var uc = o.Source as IUniqueComponent; if (uc != null) { var evt = uc as IEvent; 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 ParticipationStatus.Tentative: accepted = true; type = FreeBusyStatus.BusyTentative; break; case ParticipationStatus.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); } return(null); }
static public IFreeBusy Create(ICalendarObject obj, IFreeBusy freeBusyRequest) { if (obj is IGetOccurrencesTyped) { IGetOccurrencesTyped getOccurrences = (IGetOccurrencesTyped)obj; IList<Occurrence> occurrences = getOccurrences.GetOccurrences<IEvent>(freeBusyRequest.Start, freeBusyRequest.End); List<string> contacts = new List<string>(); bool isFilteredByAttendees = false; if (freeBusyRequest.Attendees != null && freeBusyRequest.Attendees.Count > 0) { isFilteredByAttendees = true; foreach (IAttendee attendee in freeBusyRequest.Attendees) { if (attendee.Value != null) contacts.Add(attendee.Value.OriginalString.Trim()); } } IFreeBusy fb = freeBusyRequest.Copy<IFreeBusy>(); fb.UID = new UIDFactory().Build(); fb.Entries.Clear(); fb.DTStamp = iCalDateTime.Now; foreach (Occurrence o in occurrences) { IUniqueComponent uc = o.Source as IUniqueComponent; if (uc != null) { IEvent evt = uc as IEvent; bool accepted = false; FreeBusyStatus 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; foreach (IAttendee a in uc.Attendees) { if (a.Value != null && contacts.Contains(a.Value.OriginalString.Trim())) { if (a.ParticipationStatus != null) { switch(a.ParticipationStatus.ToUpperInvariant()) { case ParticipationStatus.Tentative: accepted = true; type = FreeBusyStatus.BusyTentative; break; case ParticipationStatus.Accepted: accepted = true; type = FreeBusyStatus.Busy; break; default: break; } } } } } if (accepted) { // If the entry was accepted, add it to our list! fb.Entries.Add(new FreeBusyEntry(o.Period, type)); } } } return fb; } return null; }
/// <summary> /// Creates the specified obj. /// </summary> /// <param name="obj">The obj.</param> /// <param name="freeBusyRequest">The free busy request.</param> /// <returns></returns> public static IFreeBusy Create(ICalendarObject obj, IFreeBusy freeBusyRequest) { var occurrencesTyped = obj as IGetOccurrencesTyped; if (occurrencesTyped != null) { IGetOccurrencesTyped getOccurrences = occurrencesTyped; IList <Occurrence> occurrences = getOccurrences.GetOccurrences <IEvent>(freeBusyRequest.Start, freeBusyRequest.End); var contacts = new List <string>( ); bool isFilteredByAttendees = false; if (freeBusyRequest.Attendees != null && freeBusyRequest.Attendees.Count > 0) { isFilteredByAttendees = true; contacts.AddRange(from attendee in freeBusyRequest.Attendees where attendee.Value != null select attendee.Value.OriginalString.Trim( )); } var fb = freeBusyRequest.Copy <IFreeBusy>( ); fb.Uid = new UidFactory( ).Build( ); fb.Entries.Clear( ); fb.DtStamp = iCalDateTime.Now; foreach (Occurrence o in occurrences) { var uc = o.Source as IUniqueComponent; if (uc != null) { var evt = uc as IEvent; bool 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; foreach (IAttendee a in uc.Attendees) { if (a.Value != null && contacts.Contains(a.Value.OriginalString.Trim( ))) { if (a.ParticipationStatus != ParticipationStatus.NotSpecified) { switch (a.ParticipationStatus) { case ParticipationStatus.Tentative: accepted = true; type = FreeBusyStatus.BusyTentative; break; case ParticipationStatus.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); } return(null); }