예제 #1
0
        /// <summary>
        /// Evaluates this event to determine the dates and times for which the event occurs.
        /// This method only evaluates events which occur between <paramref name="FromDate"/>
        /// and <paramref name="ToDate"/>; therefore, if you require a list of events which
        /// occur outside of this range, you must specify a <paramref name="FromDate"/> and
        /// <paramref name="ToDate"/> which encapsulate the date(s) of interest.
        /// <note type="caution">
        ///     For events with very complex recurrence rules, this method may be a bottleneck
        ///     during processing time, especially when this method in called for a large number
        ///     of events, in sequence, or for a very large time span.
        /// </note>
        /// </summary>
        /// <param name="FromDate">The beginning date of the range to evaluate.</param>
        /// <param name="ToDate">The end date of the range to evaluate.</param>
        /// <returns></returns>                
        internal override List<Period> Evaluate(iCalDateTime FromDate, iCalDateTime ToDate)
        {
            // Add the event itself, before recurrence rules are evaluated
            // NOTE: this fixes a bug where (if evaluated multiple times)
            // a period can be added to the Periods collection multiple times.
            Period period = new Period(DTStart, Duration);
            // Ensure the period does not already exist in our collection
            if (!Periods.Contains(period))
                Periods.Add(period);
            
            // Evaluate recurrences normally
            base.Evaluate(FromDate, ToDate);

            // Ensure each period has a duration
            foreach(Period p in Periods)
            {
                if (p.EndTime == null)
                {
                    p.Duration = Duration;
                    if (p.Duration != null)
                        p.EndTime = p.StartTime + Duration;
                    else p.EndTime = p.StartTime;
                }
                // Ensure the Kind of time is consistent with DTStart
                p.EndTime.IsUniversalTime = DTStart.IsUniversalTime;
            }

            return Periods;
        }
예제 #2
0
        public override IEnumerable <IPeriod> Evaluate(IDateTime referenceDate, DateTime periodStart, DateTime periodEnd, bool includeReferenceDateInResults)
        {
            // Create a recurrence pattern suitable for use during evaluation.
            IRecurrencePattern pattern = ProcessRecurrencePattern(referenceDate);

            // Enforce evaluation restrictions on the pattern.
            EnforceEvaluationRestrictions(pattern);

            var periods = new HashSet <IPeriod>();

            foreach (DateTime dt in GetDates(referenceDate, periodStart, periodEnd, -1, pattern, includeReferenceDateInResults))
            {
                // Create a period from the date/time.
                IPeriod p = CreatePeriod(dt, referenceDate);

                if (!periods.Contains(p))
                {
                    periods.Add(p);
                }
            }


            Periods.Clear();

            foreach (var period in periods)
            {
                if (!Periods.Contains(period))
                {
                    Periods.Add(period);
                }
            }

            return(Periods);
        }
