Exemple #1
0
 IFreeBusy CombineFreeBusy(IFreeBusy main, IFreeBusy current)
 {
     if (main != null)
     {
         main.MergeWith(current);
     }
     return(current);
 }
Exemple #2
0
        public IFreeBusy GetFreeBusy(IOrganizer organizer, IAttendee[] contacts, IDateTime fromInclusive, IDateTime toExclusive)
        {
            IFreeBusy fb = null;

            foreach (var iCal in this)
            {
                fb = CombineFreeBusy(fb, iCal.GetFreeBusy(organizer, contacts, fromInclusive, toExclusive));
            }
            return(fb);
        }
Exemple #3
0
        public IFreeBusy GetFreeBusy(IDateTime fromInclusive, IDateTime toExclusive)
        {
            IFreeBusy fb = null;

            foreach (var iCal in this)
            {
                fb = CombineFreeBusy(fb, iCal.GetFreeBusy(fromInclusive, toExclusive));
            }
            return(fb);
        }
Exemple #4
0
        public IFreeBusy GetFreeBusy(IFreeBusy freeBusyRequest)
        {
            IFreeBusy fb = null;

            foreach (var iCal in this)
            {
                fb = CombineFreeBusy(fb, iCal.GetFreeBusy(freeBusyRequest));
            }
            return(fb);
        }
Exemple #5
0
        virtual public void MergeWith(IMergeable obj)
        {
            IFreeBusy fb = obj as IFreeBusy;

            if (fb != null)
            {
                foreach (IFreeBusyEntry entry in fb.Entries)
                {
                    if (!Entries.Contains(entry))
                    {
                        Entries.Add(entry.Copy <IFreeBusyEntry>());
                    }
                }
            }
        }
Exemple #6
0
        public void GetFreeBusyStatus1()
        {
            IICalendar iCal = new iCalendar();

            IEvent evt = iCal.Create <Event>();

            evt.Summary = "Test event";
            evt.Start   = new iCalDateTime(2010, 10, 1, 8, 0, 0);
            evt.End     = new iCalDateTime(2010, 10, 1, 9, 0, 0);

            IFreeBusy freeBusy = iCal.GetFreeBusy(new iCalDateTime(2010, 10, 1, 0, 0, 0), new iCalDateTime(2010, 10, 7, 11, 59, 59));

            Assert.AreEqual(FreeBusyStatus.Free, freeBusy.GetFreeBusyStatus(new iCalDateTime(2010, 10, 1, 7, 59, 59)));
            Assert.AreEqual(FreeBusyStatus.Busy, freeBusy.GetFreeBusyStatus(new iCalDateTime(2010, 10, 1, 8, 0, 0)));
            Assert.AreEqual(FreeBusyStatus.Busy, freeBusy.GetFreeBusyStatus(new iCalDateTime(2010, 10, 1, 8, 59, 59)));
            Assert.AreEqual(FreeBusyStatus.Free, freeBusy.GetFreeBusyStatus(new iCalDateTime(2010, 10, 1, 9, 0, 0)));
        }
Exemple #7
0
 public virtual IFreeBusy GetFreeBusy(IFreeBusy freeBusyRequest)
 {
     return(Net.FreeBusy.Create(this, freeBusyRequest));
 }
Exemple #8
0
 virtual public IFreeBusy GetFreeBusy(IFreeBusy freeBusyRequest)
 {
     return(DDay.iCal.FreeBusy.Create(this, freeBusyRequest));
 }
Exemple #9
0
        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;
        }
Exemple #10
0
 /// <summary>
 ///     Gets the free busy.
 /// </summary>
 /// <param name="freeBusyRequest">The free busy request.</param>
 /// <returns></returns>
 public virtual IFreeBusy GetFreeBusy(IFreeBusy freeBusyRequest)
 {
     return(Scheduling.iCalendar.FreeBusy.Create(this, freeBusyRequest));
 }
Exemple #11
0
        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);
        }
 /// <summary>
 ///     Gets the free busy.
 /// </summary>
 /// <param name="freeBusyRequest">The free busy request.</param>
 /// <returns></returns>
 public IFreeBusy GetFreeBusy(IFreeBusy freeBusyRequest)
 {
     return(this.Aggregate <IICalendar, IFreeBusy>(null, (current, iCal) => CombineFreeBusy(current, iCal.GetFreeBusy(freeBusyRequest))));
 }
Exemple #13
0
        /// <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);
        }
 private IFreeBusy CombineFreeBusy(IFreeBusy main, IFreeBusy current)
 {
     main?.MergeWith(current);
     return(current);
 }