/// <summary> /// A timeout is an event that is executed after a certain timespan has passed. /// </summary> /// <remarks> /// Timeout events are scheduled when they are created. They are always triggered /// when they are created. /// </remarks> /// <param name="environment">The environment in which it is scheduled.</param> /// <param name="delay">The timespan for the timeout.</param> /// <param name="value">The value of the timeout.</param> /// <param name="isOk">Whether the timeout should succeed or fail.</param> public Timeout(Environment environment, TimeSpan delay, object value = null, bool isOk = true) : base(environment) { IsOk = isOk; Value = value; IsTriggered = true; environment.Schedule(delay, this); }
public Initialize(Environment environment, Process process) : base(environment) { CallbackList.Add(process.Resume); IsOk = true; IsTriggered = true; environment.Schedule(this); }
/// <summary> /// This method schedules the event right now. It sets IsOk state to false /// and optionally uses also the value. If urgent is given, the event may /// be scheduled as urgent. Urgent events are placed in a separate event /// queue. The callbacks of urgent events are executed before normal events. /// </summary> /// <exception cref="InvalidOperationException"> /// Thrown when the event has already been triggered. /// </exception> /// <param name="value">The value that the event should use.</param> /// <param name="urgent">Whether the event should be scheduled urgently. /// This is ususally not required and should be reserved for very special /// cases.</param> public virtual void Fail(object value = null) { if (IsTriggered) { throw new InvalidOperationException("Event has already been triggered."); } IsOk = false; Value = value; IsTriggered = true; Environment.Schedule(this); }
/// <summary> /// This method schedules the event right now. It takes the IsOk state /// and uses the <see cref="Value"/> of the given <paramref name="@event"/>. /// Thus if the given event fails, this event will also be triggered as /// failing. /// </summary> /// <exception cref="InvalidOperationException"> /// Thrown when the event has already been triggered. /// </exception> /// <remarks> /// The signature of this method allows it to be used as a callback. /// </remarks> /// <param name="event">The event that triggers this event.</param> public virtual void Trigger(Event @event) { if (IsTriggered) { throw new InvalidOperationException("Event has already been triggered."); } IsOk = @event.IsOk; Value = @event.Value; IsTriggered = true; Environment.Schedule(this); }
/// <summary> /// This method schedules the event right now. It sets IsOk state to true /// and optionally uses also the value. If urgent is given, the event may /// be scheduled as urgent. Urgent events are placed in a separate event /// queue. The callbacks of urgent events are executed before normal events. /// </summary> /// <exception cref="InvalidOperationException"> /// Thrown when the event has already been triggered. /// </exception> /// <param name="value">The value that the event should use.</param> /// <param name="priority">The priority to rank events at the same time (smaller value = higher priority).</param> public virtual void Succeed(object value = null, int priority = 0) { if (IsTriggered) { throw new InvalidOperationException("Event has already been triggered."); } IsOk = true; Value = value; IsTriggered = true; Environment.Schedule(this, priority); }