예제 #3
0
        /// <summary>
        /// Evalates the RDate component, and adds each specified DateTime or
        /// Period to the <see cref="Periods"/> collection.
        /// </summary>
        /// <param name="FromDate">The beginning date of the range to evaluate.</param>
        /// <param name="ToDate">The end date of the range to evaluate.</param>
        virtual protected void EvaluateRDate(Date_Time FromDate, Date_Time ToDate)
        {
            // Handle RDATEs
            if (RDate != null)
            {
                foreach (RDate rdate in RDate)
                {
                    ArrayList Items = rdate.Evaluate(DTStart, FromDate, ToDate);
                    foreach (object obj in Items)
                    {
                        Period p = null;
                        if (obj is Period)
                        {
                            p = (Period)obj;
                        }
                        else if (obj is Date_Time)
                        {
                            p = new Period((Date_Time)obj);
                        }

                        if (p != null && !Periods.Contains(p))
                        {
                            Periods.Add(p);
                        }
                    }
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Evalates the ExDate component, and excludes each specified DateTime or
        /// Period from the <see cref="Periods"/> collection.
        /// </summary>
        /// <param name="periodStart">The beginning date of the range to evaluate.</param>
        /// <param name="periodEnd">The end date of the range to evaluate.</param>
        virtual protected void EvaluateExDate(IDateTime referenceDate, DateTime periodStart, DateTime periodEnd)
        {
            // Handle EXDATEs
            if (Recurrable.ExceptionDates != null)
            {
                foreach (IPeriodList exdate in Recurrable.ExceptionDates)
                {
                    IEvaluator evaluator = exdate.GetService(typeof(IEvaluator)) as IEvaluator;
                    if (evaluator != null)
                    {
                        IList <IPeriod> periods = evaluator.Evaluate(referenceDate, periodStart, periodEnd, false);
                        foreach (IPeriod p in periods)
                        {
                            // If no time was provided for the ExDate, then it excludes the entire day
                            if (!p.StartTime.HasTime || (p.EndTime != null && !p.EndTime.HasTime))
                            {
                                p.MatchesDateOnly = true;
                            }

                            while (Periods.Contains(p))
                            {
                                Periods.Remove(p);
                            }
                        }
                    }
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Evaluates this event to determine the dates and times for which the event occurs.
        /// This method only evaluates events which occur between <paramref name="FromDate"/>
        /// and <paramref name="ToDate"/>; therefore, if you require a list of events which
        /// occur outside of this range, you must specify a <paramref name="FromDate"/> and
        /// <paramref name="ToDate"/> which encapsulate the date(s) of interest.
        /// <note type="caution">
        ///     For events with very complex recurrence rules, this method may be a bottleneck
        ///     during processing time, especially when this method in called for a large number
        ///     of events, in sequence, or for a very large time span.
        /// </summary>
        /// <param name="FromDate">The beginning date of the range to evaluate.</param>
        /// <param name="ToDate">The end date of the range to evaluate.</param>
        /// <returns></returns>
        public override List <Period> Evaluate(Date_Time FromDate, Date_Time ToDate)
        {
            // Add the event itself, before recurrence rules are evaluated
            // NOTE: this fixes a bug where (if evaluated multiple times)
            // a period can be added to the Periods collection multiple times.
            Period period = new Period(DTStart, Duration);

            if (!Periods.Contains(period))
            {
                Periods.Add(period);
            }

            // Evaluate recurrences normally
            base.Evaluate(FromDate, ToDate);

            // Ensure each period has a duration
            foreach (Period p in Periods)
            {
                if (p.EndTime == null)
                {
                    p.Duration = Duration;
                    p.EndTime  = p.StartTime + Duration;
                }
            }

            return(Periods);
        }
예제 #6
0
 /// <summary>
 /// Evaulates the RRule component, and adds each specified Period
 /// to the <see cref="Periods"/> collection.
 /// </summary>
 /// <param name="periodStart">The beginning date of the range to evaluate.</param>
 /// <param name="periodEnd">The end date of the range to evaluate.</param>
 virtual protected void EvaluateRRule(IDateTime referenceDate, DateTime periodStart, DateTime periodEnd, bool includeReferenceDateInResults)
 {
     // Handle RRULEs
     if (Recurrable.RecurrenceRules != null &&
         Recurrable.RecurrenceRules.Count > 0)
     {
         foreach (IRecurrencePattern rrule in Recurrable.RecurrenceRules)
         {
             IEvaluator evaluator = rrule.GetService(typeof(IEvaluator)) as IEvaluator;
             if (evaluator != null)
             {
                 IList <IPeriod> periods = evaluator.Evaluate(referenceDate, periodStart, periodEnd, includeReferenceDateInResults);
                 foreach (IPeriod p in periods)
                 {
                     if (!Periods.Contains(p))
                     {
                         Periods.Add(p);
                     }
                 }
             }
         }
     }
     else if (includeReferenceDateInResults)
     {
         // If no RRULEs were found, then we still need to add
         // the initial reference date to the results.
         IPeriod p = new Period(referenceDate.Copy <IDateTime>());
         if (!Periods.Contains(p))
         {
             Periods.Add(p);
         }
     }
 }
예제 #7
0
        /// <summary>
        /// Evaluates this event to determine the dates and times for which the event occurs.
        /// This method only evaluates events which occur between <paramref name="FromDate"/>
        /// and <paramref name="ToDate"/>; therefore, if you require a list of events which
        /// occur outside of this range, you must specify a <paramref name="FromDate"/> and
        /// <paramref name="ToDate"/> which encapsulate the date(s) of interest.
        /// <note type="caution">
        ///     For events with very complex recurrence rules, this method may be a bottleneck
        ///     during processing time, especially when this method in called for a large number
        ///     of events, in sequence, or for a very large time span.
        /// </summary>
        /// <param name="FromDate">The beginning date of the range to evaluate.</param>
        /// <param name="ToDate">The end date of the range to evaluate.</param>
        /// <returns></returns>
        public override List <Period> Evaluate(Date_Time FromDate, Date_Time ToDate)
        {
            // Add the event itself, before recurrence rules are evaluated
            // NOTE: this fixes a bug where (if evaluated multiple times)
            // a period can be added to the Periods collection multiple times.
            Period period = new Period(DTStart, Duration);

            // Ensure the period does not already exist in our collection
            if (!Periods.Contains(period))
            {
                Periods.Add(period);
            }

            // Evaluate recurrences normally
            base.Evaluate(FromDate, ToDate);

            // Ensure each period has a duration
            foreach (Period p in Periods)
            {
                if (p.EndTime == null)
                {
                    p.Duration = Duration;
                    p.EndTime  = p.StartTime + Duration;
                }
                // Ensure the Kind of time is consistent with DTStart
                else if (p.EndTime.Kind != DTStart.Kind)
                {
                    p.EndTime.Value = DateTime.SpecifyKind(p.EndTime.Value, DTStart.Kind);;
                }
            }

            return(Periods);
        }
예제 #8
0
        /// <summary>
        /// Evaluates this event to determine the dates and times for which the event occurs.
        /// This method only evaluates events which occur between <paramref name="FromDate"/>
        /// and <paramref name="ToDate"/>; therefore, if you require a list of events which
        /// occur outside of this range, you must specify a <paramref name="FromDate"/> and
        /// <paramref name="ToDate"/> which encapsulate the date(s) of interest.
        /// <note type="caution">
        ///     For events with very complex recurrence rules, this method may be a bottleneck
        ///     during processing time, especially when this method in called for a large number
        ///     of events, in sequence, or for a very large time span.
        /// </summary>
        /// <param name="FromDate">The beginning date of the range to evaluate.</param>
        /// <param name="ToDate">The end date of the range to evaluate.</param>
        /// <returns></returns>
        public override ArrayList Evaluate(Date_Time FromDate, Date_Time ToDate)
        {
            // Add the event itself, before recurrence rules are evaluated
            DateTimes.Add(DTStart.Copy());
            Periods.Add(new Period(DTStart, Duration));

            // Evaluate recurrences normally
            base.Evaluate(FromDate, ToDate);

            // Remove DateTimes that already have a Period
            for (int i = DateTimes.Count - 1; i >= 0; i--)
            {
                foreach (Period p in Periods)
                {
                    if (p.StartTime == DateTimes[i])
                    {
                        DateTimes.RemoveAt(i);
                    }
                }
            }

            // Convert each calculated Date_Time into a Period.
            foreach (Date_Time dt in DateTimes)
            {
                Period p = new Period(dt, Duration);
                if (!Periods.Contains(p))
                {
                    Periods.Add(p);
                }
            }

            Periods.Sort();
            return(Periods);
        }
예제 #9
0
        public override IList <IPeriod> Evaluate(IDateTime referenceDate, DateTime periodStart, DateTime periodEnd, bool includeReferenceDateInResults)
        {
            // Create a recurrence pattern suitable for use during evaluation.
            IRecurrencePattern pattern = ProcessRecurrencePattern(referenceDate);

            // Enforce evaluation restrictions on the pattern.
            EnforceEvaluationRestrictions(pattern);

            Periods.Clear();
            foreach (DateTime dt in GetDates(referenceDate, periodStart, periodEnd, -1, pattern, includeReferenceDateInResults))
            {
                // Turn each resulting date/time into an IDateTime and associate it
                // with the reference date.
                IDateTime newDt = new iCalDateTime(dt, referenceDate.TZID);

                // NOTE: fixes bug #2938007 - hasTime missing
                newDt.HasTime = referenceDate.HasTime;

                newDt.AssociateWith(referenceDate);

                // Create a period from the new date/time.
                IPeriod p = new Period(newDt);

                if (!Periods.Contains(p))
                {
                    Periods.Add(p);
                }
            }

            return(Periods);
        }
예제 #10
0
        /// <summary>
        /// Evalates the ExDate component, and excludes each specified DateTime or
        /// Period from the <see cref="Periods"/> collection.
        /// </summary>
        /// <param name="FromDate">The beginning date of the range to evaluate.</param>
        /// <param name="ToDate">The end date of the range to evaluate.</param>
        virtual protected void EvaluateExDate(iCalDateTime FromDate, iCalDateTime ToDate)
        {
            // Handle EXDATEs
            if (ExDate != null)
            {
                foreach (RecurrenceDates exdate in ExDate)
                {
                    List <Period> periods = exdate.Evaluate(DTStart, FromDate, ToDate);
                    foreach (Period p in periods)
                    {
                        // If no time was provided for the ExDate, then it excludes the entire day
                        if (!p.StartTime.HasTime || (p.EndTime != null && !p.EndTime.HasTime))
                        {
                            p.MatchesDateOnly = true;
                        }

                        if (p != null)
                        {
                            while (Periods.Contains(p))
                            {
                                Periods.Remove(p);
                            }
                        }
                    }
                }
            }
        }
예제 #11
0
        public override List <Period> Evaluate(Date_Time FromDate, Date_Time ToDate)
        {
            // Add the todo itself, before recurrence rules are evaluated
            Period startPeriod = new Period(DTStart);

            if (DTStart != null &&
                !Periods.Contains(startPeriod))
            {
                Periods.Add(startPeriod);
            }

            return(base.Evaluate(FromDate, ToDate));
        }
예제 #12
0
        public override System.Collections.Generic.List <Period> Evaluate(iCalDateTime FromDate, iCalDateTime ToDate)
        {
            if (Start != null)
            {
                Period p = new Period(Start);
                if (!Periods.Contains(p))
                {
                    Periods.Add(p);
                }

                return(base.Evaluate(FromDate, ToDate));
            }
            return(new System.Collections.Generic.List <Period>());
        }
        virtual public IPeriod GetNext(IDateTime referenceDate)
        {
            DateTime?dt = GetNextDate(referenceDate, referenceDate.Value, Pattern);

            if (dt != null)
            {
                // Create a period from the date/time.
                IPeriod p = CreatePeriod(dt.Value, referenceDate);

                if (!Periods.Contains(p))
                {
                    Periods.Add(p);
                }
            }
            return(null);
        }
예제 #14
0
        public override List <Period> Evaluate(Date_Time FromDate, Date_Time ToDate)
        {
            // TODO items can only recur if a start date is specified
            if (DTStart != null)
            {
                // Add the todo itself, before recurrence rules are evaluated
                Period startPeriod = new Period(DTStart);
                if (DTStart != null &&
                    !Periods.Contains(startPeriod))
                {
                    Periods.Add(startPeriod);
                }

                return(base.Evaluate(FromDate, ToDate));
            }
            return(new List <Period>());
        }
예제 #15
0
 /// <summary>
 /// Evalates the RDate component, and adds each specified DateTime or
 /// Period to the <see cref="Periods"/> collection.
 /// </summary>
 /// <param name="FromDate">The beginning date of the range to evaluate.</param>
 /// <param name="ToDate">The end date of the range to evaluate.</param>
 virtual protected void EvaluateRDate(iCalDateTime FromDate, iCalDateTime ToDate)
 {
     // Handle RDATEs
     if (RDate != null)
     {
         foreach (RecurrenceDates rdate in RDate)
         {
             List <Period> periods = rdate.Evaluate(DTStart, FromDate, ToDate);
             foreach (Period p in periods)
             {
                 if (p != null && !Periods.Contains(p))
                 {
                     Periods.Add(p);
                 }
             }
         }
     }
 }
예제 #16
0
        /// <summary>
        /// Evaluates this event to determine the dates and times for which the event occurs.
        /// This method only evaluates events which occur between <paramref name="FromDate"/>
        /// and <paramref name="ToDate"/>; therefore, if you require a list of events which
        /// occur outside of this range, you must specify a <paramref name="FromDate"/> and
        /// <paramref name="ToDate"/> which encapsulate the date(s) of interest.
        /// <note type="caution">
        ///     For events with very complex recurrence rules, this method may be a bottleneck
        ///     during processing time, especially when this method in called for a large number
        ///     of events, in sequence, or for a very large time span.
        /// </summary>
        /// <param name="FromDate">The beginning date of the range to evaluate.</param>
        /// <param name="ToDate">The end date of the range to evaluate.</param>
        /// <returns></returns>
        public override List <Period> Evaluate(Date_Time FromDate, Date_Time ToDate)
        {
            // Make sure Duration is not null by now
            if (Duration == null)
            {
                // If a DTEnd was not provided, set one!
                if (DTEnd == null)
                {
                    DTEnd = DTStart.Copy();
                }
                Duration = DTEnd - DTStart;
            }

            // Add the event itself, before recurrence rules are evaluated
            // NOTE: this fixes a bug where (if evaluated multiple times)
            // a period can be added to the Periods collection multiple times.
            Period period = new Period(DTStart, Duration);

            if (!Periods.Contains(period))
            {
                Periods.Add(period);
            }

            // Evaluate recurrences normally
            base.Evaluate(FromDate, ToDate);

            // Ensure each period has a duration
            foreach (Period p in Periods)
            {
                if (p.EndTime == null)
                {
                    p.Duration = Duration;
                    p.EndTime  = p.StartTime + Duration;
                }
                // Ensure the Kind of time is consistent with DTStart
                else if (p.EndTime.Kind != DTStart.Kind)
                {
                    p.EndTime.Value = new DateTime(p.EndTime.Year, p.EndTime.Month, p.EndTime.Day,
                                                   p.EndTime.Hour, p.EndTime.Minute, p.EndTime.Second, DTStart.Kind);
                }
            }

            return(Periods);
        }
        public List <string> GetPeriodsList()
        {
            if (!Periods.Contains("-"))
            {
                return new List <string> {
                           Periods
                }
            }
            ;
            var parts = Periods
                        .Split('-')
                        .Select(int.Parse)
                        .ToList();

            return(Enumerable.Range(parts.First(), parts.Last() - parts.First() + 1)
                   .Select(period => period.ToString())
                   .ToList());
        }
    }
예제 #18
0
        /// <summary>
        /// Evaluates this event to determine the dates and times for which the event occurs.
        /// This method only evaluates events which occur between <paramref name="FromDate"/>
        /// and <paramref name="ToDate"/>; therefore, if you require a list of events which
        /// occur outside of this range, you must specify a <paramref name="FromDate"/> and
        /// <paramref name="ToDate"/> which encapsulate the date(s) of interest.
        /// <note type="caution">
        ///     For events with very complex recurrence rules, this method may be a bottleneck
        ///     during processing time, especially when this method in called for a large number
        ///     of events, in sequence, or for a very large time span.
        /// </summary>
        /// <param name="FromDate">The beginning date of the range to evaluate.</param>
        /// <param name="ToDate">The end date of the range to evaluate.</param>
        /// <returns></returns>
        public override ArrayList Evaluate(Date_Time FromDate, Date_Time ToDate)
        {
            // Add the event itself, before recurrence rules are evaluated
            Periods.Add(new Period(DTStart, (TimeSpan)Duration));

            // Evaluate recurrences normally
            base.Evaluate(FromDate, ToDate);

            // Convert each calculated Date_Time into a Period.
            foreach (Date_Time dt in DateTimes)
            {
                Period p = new Period(dt, Duration);
                if (!Periods.Contains(p))
                {
                    Periods.Add(p);
                }
            }

            return(Periods);
        }
예제 #19
0
        /// <summary>
        /// Evaulates the RRule component, and adds each specified Period
        /// to the <see cref="Periods"/> collection.
        /// </summary>
        /// <param name="FromDate">The beginning date of the range to evaluate.</param>
        /// <param name="ToDate">The end date of the range to evaluate.</param>
        virtual protected void EvaluateRRule(Date_Time FromDate, Date_Time ToDate)
        {
            // Handle RRULEs
            if (RRule != null)
            {
                foreach (Recur rrule in RRule)
                {
                    List <Date_Time> DateTimes = rrule.Evaluate(DTStart, FromDate, ToDate);
                    foreach (Date_Time dt in DateTimes)
                    {
                        Period p = new Period(dt);

                        if (!Periods.Contains(p))
                        {
                            this.Periods.Add(p);
                        }
                    }
                }
            }
        }
예제 #20
0
        internal override List <Period> Evaluate(iCalDateTime FromDate, iCalDateTime ToDate)
        {
            // TODO items can only recur if a start date is specified
            if (DTStart != null)
            {
                // Add the todo itself, before recurrence rules are evaluated
                Period startPeriod = new Period(DTStart);
                if (DTStart != null &&
                    !Periods.Contains(startPeriod))
                {
                    Periods.Add(startPeriod);
                }

                base.Evaluate(FromDate, ToDate);

                // Ensure each period has a duration
                foreach (Period p in Periods)
                {
                    if (p.EndTime == null)
                    {
                        p.Duration = Duration;
                        if (p.Duration != null)
                        {
                            p.EndTime = p.StartTime + Duration;
                        }
                        else
                        {
                            p.EndTime = p.StartTime;
                        }
                    }
                    // Ensure the Kind of time is consistent with DTStart
                    else
                    {
                        p.EndTime.IsUniversalTime = DTStart.IsUniversalTime;
                    }
                }

                return(Periods);
            }
            return(new List <Period>());
        }
예제 #21
0
        /// <summary>
        /// Evalates the ExDate component, and excludes each specified DateTime or
        /// Period from the <see cref="Periods"/> collection.
        /// </summary>
        /// <param name="FromDate">The beginning date of the range to evaluate.</param>
        /// <param name="ToDate">The end date of the range to evaluate.</param>
        protected override void EvaluateExDate(Date_Time FromDate, Date_Time ToDate)
        {
            // Handle EXDATEs
            if (ExDate != null)
            {
                foreach (RDate exdate in ExDate)
                {
                    ArrayList Items = exdate.Evaluate(DTStart, FromDate, ToDate);
                    foreach (object obj in Items)
                    {
                        Period p = null;
                        if (obj is Period)
                        {
                            p = (Period)obj;
                        }
                        else if (obj is Date_Time)
                        {
                            p = new Period((Date_Time)obj, Duration);
                        }

                        // If no time was provided for the ExDate, then it excludes the entire day
                        if (!p.StartTime.HasTime || !p.EndTime.HasTime)
                        {
                            p.MatchesDateOnly = true;
                        }

                        if (p != null)
                        {
                            // If p.MatchesDateOnly, remove all occurrences of this event
                            // on that specific date
                            while (Periods.Contains(p))
                            {
                                Periods.Remove(p);
                                DateTimes.Remove(p.StartTime);
                            }
                        }
                    }
                }
            }
        }
예제 #22
0
 /// <summary>
 /// Evalates the RDate component, and adds each specified DateTime or
 /// Period to the <see cref="Periods"/> collection.
 /// </summary>
 /// <param name="periodStart">The beginning date of the range to evaluate.</param>
 /// <param name="periodEnd">The end date of the range to evaluate.</param>
 virtual protected void EvaluateRDate(IDateTime referenceDate, DateTime periodStart, DateTime periodEnd)
 {
     // Handle RDATEs
     if (Recurrable.RecurrenceDates != null)
     {
         foreach (IPeriodList rdate in Recurrable.RecurrenceDates)
         {
             IEvaluator evaluator = rdate.GetService(typeof(IEvaluator)) as IEvaluator;
             if (evaluator != null)
             {
                 IList <IPeriod> periods = evaluator.Evaluate(referenceDate, periodStart, periodEnd, false);
                 foreach (IPeriod p in periods)
                 {
                     if (!Periods.Contains(p))
                     {
                         Periods.Add(p);
                     }
                 }
             }
         }
     }
 }
예제 #23
0
        /// <summary>
        /// Evaulates the RRule component, and adds each specified Period
        /// to the <see cref="Periods"/> collection.
        /// </summary>
        /// <param name="FromDate">The beginning date of the range to evaluate.</param>
        /// <param name="ToDate">The end date of the range to evaluate.</param>
        virtual protected void EvaluateRRule(iCalDateTime FromDate, iCalDateTime ToDate)
        {
            // Handle RRULEs
            if (RRule != null)
            {
                foreach (RecurrencePattern rrule in RRule)
                {
                    // Get a list of static occurrences
                    // This is important to correctly calculate
                    // recurrences with COUNT.
                    rrule.StaticOccurrences = new List <iCalDateTime>();
                    foreach (Period p in Periods)
                    {
                        rrule.StaticOccurrences.Add(p.StartTime);
                    }

                    //
                    // Determine the last allowed date in this recurrence
                    //
                    if (rrule.Until != null && (Until == null || Until < rrule.Until))
                    {
                        Until = rrule.Until.Copy();
                    }

                    List <iCalDateTime> DateTimes = rrule.Evaluate(DTStart, FromDate, ToDate);
                    foreach (iCalDateTime dt in DateTimes)
                    {
                        dt.TZID = Start.TZID;
                        Period p = new Period(dt);

                        if (!Periods.Contains(p))
                        {
                            this.Periods.Add(p);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Remove old species facts that are no longer
        /// included in the species fact scope.
        /// </summary>
        private void RemoveSpeciesFactsNotInScope()
        {
            Int32        index;
            ISpeciesFact speciesFact;

            if (SpeciesFacts.IsNotEmpty())
            {
                for (index = SpeciesFacts.Count - 1; index >= 0; index--)
                {
                    speciesFact = SpeciesFacts[index];
                    if ((!Factors.Contains(speciesFact.Factor)) ||
                        (!IndividualCategories.Contains(speciesFact.IndividualCategory)) ||
                        (!Taxa.Contains(speciesFact.Taxon)) ||
                        (speciesFact.HasHost && !Hosts.Contains(speciesFact.Host)) ||
                        (speciesFact.HasPeriod && !Periods.Contains(speciesFact.Period)))
                    {
                        // This species fact is no longer
                        // included in the species fact scope.
                        SpeciesFacts.RemoveAt(index);
                    }
                }
            }
        }
예제 #25
0
        /// <summary>
        /// Evalates the ExDate component, and excludes each specified DateTime or
        /// Period from the <see cref="Periods"/> collection.
        /// </summary>
        /// <param name="FromDate">The beginning date of the range to evaluate.</param>
        /// <param name="ToDate">The end date of the range to evaluate.</param>
        virtual protected void EvaluateExDate(Date_Time FromDate, Date_Time ToDate)
        {
            // Handle EXDATEs
            if (ExDate != null)
            {
                foreach (RDate exdate in ExDate)
                {
                    ArrayList Items = exdate.Evaluate(DTStart, FromDate, ToDate);
                    foreach (object obj in Items)
                    {
                        Period p = null;
                        if (obj is Period)
                        {
                            p = (Period)obj;
                        }
                        else if (obj is Date_Time)
                        {
                            p = new Period((Date_Time)obj);
                        }

                        // If no time was provided for the ExDate, then it excludes the entire day
                        if (!p.StartTime.HasTime || (p.EndTime != null && !p.EndTime.HasTime))
                        {
                            p.MatchesDateOnly = true;
                        }

                        if (p != null)
                        {
                            while (Periods.Contains(p))
                            {
                                Periods.Remove(p);
                            }
                        }
                    }
                }
            }
        }
예제 #26
0
        public override IList <IPeriod> Evaluate(IDateTime referenceDate, DateTime periodStart, DateTime periodEnd, bool includeReferenceDateInResults)
        {
            // Ensure the reference date is associated with the time zone
            if (referenceDate.AssociatedObject == null)
            {
                referenceDate.AssociatedObject = TimeZone;
            }

            List <ITimeZoneInfo> infos = new List <ITimeZoneInfo>(TimeZone.TimeZoneInfos);

            // Evaluate extra time periods, without re-evaluating ones that were already evaluated
            if ((EvaluationStartBounds == DateTime.MaxValue && EvaluationEndBounds == DateTime.MinValue) ||
                (periodEnd.Equals(EvaluationStartBounds)) ||
                (periodStart.Equals(EvaluationEndBounds)))
            {
                foreach (ITimeZoneInfo curr in infos)
                {
                    IEvaluator evaluator = curr.GetService(typeof(IEvaluator)) as IEvaluator;
                    Debug.Assert(curr.Start != null, "TimeZoneInfo.Start must not be null.");
                    Debug.Assert(curr.Start.TZID == null, "TimeZoneInfo.Start must not have a time zone reference.");
                    Debug.Assert(evaluator != null, "TimeZoneInfo.GetService(typeof(IEvaluator)) must not be null.");

                    // Time zones must include an effective start date/time
                    // and must provide an evaluator.
                    if (evaluator != null)
                    {
                        // Set the start bounds
                        if (EvaluationStartBounds > periodStart)
                        {
                            EvaluationStartBounds = periodStart;
                        }

                        // FIXME: 5 years is an arbitrary number, to eliminate the need
                        // to recalculate time zone information as much as possible.
                        DateTime offsetEnd = periodEnd.AddYears(5);

                        // Determine the UTC occurrences of the Time Zone observances
                        IList <IPeriod> periods = evaluator.Evaluate(
                            referenceDate,
                            periodStart,
                            offsetEnd,
                            includeReferenceDateInResults);

                        foreach (IPeriod period in periods)
                        {
                            if (!Periods.Contains(period))
                            {
                                Periods.Add(period);
                            }

                            Occurrence o = new Occurrence(curr, period);
                            if (!m_Occurrences.Contains(o))
                            {
                                m_Occurrences.Add(o);
                            }
                        }

                        if (EvaluationEndBounds == DateTime.MinValue || EvaluationEndBounds < offsetEnd)
                        {
                            EvaluationEndBounds = offsetEnd;
                        }
                    }
                }

                ProcessOccurrences(referenceDate);
            }
            else
            {
                if (EvaluationEndBounds != DateTime.MinValue && periodEnd > EvaluationEndBounds)
                {
                    Evaluate(referenceDate, EvaluationEndBounds, periodEnd, includeReferenceDateInResults);
                }
            }

            return(Periods);
        }