Example #1
0
        public static HashSet <Occurrence> GetOccurrences(IRecurrable recurrable, IDateTime periodStart, IDateTime periodEnd, bool includeReferenceDateInResults)
        {
            var evaluator = recurrable.GetService(typeof(IEvaluator)) as IEvaluator;

            if (evaluator == null || recurrable.Start == null)
            {
                return(new HashSet <Occurrence>());
            }

            // Ensure the start time is associated with the object being queried
            var start = recurrable.Start;

            start.AssociatedObject = recurrable as ICalendarObject;

            // Change the time zone of periodStart/periodEnd as needed
            // so they can be used during the evaluation process.

            periodStart.TzId = start.TzId;
            periodEnd.TzId   = start.TzId;

            var periods = evaluator.Evaluate(start, DateUtil.GetSimpleDateTimeData(periodStart), DateUtil.GetSimpleDateTimeData(periodEnd),
                                             includeReferenceDateInResults);

            var otherOccurrences = from p in periods
                                   let endTime = p.EndTime ?? p.StartTime
                                                 where endTime.GreaterThan(periodStart) && p.StartTime.LessThanOrEqual(periodEnd)
                                                 select new Occurrence(recurrable, p);

            var occurrences = new HashSet <Occurrence>(otherOccurrences);

            return(occurrences);
        }
Example #2
0
        static public IList <Occurrence> GetOccurrences(IRecurrable recurrable, IDateTime periodStart, IDateTime periodEnd, bool includeReferenceDateInResults)
        {
            List <Occurrence> occurrences = new List <Occurrence>();

            IEvaluator evaluator = recurrable.GetService(typeof(IEvaluator)) as IEvaluator;

            if (evaluator != null)
            {
                // Change the time zone of periodStart/periodEnd as needed
                // so they can be used during the evaluation process.
                periodStart = DateUtil.MatchTimeZone(recurrable.Start, periodStart);
                periodEnd   = DateUtil.MatchTimeZone(recurrable.Start, periodEnd);

                IList <IPeriod> periods = evaluator.Evaluate(
                    recurrable.Start,
                    DateUtil.GetSimpleDateTimeData(periodStart),
                    DateUtil.GetSimpleDateTimeData(periodEnd),
                    includeReferenceDateInResults);

                foreach (IPeriod p in periods)
                {
                    // Filter the resulting periods to only contain those between
                    // startTime and endTime.
                    if (p.StartTime.GreaterThanOrEqual(periodStart) &&
                        p.StartTime.LessThanOrEqual(periodEnd))
                    {
                        occurrences.Add(new Occurrence(recurrable, p));
                    }
                }

                occurrences.Sort();
            }
            return(occurrences);
        }
Example #3
0
        /// <summary>
        ///     Gets the occurrences.
        /// </summary>
        /// <param name="recurrable">The recurrable.</param>
        /// <param name="periodStart">The period start.</param>
        /// <param name="periodEnd">The period end.</param>
        /// <param name="includeReferenceDateInResults">
        ///     if set to <c>true</c> [include reference date in results].
        /// </param>
        /// <returns></returns>
        public static IList <Occurrence> GetOccurrences(IRecurrable recurrable, IDateTime periodStart, IDateTime periodEnd, bool includeReferenceDateInResults)
        {
            var occurrences = new List <Occurrence>( );

            var evaluator = recurrable.GetService(typeof(IEvaluator)) as IEvaluator;

            if (evaluator != null)
            {
                // Ensure the start time is associated with the object being queried
                var start = recurrable.Start.Copy <IDateTime>( );
                start.AssociatedObject = recurrable as ICalendarObject;

                // Change the time zone of periodStart/periodEnd as needed
                // so they can be used during the evaluation process.
                periodStart = DateUtil.MatchTimeZone(start, periodStart);
                periodEnd   = DateUtil.MatchTimeZone(start, periodEnd);

                ISet <IPeriod> periods = evaluator.Evaluate(
                    start,
                    DateUtil.GetSimpleDateTimeData(periodStart),
                    DateUtil.GetSimpleDateTimeData(periodEnd),
                    includeReferenceDateInResults);

                // Filter the resulting periods to only contain those
                // that occur sometime between startTime and endTime.
                // NOTE: fixes bug #3007244 - GetOccurences not returning long spanning all-day events
                occurrences.AddRange(from p in periods
                                     let endTime = p.EndTime ?? p.StartTime
                                                   where endTime.GreaterThan(periodStart) && p.StartTime.LessThanOrEqual(periodEnd)
                                                   select new Occurrence(recurrable, p));

                occurrences.Sort( );
            }
            return(occurrences);
        }
