using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Euro.Transfer.Base
{
///
/// 工作项
///
public abstract class ServiceTask : ServiceBase
{
//配置对象
private ServiceConfig mConfigObject;
//下次运行时间
private DateTime mNextTime;
//任务是否在运行中
protected bool mIsRunning;
//初始化客戶端
public static HubTransfer hubClient = new HubTransfer();
///
/// 构造函数
///
public ServiceTask()
{
//变量初始化
this.mNextTime = DateTime.Now;
this.mIsRunning = false;
}
///
/// 配置对象
///
public ServiceConfig ConfigObject
{
get { return this.mConfigObject; }
set { this.mConfigObject = value; }
}
///
/// 开始工作
///
public void StartJob()
{
if (this.mConfigObject != null && this.mNextTime != null)
{
if (this.mConfigObject.Enabled.ToLower() == "true")
{
if (DateTime.Now >= this.mNextTime)
{
if (!this.mIsRunning)
{
this.mNextTime = DateTime.Now.AddSeconds((double)this.mConfigObject.Interval);
this.Start();
}
}
}
}
}
///
/// 停止工作
///
public void StopJob()
{
this.mConfigObject = null;
this.mNextTime = DateTime.Now;
this.mIsRunning = false;
this.Stop();
}
#region 子类必需实现的抽象成员
///
/// 开始工作
///
protected abstract void Start();
///
/// 停止工作
///
protected abstract void Stop();
#endregion
}
}