Проекты

Timers Plugin

Timers storage for service infrastructure. This is a core component for each service infrastructure where you need to invoke any process after some time.

This plugin can be configured through Plugin.Configuration or Plugin.ConfigurationHttp plugin.

Settings

  • Description: — Timer description (For search simplicity)
  • Timer Name: — Timer name that can be used from application
  • Interval: 00:01:00 — Timer interval
  • Sleep Hours: Empty — Temporary suspend interval (Turned off by default)
    1. StartTimeSpan: 00:00:00 — Start suspend interval
    2. EndTimeSpan: 23:59:59 — End suspend interval
  • Start Interval (sec): 00:00:01 — Startup interval after host is started
  • Work Days: 127 — Days when timer is working
  • Work Hours: Empty — Hours when timer is working (Turned off by default)
    1. StartTimeSpan: 00:00:00 — Start time
    2. EndTimeSpan: 23:59:59 — End time
  • Single Instance: False — Timer can be launched only in one instance. (IPC will be launched with the timer)
  • Timer Type: TimersTimer — Type of used native timer (Available timers: System.Timers.Timer, System.Threading.Timer, System.Windows.Forms.Timer)
  • Default — Default settings for new timers. If plugin will use timer with unknown Timer Name then this settings will be used as a default values.

Methods

/// <summary>Reference to plugin description</summary>
public IPluginDescription PluginInstance
{
	get { return this._pluginTimer ?? (this._pluginTimer = this.Plugin.Host.Plugins["69c79417-c168-434a-a597-4e224237a527"]); }
}

/// <summary>Launch timer with specific name</summary>
/// <param name="key">Unique timer index to identify specific instance of launched timer</param>
/// <param name="timerName">Timer name that is used to set specific timer settings. If timer with that name is not found then Default timer settings will be used</param>
/// <param name="callback">Callback that will be called when timer is triggered</param>
/// <param name="state">Data that will be transferred to callback menthow when timer is triggered</param>
public void RegisterTimer(String key, String timerName, EventHandler<EventArgs> callback, Object state)
{
	IPluginDescription pluginTimer = this.PluginInstance;
	if(pluginTimer == null)
		throw new ArgumentNullException("Plugin ID=69c79417-c168-434a-a597-4e224237a527 not installed");

	pluginTimer.Type.GetMember<IPluginMethodInfo>("RegisterTimer")
		.Invoke(key, timerName, callback, state);
}

/// <summary>Stop timer by sending unique index of started timer</summary>
/// <param name="key">Unique timer index to identify specific instance of launched timer</param>
/// <returns>Timer successfully unregistered</returns>
public Boolean UnregisterTimer(String key)
{
	IPluginDescription pluginTimer = this.PluginInstance;
	if(pluginTimer == null)
		throw new ArgumentNullException("Plugin ID=69c79417-c168-434a-a597-4e224237a527 not installed");

	return (Boolean)pluginTimer.Type.GetMember<IPluginMethodInfo>("UnregisterTimer")
		.Invoke(key);
}

/// <summary>Invoke timer by unique timer index</summary>
/// <param name="key">Unique timer index that need to be invoked</param>
public void InvokeTimer(String key)
{
	IPluginDescription pluginTimer = this.PluginInstance;
	if(pluginTimer == null)
		throw new ArgumentNullException("Plugin ID=69c79417-c168-434a-a597-4e224237a527 not installed");

	pluginTimer.Type.GetMember<IPluginMethodInfo>("InvokeTimer")
		.Invoke(key);
}

/// <summary>Get all launched timer names</summary>
/// <returns>Name of all created timers</returns>
public String[] GetTimersName()
{
	IPluginDescription pluginTimer = this.PluginInstance;
	if(pluginTimer == null)
		return null;

	return (String[])pluginTimer.Type.GetMember<IPluginMethodInfo>("GetTimersName")
		.Invoke();
}

/// <summary>Search for timer by specified timer name</summary>
/// <param name="timerName">Timer name that we trying to find in launched timers</param>
/// <returns>Timer with this name exists and launched</returns>
public Boolean IsTimerExists(String timerName)
{
	IPluginDescription pluginTimer = this.PluginInstance;
	if(pluginTimer == null)
		return false;

	return (Boolean)pluginTimer.Type.GetMember<IPluginMethodInfo>("IsTimerExists")
		.Invoke(timerName);
}
Теги:

Скачать

Ссылки

Родительские файлы

Дочерние файлы