Пример #1
0
            public void HandleConditionsMetEvent(object sender, ConditionsMetEventArgs e)
            {
                if (!new int[] {0, 10, 20, 30, 40, 50}.Contains(e.TimeScheduledUtc.Second))
                    throw new InvalidOperationException();

                Ticked = true;
            }
Пример #2
0
            public void HandleConditionsMetEvent(object sender, ConditionsMetEventArgs e)
            {
                if (!new int[] { 1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56 }.Contains(e.TimeScheduledUtc.Second))
                    throw new InvalidOperationException();

                Ticked = true;
            }
Пример #3
0
		public void HandleConditionsMetEvent(object sender, ConditionsMetEventArgs e)
		{
			try
			{
				using (var client = new BackgroundServiceClient())
				{
					client.CheckSMSReplies();
				}
			}
			catch (Exception ex)
			{
				Logger.WriteError(ex);
			}
		}
Пример #4
0
		public void HandleConditionsMetEvent(object sender, ConditionsMetEventArgs e)
		{
			Logger.WriteInfo("DailyTask.Elapsed");

			try
			{
				foreach (var taskType in _taskTypes)
				{
					using (var client = new BackgroundServiceClient())
					{
						Logger.WriteInfo("DailyTask.Elapsed. Add " + taskType.ToString());
						client.AddTask(taskType, null);
					}
				}
			}
			catch (Exception ex)
			{
				Logger.WriteError(ex);
			}
		}
 public void HandleConditionsMetEvent(object sender, ConditionsMetEventArgs e)
 {
     Console.WriteLine("{0}: Event intended for {1:o} occured at {2:o}", e.TaskId, e.TimeScheduledUtc, e.TimeSignaledUtc);
 }
Пример #6
0
            public void HandleConditionsMetEvent(object sender, ConditionsMetEventArgs e)
            {
                if (!new int[] { 2, 7, 12, 17, 22, 27, 32, 37, 42, 47, 52, 57 }.Contains(e.TimeScheduledUtc.Second))
                    throw new InvalidOperationException();

                Ticked = true;
            }
 /// <summary>
 /// Calls OnConditionsMet on its own thread, which then raises the ConditionsMet event for each of the delegates wired up.
 /// </summary>
 protected virtual void OnConditionsMetAsync(object sender, ConditionsMetEventArgs e)
 {
     if (ConditionsMet != null)
     {
         EventHandler<ConditionsMetEventArgs> workerDelegate = new EventHandler<ConditionsMetEventArgs>(this.OnConditionsMet);
         workerDelegate.BeginInvoke(sender, e,
             new AsyncCallback(asyncResult => ((EventHandler<ConditionsMetEventArgs>)asyncResult.AsyncState).EndInvoke(asyncResult)),
             workerDelegate);
     }
 }
 /// <summary>
 /// Raises a ConditionsMet event.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected virtual void OnConditionsMet(object sender, ConditionsMetEventArgs e)
 {
     if (ConditionsMet != null)
         ConditionsMet(sender, e);
 }
        /// <summary>
        /// Compare the provided DateTime to the schedule definition. If the event should occur,
        /// the <see cref="ConditionsMet"/> will fire and this will return true.
        /// </summary>
        /// <param name="DateTime">In UTC</param>
        /// <returns></returns>
        public bool Evaluate(DateTime inputValueUtc)
        {
            //TODO : move compareValue into a more compare-friendly object. Peformance-wise, probably not ever necessary.

            //The inputValue is in UTC, but the rule supports comparing in Local time.
            //Determine which we want to compare and save it as compareValue.
            DateTime compareValue = Kind == DateTimeKind.Local ? compareValue = inputValueUtc.ToLocalTime() : compareValue = inputValueUtc;

            //Perform a bitwise AND on the compareValue and this. If the result is non-zero, then there is a match.
            //1 << x is the same as 2^^x, just faster since it's not a floating point op.
            bool match = ((1 << compareValue.Month & this.Month) != 0)
                && ((1L << compareValue.Day & this.DayOfMonth) != 0)
                && ((1L << (int)compareValue.DayOfWeek & this.DayOfWeek) != 0)
                && ((1L << compareValue.Hour & this.Hour) != 0)
                && ((1L << compareValue.Minute & this.Minute) != 0)
                && ((1L << compareValue.Second & this.Second) != 0);

            if (match)
            {
                ConditionsMetEventArgs e = new ConditionsMetEventArgs();
                e.TimeScheduledUtc = inputValueUtc;
                e.TimeSignaledUtc = DateTime.UtcNow;
                e.TaskId = TaskId.Increment();
                e.ScheduleDefinition = this;
                OnConditionsMetAsync(this, e);
            }

            return match;
        }