Example #4
0
        static public IList<Occurrence> GetOccurrences(IRecurrable recurrable, IDateTime periodStart, IDateTime periodEnd, bool includeReferenceDateInResults)
        {
            List<Occurrence> occurrences = new List<Occurrence>();

            IEvaluator evaluator = recurrable.GetService(typeof(IEvaluator)) as IEvaluator;
            if (evaluator != null)
            {
                // Change the time zone of periodStart/periodEnd as needed 
                // so they can be used during the evaluation process.
                periodStart = DateUtil.MatchTimeZone(recurrable.Start, periodStart);
                periodEnd = DateUtil.MatchTimeZone(recurrable.Start, periodEnd);

                IList<IPeriod> periods = evaluator.Evaluate(
                    recurrable.Start,
                    DateUtil.GetSimpleDateTimeData(periodStart),
                    DateUtil.GetSimpleDateTimeData(periodEnd),
                    includeReferenceDateInResults);

                foreach (IPeriod p in periods)
                {
                    // Filter the resulting periods to only contain those 
                    // that occur sometime between startTime and endTime.
                    // NOTE: fixes bug #3007244 - GetOccurences not returning long spanning all-day events 
                    IDateTime endTime = p.EndTime ?? p.StartTime;
                    if (endTime.GreaterThan(periodStart) && p.StartTime.LessThanOrEqual(periodEnd))
                        occurrences.Add(new Occurrence(recurrable, p));
                }

                occurrences.Sort();
            }
            return occurrences;
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="RecurringEvaluator" /> class.
        /// </summary>
        /// <param name="obj">The obj.</param>
        public RecurringEvaluator(IRecurrable obj)
        {
            Recurrable = obj;

            // We're not sure if the object is a calendar object
            // or a calendar data type, so we need to assign
            // the associated object manually
            var calendarObject = obj as ICalendarObject;

            if (calendarObject != null)
            {
// ReSharper disable DoNotCallOverridableMethodsInConstructor
                AssociatedObject = calendarObject;
// ReSharper restore DoNotCallOverridableMethodsInConstructor
            }

// ReSharper disable SuspiciousTypeConversion.Global
            var calendarDataType = obj as ICalendarDataType;

// ReSharper restore SuspiciousTypeConversion.Global

            if (calendarDataType != null)
            {
                ICalendarDataType dt = calendarDataType;
// ReSharper disable DoNotCallOverridableMethodsInConstructor
                AssociatedObject = dt.AssociatedObject;
// ReSharper restore DoNotCallOverridableMethodsInConstructor
            }
        }
Example #6
0
 static public IList<Occurrence> GetOccurrences(IRecurrable recurrable, IDateTime dt, bool includeReferenceDateInResults)
 {
     return GetOccurrences(
         recurrable, 
         new iCalDateTime(dt.Local.Date), 
         new iCalDateTime(dt.Local.Date.AddDays(1).AddSeconds(-1)),
         includeReferenceDateInResults);
 }
Example #7
0
 static public IList <Occurrence> GetOccurrences(IRecurrable recurrable, IDateTime dt, bool includeReferenceDateInResults)
 {
     return(GetOccurrences(
                recurrable,
                new iCalDateTime(dt.Local.Date),
                new iCalDateTime(dt.Local.Date.AddDays(1).AddSeconds(-1)),
                includeReferenceDateInResults));
 }
Example #8
0
        static public void ClearEvaluation(IRecurrable recurrable)
        {
            IEvaluator evaluator = recurrable.GetService(typeof(IEvaluator)) as IEvaluator;

            if (evaluator != null)
            {
                evaluator.Clear();
            }
        }
        public RecurringEvaluator(IRecurrable obj)
        {
            Recurrable = obj;

            // We're not sure if the object is a calendar object
            // or a calendar data type, so we need to assign
            // the associated object manually
            if (obj is ICalendarObject)
                AssociatedObject = (ICalendarObject)obj;
            if (obj is ICalendarDataType)
            {
                ICalendarDataType dt = (ICalendarDataType)obj;
                AssociatedObject = dt.AssociatedObject;
            }
        }
Example #10
0
        public RecurringEvaluator(IRecurrable obj)
        {
            Recurrable = obj;

            // We're not sure if the object is a calendar object
            // or a calendar data type, so we need to assign
            // the associated object manually
            if (obj is ICalendarObject)
            {
                AssociatedObject = (ICalendarObject)obj;
            }
            if (obj is ICalendarDataType)
            {
                var dt = (ICalendarDataType)obj;
                AssociatedObject = dt.AssociatedObject;
            }
        }
Example #11
0
        public static void ClearEvaluation(IRecurrable recurrable)
        {
            var evaluator = recurrable.GetService(typeof(IEvaluator)) as IEvaluator;

            evaluator?.Clear();
        }
Example #12
0
 public Occurrence(IRecurrable recurrable, Period period)
 {
     Source = recurrable;
     Period = period;
 }
Example #13
0
 public Occurrence(Occurrence ao)
 {
     Period = ao.Period;
     Source = ao.Source;
 }
Example #14
0
 public TimeZoneInfoEvaluator(IRecurrable tzi) : base(tzi)
 {
 }
Example #15
0
 public Occurrence(IRecurrable recurrable, IPeriod period)
 {
     m_Source = recurrable;
     m_Period = period;
 }
Example #16
0
 public Occurrence(Occurrence ao)
 {
     m_Period = ao.Period;
     m_Source = ao.Source;
 }
Example #17
0
 public static HashSet <Occurrence> GetOccurrences(IRecurrable recurrable, IDateTime dt, bool includeReferenceDateInResults) => GetOccurrences(recurrable,
                                                                                                                                               new CalDateTime(dt.AsSystemLocal.Date), new CalDateTime(dt.AsSystemLocal.Date.AddDays(1).AddSeconds(-1)), includeReferenceDateInResults);
Example #18
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="Occurrence" /> structure.
 /// </summary>
 /// <param name="recurrable">The recurrable.</param>
 /// <param name="period">The period.</param>
 public Occurrence(IRecurrable recurrable, IPeriod period)
 {
     _source = recurrable;
     _period = period;
 }
Example #19
0
        private static DayOfWeek DayOfWeekFromEvent(IRecurrable ev)
        {
            var rule = ev.RecurrenceRules.SingleOrDefault(r => r.Frequency == FrequencyType.Weekly);

            return(rule?.ByDay[0].DayOfWeek ?? ev.Start.DayOfWeek);
        }
Example #20
0
 static public void ClearEvaluation(IRecurrable recurrable)
 {
     IEvaluator evaluator = recurrable.GetService(typeof(IEvaluator)) as IEvaluator;
     if (evaluator != null)
         evaluator.Clear();
 }
Example #21
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="Occurrence" /> structure.
 /// </summary>
 /// <param name="ao">The occurrence.</param>
 public Occurrence(Occurrence ao)
 {
     _period = ao.Period;
     _source = ao.Source;
 }