示例#1
0
 public override bool TryParse(string value, ref object obj)
 {
     string[] values = value.Split(',');
     foreach (string v in values)
     {
         object dt = new Date_Time();
         object p = new Period();
         
         //
         // Set the iCalendar for each Date_Time object here,
         // so that any time zones applied to these objects will be
         // handled correctly.
         // NOTE: fixes RRULE30 eval, where EXDATE references a 
         // DATE-TIME without a time zone; therefore, the time zone
         // is implied from DTSTART, and would fail to do a proper
         // time zone lookup, because it wasn't assigned an iCalendar
         // object.
         //
         if (((Date_Time)dt).TryParse(v, ref dt))
         {
             ((Date_Time)dt).iCalendar = iCalendar;
             ((Date_Time)dt).TZID = TZID;
             Items.Add(dt);
         }
         else if (((Period)p).TryParse(v, ref p))
         {
             ((Period)p).StartTime.iCalendar = ((Period)p).EndTime.iCalendar = iCalendar;
             ((Period)p).StartTime.TZID = ((Period)p).EndTime.TZID = TZID;
             Items.Add(p);
         }
         else return false;
     }
     return true;
 }
示例#2
0
        public override System.Collections.Generic.List<Period> Evaluate(Date_Time FromDate, Date_Time 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>();
        }
示例#3
0
        public override bool TryParse(string value, ref object obj)
        {
            string[] values = value.Split(',');
            foreach (string v in values)
            {
                object dt = new Date_Time();
                object p = new Period();

                if (((Date_Time)dt).TryParse(v, ref dt))
                    Items.Add(dt);
                else if (((Period)p).TryParse(v, ref p))
                    Items.Add(p);
                else return false;
            }
            return true;
        }
示例#4
0
 /// <summary>
 /// "Flattens" a single todo recurrence into a copy of the
 /// todo.  This essentially "extracts" a recurrence into
 /// a fully-fledged non-recurring todo (a single instance).
 /// </summary>
 /// <param name="obj">The iCalObject that will contain the flattened todo</param>
 /// <param name="p">The period (instance) to be flattened</param>
 /// <returns>A todo which represents a single flattened todo instance</returns>
 protected override RecurringComponent FlattenInstance(iCalObject obj, Period p)
 {
     Todo todo = (Todo)base.FlattenInstance(obj, p);            
     todo.Duration = p.Duration;
     return todo;
 }
示例#5
0
 public override object Parse(string value)
 {
     object p = new Period();
     if (!TryParse(value, ref p))
         throw new ArgumentException("Period.Parse cannot parse the value '" + value + "' because it is not formatted correctly.");
     return p;
 }
示例#6
0
 public void Add(Period p)
 {
     Periods.Add(p);
 }
示例#7
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, (TimeSpan)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);
                        }
                    }
                }
            }
        }
示例#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
            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;
        }
示例#9
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>                
        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;
                    if (p.Duration != null)
                        p.EndTime = p.StartTime + Duration;
                    else p.EndTime = p.StartTime;
                }
                // Ensure the Kind of time is consistent with DTStart
                else if (p.EndTime.Kind != DTStart.Kind)
                    p.EndTime.Kind = DTStart.Kind;
            }

            return Periods;
        }
示例#10
0
 /// <summary>
 /// Evaulates the ExRule component, and excludes each specified DateTime
 /// 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 void EvaluateExRule(Date_Time FromDate, Date_Time ToDate)
 {
     // Handle EXRULEs
     if (ExRule != null)
     {
         foreach (Recur exrule in ExRule)
         {
             ArrayList DateTimes = exrule.Evaluate(DTStart, FromDate, ToDate);
             foreach (Date_Time dt in DateTimes)
             {
                 Period p = new Period(dt, (TimeSpan)Duration);
                 if (Periods.Contains(p))
                     Periods.Remove(p);
             }
         }
     }
 }
示例#11
0
 /// <summary>
 /// Evaulates the RRule component, and adds each specified DateTime
 /// 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>
 protected void EvaluateRRule(Date_Time FromDate, Date_Time ToDate)
 {
     // Handle RRULEs
     if (RRule != null)
     {
         foreach (Recur rrule in RRule)
         {
             ArrayList DateTimes = rrule.Evaluate(DTStart, FromDate, ToDate);
             foreach (Date_Time dt in DateTimes)
             {
                 Period p = new Period(dt, (TimeSpan)Duration);
                 if (!Periods.Contains(p))
                     Periods.Add(p);
             }
         }
     }
 }
示例#12
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>
        protected void EvaluateRDate(DateTime FromDate, DateTime ToDate)
        {
            // Handle RDATEs
            if (RDate != null)
            {
                foreach (RDate rdate in RDate)
                {
                    ArrayList Items = rdate.Evaluate(DTStart, new Date_Time(FromDate), new Date_Time(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).Value, Duration.Value);

                        if (p != null && !Periods.Contains(p))
                            Periods.Add(p);
                    }
                }
            }
        }
示例#13
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)
                {
                    // Get a list of static occurrences
                    // This is important to correctly calculate
                    // recurrences with COUNT.
                    rrule.StaticOccurrences = new List<Date_Time>();
                    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<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);
                    }
                }
            }
        }
示例#14
0
文件: Todo.cs 项目: xxjeng/nuxleus
        public 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>();
        }
示例#15
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;
        }
示例#16
0
 public void Remove(Period p)
 {
     Periods.Remove(p);
 }
示例#17
0
 public PeriodSerializer(Period p)
     : base(p)
 {
     this.m_Period = p;
 }
示例#18
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);
                    }
                }
            }
        }
示例#19
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;
        }
示例#20
0
 /// <summary>
 /// Evaulates the ExRule component, and excludes each specified DateTime
 /// 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 EvaluateExRule(Date_Time FromDate, Date_Time ToDate)
 {
     // Handle EXRULEs
     if (ExRule != null)
     {
         foreach (Recur exrule in ExRule)
         {
             List<Date_Time> DateTimes = exrule.Evaluate(DTStart, FromDate, ToDate);
             foreach (Date_Time dt in DateTimes)
             {
                 Period p = new Period(dt);
                 if (this.Periods.Contains(p))
                     this.Periods.Remove(p);
             }
         }
     }
 }
示例#21
0
        protected override 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, (TimeSpan)Duration);

                        if (p != null && !Periods.Contains(p))
                            Periods.Add(p);
                    }
                }
            }
        }
示例#22
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);
                        }
                    }
                }
            }
        }
示例#23
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);
        }
示例#24
0
 /// <summary>
 /// "Flattens" a single event recurrence into a copy of the
 /// event.  This essentially "extracts" a recurrence into
 /// a fully-fledged non-recurring event (a single instance).
 /// </summary>
 /// <param name="obj">The iCalObject that will contain the flattened event</param>
 /// <param name="p">The period (instance) to be flattened</param>
 /// <returns>An event which represents a single flattened event instance</returns>
 protected override RecurringComponent FlattenInstance(iCalObject obj, Period p)
 {
     Event evt = (Event)base.FlattenInstance(obj, p);
     evt.Duration = p.Duration;
     return evt;
 }
示例#25
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>();
        }
示例#26
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;
        }