replace saving background tasks in DB

This commit is contained in:
vfedosevich 2013-05-23 09:42:55 +03:00
parent 3353de1e5d
commit e7d5bf0c7e
52 changed files with 1423 additions and 1306 deletions

View file

@ -36,162 +36,156 @@ using System.Xml.Serialization;
namespace WebsitePanel.EnterpriseServer
{
public class BackgroundTask
{
private string taskId;
private int userId;
private int packageId;
private int effectiveUserId;
private DateTime startDate = DateTime.MinValue;
private DateTime finishDate = DateTime.MinValue;
private int maximumExecutionTime = -1; // seconds
private string source;
private string taskName;
private int scheduleId;
private string itemName;
private int itemId = 0;
private int severity = 0; /* 0 - Info, 1 - Warning, 2 - Error */
private List<BackgroundTaskLogRecord> logRecords = new List<BackgroundTaskLogRecord>();
private List<BackgroundTaskLogRecord> lastLogRecords = new List<BackgroundTaskLogRecord>();
private BackgroundTaskLogRecord lastLogRecord;
private Hashtable parameters = new Hashtable();
private int indicatorMaximum;
private int indicatorCurrent;
private bool completed;
private bool notifyOnComplete;
private Thread taskThread;
#region Properties
public System.DateTime StartDate
public int Id { get; protected set; }
public String TaskId { get; protected set; }
public int ScheduleId { get; set; }
public int PackageId { get; set; }
public int UserId { get; protected set; }
public int EffectiveUserId { get; protected set; }
public String TaskName { get; protected set; }
public int ItemId { get; set; }
public String ItemName { get; set; }
public DateTime StartDate { get; protected set; }
public DateTime FinishDate { get; set; }
public int IndicatorCurrent { get; set; }
public int IndicatorMaximum { get; set; }
public int MaximumExecutionTime { get; set; }
public String Source { get; protected set; }
public int Severity { get; set; }
public bool Completed { get; set; }
public bool NotifyOnComplete { get; set; }
public BackgroundTaskStatus Status { get; set; }
public IList<BackgroundTaskLogRecord> Logs { get; set; }
public IList<BackgroundTaskParameter> Params { get; set; }
#endregion
#region Constructors
public BackgroundTask()
{
get { return this.startDate; }
set { this.startDate = value; }
StartDate = DateTime.Now;
Severity = 0;
IndicatorCurrent = 0;
IndicatorMaximum = 0;
Status = BackgroundTaskStatus.Run;
Logs = new List<BackgroundTaskLogRecord>();
}
public System.DateTime FinishDate
public BackgroundTask(String taskId, int userId, int effectiveUserId, String source, String taskName, String itemName,
int itemId, int scheduleId, int packageId, int maximumExecutionTime, IList<BackgroundTaskParameter> parameters)
: this()
{
get { return this.finishDate; }
set { this.finishDate = value; }
TaskId = TaskId;
UserId = userId;
EffectiveUserId = effectiveUserId;
Source = source;
TaskName = taskName;
ItemName = itemName;
ItemId = itemId;
ScheduleId = scheduleId;
PackageId = packageId;
MaximumExecutionTime = maximumExecutionTime;
Params = parameters;
}
public string Source
#endregion
#region Methods
public Object GetParamValue(String name)
{
get { return this.source; }
set { this.source = value; }
foreach(BackgroundTaskParameter param in Params)
{
if (param.Name == name)
return param.Value;
}
return null;
}
public string TaskName
public void UpdateParamValue(String name, object value)
{
get { return this.taskName; }
set { this.taskName = value; }
foreach (BackgroundTaskParameter param in Params)
{
if (param.Name == name)
{
param.Value = value;
return;
}
}
Params.Add(new BackgroundTaskParameter(name, value));
}
public int ItemId
public bool ContainsParam(String name)
{
get { return this.itemId; }
set { this.itemId = value; }
foreach (BackgroundTaskParameter param in Params)
{
if (param.Name == name)
return true;
}
return false;
}
public int PackageId
#endregion
}
public class BackgroundTaskParameter
{
#region Properties
public int ParameterId { get; protected set; }
public int TaskId { get; protected set; }
public String Name { get; protected set; }
public Object Value { get; set; }
public String SerializerValue { get; set; }
#endregion
#region Constructors
public BackgroundTaskParameter() { }
public BackgroundTaskParameter(String name, Object value)
{
get { return this.packageId; }
set { this.packageId = value; }
Name = name;
Value = value;
}
public int Severity
{
get { return this.severity; }
set { this.severity = value; }
}
[XmlIgnore]
public List<BackgroundTaskLogRecord> LogRecords
{
get { return this.logRecords; }
set { this.logRecords = value; }
}
public List<BackgroundTaskLogRecord> LastLogRecords
{
get { return this.lastLogRecords; }
}
public string ItemName
{
get { return this.itemName; }
set { this.itemName = value; }
}
public BackgroundTaskLogRecord LastLogRecord
{
get { return this.lastLogRecord; }
set { this.lastLogRecord = value; }
}
public string TaskId
{
get { return this.taskId; }
set { this.taskId = value; }
}
public int UserId
{
get { return this.userId; }
set { this.userId = value; }
}
[XmlIgnore]
public Hashtable Parameters
{
get { return this.parameters; }
}
public int IndicatorMaximum
{
get { return this.indicatorMaximum; }
set { this.indicatorMaximum = value; }
}
public int IndicatorCurrent
{
get { return this.indicatorCurrent; }
set { this.indicatorCurrent = value; }
}
public bool Completed
{
get { return this.completed; }
set { this.completed = value; }
}
public bool NotifyOnComplete
{
get { return this.notifyOnComplete; }
set { this.notifyOnComplete = value; }
}
public int EffectiveUserId
{
get { return this.effectiveUserId; }
set { this.effectiveUserId = value; }
}
[XmlIgnore]
public System.Threading.Thread TaskThread
{
get { return this.taskThread; }
set { this.taskThread = value; }
}
public int ScheduleId
{
get { return this.scheduleId; }
set { this.scheduleId = value; }
}
public int MaximumExecutionTime
{
get { return this.maximumExecutionTime; }
set { this.maximumExecutionTime = value; }
}
#endregion
}
}