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
}
}

View file

@ -34,54 +34,54 @@ namespace WebsitePanel.EnterpriseServer
{
public class BackgroundTaskLogRecord
{
private DateTime date = DateTime.Now;
private string text;
private int severity; /* 0 - Info, 1 - Warning, 2 - Error */
private string[] textParameters;
private int textIdent = 0;
private bool innerTaskStart;
private string exceptionStackTrace;
#region Properties
public System.DateTime Date
public int LogId { get; set; }
public int TaskId { get; set; }
public DateTime Date { get; set; }
public String ExceptionStackTrace { get; set; }
public bool InnerTaskStart { get; set; }
public int Severity { get; set; }
public String Text { get; set; }
public int TextIdent { get; set; }
public string[] TextParameters { get; set; }
public string XmlParameters { get; set; }
#endregion
#region Constructors
public BackgroundTaskLogRecord()
{
get { return this.date; }
set { this.date = value; }
Date = DateTime.Now;
}
public string Text
public BackgroundTaskLogRecord(int taskId, int textIdent, bool innerTaskStart, String text, string[] textParameters)
: this()
{
get { return this.text; }
set { this.text = value; }
TaskId = taskId;
TextIdent = textIdent;
Text = text;
InnerTaskStart = innerTaskStart;
TextParameters = textParameters;
}
public int Severity
public BackgroundTaskLogRecord(int taskId, int textIdent, bool innerTaskStart, String text,
String exceptionStackTrace, string[] textParameters)
: this(taskId, textIdent, innerTaskStart, text, textParameters)
{
get { return this.severity; }
set { this.severity = value; }
ExceptionStackTrace = exceptionStackTrace;
}
public string[] TextParameters
{
get { return this.textParameters; }
set { this.textParameters = value; }
}
public int TextIdent
{
get { return this.textIdent; }
set { this.textIdent = value; }
}
public bool InnerTaskStart
{
get { return this.innerTaskStart; }
set { this.innerTaskStart = value; }
}
public string ExceptionStackTrace
{
get { return this.exceptionStackTrace; }
set { this.exceptionStackTrace = value; }
}
#endregion
}
}

View file

@ -0,0 +1,8 @@
namespace WebsitePanel.EnterpriseServer
{
public enum BackgroundTaskStatus
{
Run = 1,
Abort = 2
}
}

View file

@ -156,6 +156,7 @@
<Compile Include="System\SystemSettings.cs" />
<Compile Include="Tasks\BackgroundTask.cs" />
<Compile Include="Tasks\BackgroundTaskLogRecord.cs" />
<Compile Include="Tasks\BackgroundTaskStatus.cs" />
<Compile Include="Users\UserInfo.cs" />
<Compile Include="Users\UserLoginStatus.cs" />
<Compile Include="Users\UsernamePolicy.cs" />