/// <summary> /// Polls the <see cref="Alarm"/> component for alarms that have been triggered /// since the provided <paramref name="Start"/> date/time. If <paramref name="Start"/> /// is null, all triggered alarms will be returned. /// </summary> /// <param name="Start">The earliest date/time to poll trigerred alarms for.</param> /// <returns>A list of <see cref="AlarmOccurrence"/> objects, each containing a triggered alarm.</returns> public List <AlarmOccurrence> Poll(Date_Time Start, Date_Time End) { // Ensure the recurring component that owns this // alarm has evaluated the time frame in question // before polling alarms RecurringComponent rc = Parent as RecurringComponent; if (rc != null) { rc.Evaluate( Start ?? rc.Start, End ?? DateTime.Now); } List <AlarmOccurrence> Results = new List <AlarmOccurrence>(); foreach (AlarmOccurrence ao in Occurrences) { if ((Start == null || ao.DateTime >= Start) && ao.DateTime <= DateTime.Now) { Results.Add(ao.Copy()); } } return(Results); }
/// <summary> /// Evaluates <see cref="Alarm"/>s for the given recurring component, <paramref name="rc"/>. /// This evaluation is based on the evaluation period for the <see cref="RecurringComponent"/>. /// </summary> /// <param name="rc">The </param> /// <returns></returns> virtual public List <AlarmOccurrence> Evaluate(RecurringComponent rc) { Occurrences = new List <AlarmOccurrence>(); // If the trigger is relative, it can recur right along with // the recurring items, otherwise, it happens once and // only once (at a precise time). if (Trigger.IsRelative) { foreach (Date_Time dt in rc.DateTimes) { Occurrences.Add(new AlarmOccurrence(this, dt + Trigger.Duration, rc)); } } else { Occurrences.Add(new AlarmOccurrence(this, Trigger.DateTime.Copy(), rc)); } // If a REPEAT and DURATION value were specified, // then handle those repetitions here. AddRepeatedItems(); return(Occurrences); }
/// <summary> /// "Flattens" component recurrences that occur in the given date into a series of equivalent objects. /// </summary> /// <param name="dt">The date on which the event recurs</param> /// <returns>A list of <see cref="Event"/>s if they could be flattened, null otherwise.</returns> virtual public IEnumerable <RecurringComponent> FlattenRecurrencesOn(Date_Time dt) { // Create a dummy iCalendar to hold our flattened component iCalendar iCal = new iCalendar(); if (Start.TZID != null) { // Place the time zone into our dummy iCalendar DDay.iCal.Components.TimeZone tz = iCalendar.GetTimeZone(Start.TZID); if (tz != null) { tz.Copy(iCal); } } // Iterate through each period to find all occurrences on this date foreach (Period p in Periods) { // Check to see if this occurrence is on the same date if (p.StartTime.Date.Equals(dt.Date)) { // Copy the component into the dummy iCalendar RecurringComponent rc = (RecurringComponent)Copy(iCal); rc.Start = p.StartTime.Copy(); rc.RRule = new Recur[0]; rc.RDate = new RDate[0]; rc.ExRule = new Recur[0]; rc.ExDate = new RDate[0]; yield return(rc); } } }
/// <summary> /// Gets a list of alarm occurrences for the given recurring component, <paramref name="rc"/> /// that occur between <paramref name="FromDate"/> and <paramref name="ToDate"/>. /// </summary> virtual public List <AlarmOccurrence> GetOccurrences(RecurringComponent rc, iCalDateTime FromDate, iCalDateTime ToDate) { Occurrences.Clear(); // If the trigger is relative, it can recur right along with // the recurring items, otherwise, it happens once and // only once (at a precise time). if (Trigger.IsRelative) { // Ensure that "FromDate" has already been set if (FromDate == null) { FromDate = rc.Start.Copy(); } Duration d = null; foreach (Occurrence o in rc.GetOccurrences(FromDate, ToDate)) { iCalDateTime dt = o.Period.StartTime; if (Trigger.Related == Trigger.TriggerRelation.End) { if (o.Period.EndTime != null) { dt = o.Period.EndTime; if (d == null) { d = o.Period.Duration; } } // Use the "last-found" duration as a reference point else if (d != null) { dt = o.Period.StartTime + d; } else { throw new ArgumentException("Alarm trigger is relative to the END of the occurrence; however, the occurence has no discernible end."); } } Occurrences.Add(new AlarmOccurrence(this, dt + Trigger.Duration, rc)); } } else { Occurrences.Add(new AlarmOccurrence(this, Trigger.DateTime.Copy(), rc)); } // If a REPEAT and DURATION value were specified, // then handle those repetitions here. AddRepeatedItems(); return(Occurrences); }
/// <summary> /// Polls the <see cref="Alarm"/> component for alarms that have been triggered /// since the provided <paramref name="Start"/> date/time. If <paramref name="Start"/> /// is null, all triggered alarms will be returned. /// </summary> /// <param name="Start">The earliest date/time to poll trigerred alarms for.</param> /// <returns>A list of <see cref="AlarmOccurrence"/> objects, each containing a triggered alarm.</returns> public List <AlarmOccurrence> Poll(iCalDateTime Start, iCalDateTime End) { List <AlarmOccurrence> Results = new List <AlarmOccurrence>(); // Evaluate the alarms to determine the recurrences RecurringComponent rc = Parent as RecurringComponent; if (rc != null) { Results.AddRange(GetOccurrences(rc, Start, End)); Results.Sort(); } return(Results); }
/// <summary> /// "Flattens" a single component recurrence into a copy of the /// component. This essentially "extracts" a recurrence into /// a fully-fledged non-recurring object (a single instance). /// </summary> /// <param name="obj">The iCalObject that will contain this recurring component</param> /// <param name="p">The period (recurrence instance) to be flattened</param> /// <returns>A recurring component which represents a single flattened recurrence instance</returns> virtual protected RecurringComponent FlattenInstance(iCalObject obj, Period p) { // Copy the component into the dummy iCalendar RecurringComponent rc = (RecurringComponent)Copy(obj); rc.m_IsOriginal = false; rc.m_Original = this; rc.Start = p.StartTime.Copy(); rc.RRule = new Recur[0]; rc.RDate = new RDate[0]; rc.ExRule = new Recur[0]; rc.ExDate = new RDate[0]; return(rc); }
/// <summary> /// Evaluates <see cref="Alarm"/>s for the given recurring component, <paramref name="rc"/>. /// This evaluation is based on the evaluation period for the <see cref="RecurringComponent"/>. /// </summary> /// <param name="rc">The </param> /// <returns></returns> virtual public List <AlarmOccurrence> Evaluate(RecurringComponent rc) { Occurrences = new List <AlarmOccurrence>(); // If the trigger is relative, it can recur right along with // the recurring items, otherwise, it happens once and // only once (at a precise time). if (Trigger.IsRelative) { Duration d = null; foreach (Period p in rc.Periods) { Date_Time dt = p.StartTime; if (Trigger.Related == Trigger.TriggerRelation.END) { if (p.EndTime != null) { dt = p.EndTime; if (d == null) { d = p.Duration; } } // Use the "last-found" duration as a reference point else if (d != null) { dt = p.StartTime + d; } else { throw new ArgumentException("Alarm trigger is relative to the END of the occurrence; however, the occurence has discernible end."); } } Occurrences.Add(new AlarmOccurrence(this, dt + Trigger.Duration, rc)); } } else { Occurrences.Add(new AlarmOccurrence(this, Trigger.DateTime.Copy(), rc)); } // If a REPEAT and DURATION value were specified, // then handle those repetitions here. AddRepeatedItems(); return(Occurrences); }
public override bool Equals(object obj) { if (obj is RecurringComponent && obj != this) { RecurringComponent r = (RecurringComponent)obj; if (UID != null) { return(UID.Equals(r.UID)); } else { return(UID == r.UID); } } return(base.Equals(obj)); }
public AlarmOccurrence(Alarm a, Date_Time dt, RecurringComponent rc) { this.Alarm = a; this.Period = new Period(dt); this.Component = rc; }
public AlarmOccurrence(AlarmOccurrence ao) { this.Alarm = ao.Alarm; this.DateTime = ao.DateTime.Copy(); this.Component = ao.Component; }
static public Alarm Create(RecurringComponent rc) { Alarm alarm = rc.iCalendar.Create<Alarm>(); return alarm; }
public Occurrence(Occurrence ao) { this.Period = ao.Period.Copy(); this.Component = ao.Component; }
static public Alarm Create(RecurringComponent rc) { Alarm alarm = (Alarm)rc.iCalendar.Create(rc, "VALARM"); return(alarm); }
/// <summary> /// Evaluates <see cref="Alarm"/>s for the given recurring component, <paramref name="rc"/>. /// This evaluation is based on the evaluation period for the <see cref="RecurringComponent"/>. /// </summary> /// <param name="rc">The </param> /// <returns></returns> virtual public List<AlarmOccurrence> Evaluate(RecurringComponent rc) { Occurrences.Clear(); // If the trigger is relative, it can recur right along with // the recurring items, otherwise, it happens once and // only once (at a precise time). if (Trigger.IsRelative) { Duration d = null; foreach (Period p in rc.Periods) { Date_Time dt = p.StartTime; if (Trigger.Related == Trigger.TriggerRelation.END) { if (p.EndTime != null) { dt = p.EndTime; if (d == null) d = p.Duration; } // Use the "last-found" duration as a reference point else if (d != null) dt = p.StartTime + d; else throw new ArgumentException("Alarm trigger is relative to the END of the occurrence; however, the occurence has no discernible end."); } Occurrences.Add(new AlarmOccurrence(this, dt + Trigger.Duration, rc)); } } else Occurrences.Add(new AlarmOccurrence(this, Trigger.DateTime.Copy(), rc)); // If a REPEAT and DURATION value were specified, // then handle those repetitions here. AddRepeatedItems(); return Occurrences; }
public AlarmOccurrence(Alarm a, Date_Time dt, RecurringComponent rc) { this.Alarm = a; this.DateTime = dt; this.Component = rc; }
public Occurrence(RecurringComponent component, Period period) { Component = component; Period = period; }
static public Alarm Create(RecurringComponent rc) { Alarm alarm = (Alarm)rc.iCalendar.Create(rc, "VALARM"); return alarm; }
static public Alarm Create(RecurringComponent rc) { Alarm alarm = rc.iCalendar.Create <Alarm>(); return(alarm); }