This project has moved. For the latest updates, please go here.

Implementation of Delay vs RandomDelay

Dec 27, 2011 at 5:22 AM

In reviewing the implementation of Delay and RandomDelay, it seems that they have essentially identical behavior and use... 

Daily Trigger

 

/// <summary>
/// Gets or sets a delay time that is randomly added to the start time of the trigger.
/// </summary>
[DefaultValue(0)]
public TimeSpan RandomDelay
{
	get
	{
		if (v2Trigger != null)
			return Task.StringToTimeSpan(((V2Interop.IDailyTrigger)v2Trigger).RandomDelay);
		if (v1Trigger != null)
			throw new NotV1SupportedException();
		return (unboundValues.ContainsKey("RandomDelay") ? (TimeSpan)unboundValues["RandomDelay"] : TimeSpan.Zero);
	}
	set
	{
		if (v2Trigger != null)
			((V2Interop.IDailyTrigger)v2Trigger).RandomDelay = Task.TimeSpanToString(value);
		else if (v1Trigger != null)
			throw new NotV1SupportedException();
		else
			unboundValues["RandomDelay"] = value;
	}
}

/// <summary>
/// Gets or sets a value that indicates the amount of time before the task is started.
/// </summary>
/// <value>The delay duration.</value>
TimeSpan ITriggerDelay.Delay
{
	get { return this.RandomDelay; }
	set { this.RandomDelay = value; }
}

 

Boot Trigger

 

/// <summary>
/// Gets or sets a value that indicates the amount of time between when the system is booted and when the task is started.
/// </summary>
[DefaultValue(0)]
public TimeSpan Delay
{
	get
	{
		if (v2Trigger != null)
			return Task.StringToTimeSpan(((V2Interop.IBootTrigger)v2Trigger).Delay);
		if (v1Trigger != null)
			throw new NotV1SupportedException();
		return (unboundValues.ContainsKey("Delay") ? (TimeSpan)unboundValues["Delay"] : TimeSpan.Zero);
	}
	set
	{
		if (v2Trigger != null)
			((V2Interop.IBootTrigger)v2Trigger).Delay = Task.TimeSpanToString(value);
		else if (v1Trigger != null)
			throw new NotV1SupportedException();
		else
			unboundValues["Delay"] = value;
	}
}

I'm wondering if this is just un-refactored code, or if there was a conscious decision to make things work in this fashion?

Coordinator
Dec 27, 2011 at 4:13 PM
Edited Dec 27, 2011 at 4:15 PM

It was conscious as I wanted to closely follow the scripting model of the V2 native library. I added the ITriggerDelay interface as a means of simplifying some of the UI code. You will notice that the RandomDelay and Delay properties pull from their similarly named counterparts in the V2 library.

It was also important to retain the different property names as they do behave differently. RandomDelay will pick a random time up to the amount specified before starting the task. Delay will execute at precisely that time.