Ejemplo n.º 1
0
		/// <summary>
		/// Returns a list of Dates that are the next fire times of a  <see cref="Trigger" />
		/// that fall within the given date range. The input trigger will be cloned
		/// before any work is done, so you need not worry about its state being
		/// altered by this method.
		/// <p>
		/// NOTE: if this is a trigger that has previously fired within the given
		/// date range, then firings which have already occured will not be listed
		/// in the output List.
		/// </p>
		/// </summary>
		/// <param name="trigg">The trigger upon which to do the work</param>
		/// <param name="cal">The calendar to apply to the trigger's schedule</param>
		/// <param name="from">The starting date at which to find fire times</param>
		/// <param name="to">The ending date at which to stop finding fire times</param>
		/// <returns>List of java.util.Date objects</returns>
		public static IList ComputeFireTimesBetween(Trigger trigg, ICalendar cal, DateTime from, DateTime to)
		{
			ArrayList lst = new ArrayList();

			Trigger t = (Trigger) trigg.Clone();

			if (t.GetNextFireTimeUtc() == null || !t.GetNextFireTimeUtc().HasValue)
			{
				t.StartTimeUtc = from;
				t.EndTimeUtc = to;
				t.ComputeFirstFireTimeUtc(cal);
			}

			// TODO: this method could be more efficient by using logic specific
			//        to the type of trigger ...
			while (true)
			{
                NullableDateTime d = t.GetNextFireTimeUtc();
                if (d.HasValue)
				{
					if (d.Value < from)
					{
						t.Triggered(cal);
						continue;
					}
					if (d.Value > to)
					{
						break;
					}
					lst.Add(d);
					t.Triggered(cal);
				}
				else
				{
					break;
				}
			}
			return ArrayList.ReadOnly(new ArrayList(lst));
		}
Ejemplo n.º 2
0
		/// <summary>
		/// Returns a list of Dates that are the next fire times of a
		/// <see cref="Trigger" />.
		/// The input trigger will be cloned before any work is done, so you need
		/// not worry about its state being altered by this method.
		/// </summary>
		/// <param name="trigg">The trigger upon which to do the work</param>
		/// <param name="cal">The calendar to apply to the trigger's schedule</param>
		/// <param name="numTimes">The number of next fire times to produce</param>
		/// <returns>List of java.util.Date objects</returns>
		public static IList ComputeFireTimes(Trigger trigg, ICalendar cal, int numTimes)
		{
			ArrayList lst = new ArrayList();

			Trigger t = (Trigger) trigg.Clone();

			if (t.GetNextFireTimeUtc() == null || !t.GetNextFireTimeUtc().HasValue)
			{
				t.ComputeFirstFireTimeUtc(cal);
			}

			for (int i = 0; i < numTimes; i++)
			{
                NullableDateTime d = t.GetNextFireTimeUtc();
                if (d.HasValue)
				{
					lst.Add(d);
					t.Triggered(cal);
				}
				else
				{
					break;
				}
			}

			return ArrayList.ReadOnly(new ArrayList(lst));
		}