fixed bugs Scheduler Service

This commit is contained in:
vfedosevich 2013-05-24 15:46:10 +03:00
parent d14b5fc01f
commit 20f4b371d1
30 changed files with 332 additions and 190 deletions

View file

@ -1845,29 +1845,46 @@ namespace WebsitePanel.EnterpriseServer
new SqlParameter("@taskId", taskId));
}
public static IDataReader GetScheduleBackgroundTasks(int actorId, int scheduleId)
{
return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
ObjectQualifier + "GetScheduleBackgroundTasks",
new SqlParameter("@actorId", actorId),
new SqlParameter("@scheduleId", scheduleId));
}
public static IDataReader GetBackgroundTasks(int actorId)
{
return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
ObjectQualifier + "GetBackgroundTasks",
new SqlParameter("actorId", actorId));
new SqlParameter("@actorId", actorId));
}
public static IDataReader GetBackgroundTasks(int actorId, Guid guid)
{
return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
ObjectQualifier + "GetThreadBackgroundTasks",
new SqlParameter("@actorId", actorId),
new SqlParameter("@guid", guid));
}
public static IDataReader GetProcessBackgroundTasks(int actorId, BackgroundTaskStatus status)
{
return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
ObjectQualifier + "GetProcessBackgroundTasks",
new SqlParameter("actorId", actorId),
new SqlParameter("status", (int)status));
new SqlParameter("@actorId", actorId),
new SqlParameter("@status", (int)status));
}
public static IDataReader GetBackgroundTopTask(int actorId)
public static IDataReader GetBackgroundTopTask(int actorId, Guid guid)
{
return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
ObjectQualifier + "GetBackGroundTopTask",
new SqlParameter("actorId", actorId));
new SqlParameter("@actorId", actorId),
new SqlParameter("@guid", guid));
}
public static int AddBackgroundTask(string taskId, int scheduleId, int packageId, int userId,
public static int AddBackgroundTask(Guid guid, string taskId, int scheduleId, int packageId, int userId,
int effectiveUserId, string taskName, int itemId, string itemName, DateTime startDate,
int indicatorCurrent, int indicatorMaximum, int maximumExecutionTime, string source,
int severity, bool completed, bool notifyOnComplete, BackgroundTaskStatus status)
@ -1878,6 +1895,7 @@ namespace WebsitePanel.EnterpriseServer
SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
ObjectQualifier + "AddBackgroundTask",
prmId,
new SqlParameter("@guid", guid),
new SqlParameter("@taskId", taskId),
new SqlParameter("@scheduleId", scheduleId),
new SqlParameter("@packageId", packageId),
@ -1923,12 +1941,13 @@ namespace WebsitePanel.EnterpriseServer
new SqlParameter("@startLogTime", startLogTime));
}
public static void UpdateBackgroundTask(int taskId, int scheduleId, int packageId, string taskName, int itemId,
public static void UpdateBackgroundTask(Guid guid, int taskId, int scheduleId, int packageId, string taskName, int itemId,
string itemName, DateTime finishDate, int indicatorCurrent, int indicatorMaximum, int maximumExecutionTime,
string source, int severity, bool completed, bool notifyOnComplete, BackgroundTaskStatus status)
{
SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
ObjectQualifier + "UpdateBackgroundTask",
new SqlParameter("@Guid", guid),
new SqlParameter("@taskId", taskId),
new SqlParameter("@scheduleId", scheduleId),
new SqlParameter("@packageId", packageId),
@ -2002,13 +2021,6 @@ namespace WebsitePanel.EnterpriseServer
new SqlParameter("@taskId", taskId));
}
public static IDataReader GetRunningSchedules(int actorId)
{
return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
ObjectQualifier + "GetRunningSchedules",
new SqlParameter("@actorId", actorId));
}
public static DataSet GetSchedules(int actorId, int packageId)
{
return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
@ -2107,7 +2119,7 @@ namespace WebsitePanel.EnterpriseServer
public static void UpdateSchedule(int actorId, int scheduleId, string taskId,
string scheduleName, string scheduleTypeId, int interval,
DateTime fromTime, DateTime toTime, DateTime startTime,
DateTime lastRun, DateTime lastFinish, DateTime nextRun, bool enabled, string priorityId,
DateTime lastRun, DateTime nextRun, bool enabled, string priorityId,
int historiesNumber, int maxExecutionTime, int weekMonthDay, string xmlParameters)
{
SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure,
@ -2122,7 +2134,6 @@ namespace WebsitePanel.EnterpriseServer
new SqlParameter("@toTime", toTime),
new SqlParameter("@startTime", startTime),
new SqlParameter("@lastRun", (lastRun == DateTime.MinValue) ? DBNull.Value : (object)lastRun),
new SqlParameter("@lastFinish", (lastFinish == DateTime.MinValue) ? DBNull.Value : (object)lastFinish),
new SqlParameter("@nextRun", nextRun),
new SqlParameter("@enabled", enabled),
new SqlParameter("@priorityId", priorityId),

View file

@ -45,7 +45,7 @@ namespace WebsitePanel.Ecommerce.EnterpriseServer.TaskEventHandlers
/// </summary>
public override void OnComplete()
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
if (!TaskManager.HasErrors(topTask))
{
@ -74,7 +74,7 @@ namespace WebsitePanel.Ecommerce.EnterpriseServer.TaskEventHandlers
// send an e-mail notification
try
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
bool sendNotification = Utils.ParseBool(topTask.GetParamValue(SystemTaskParams.PARAM_SEND_EMAIL), false);
@ -117,7 +117,7 @@ namespace WebsitePanel.Ecommerce.EnterpriseServer.TaskEventHandlers
//
try
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
// Read task parameters
Invoice invoice = (Invoice)topTask.GetParamValue(SystemTaskParams.PARAM_INVOICE);
@ -146,7 +146,7 @@ namespace WebsitePanel.Ecommerce.EnterpriseServer.TaskEventHandlers
//
try
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
// Read task parameters
Contract contract = (Contract)topTask.GetParamValue(SystemTaskParams.PARAM_CONTRACT);

View file

@ -44,7 +44,7 @@ namespace WebsitePanel.Ecommerce.EnterpriseServer.TaskEventHandlers
public override void OnComplete()
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
if (!TaskManager.HasErrors(topTask))
{
@ -66,10 +66,8 @@ namespace WebsitePanel.Ecommerce.EnterpriseServer.TaskEventHandlers
private void RegisterInvoiceActivationTrigger()
{
BackgroundTask topTask = TaskController.GetTopTask();
// Read contract invoice
Invoice invoice = (Invoice)topTask.GetParamValue(SystemTaskParams.PARAM_INVOICE);
Invoice invoice = (Invoice)TaskManager.TopTask.GetParamValue(SystemTaskParams.PARAM_INVOICE);
//
TriggerSystem.TriggerController.AddSystemTrigger(invoice.InvoiceId.ToString(),
ActivateInvoiceTrigger.STATUS_AWAITING_PAYMENT, typeof(ActivateInvoiceTrigger));
@ -77,7 +75,7 @@ namespace WebsitePanel.Ecommerce.EnterpriseServer.TaskEventHandlers
private void RegisterContractActivationTrigger()
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
// Ensure the contract has been registered successfully
if (topTask.ContainsParam(SystemTaskParams.PARAM_CONTRACT))
@ -94,7 +92,7 @@ namespace WebsitePanel.Ecommerce.EnterpriseServer.TaskEventHandlers
private void ActivatePaymentSystemTriggers()
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
CustomerPayment payment = (CustomerPayment)topTask.GetParamValue(SystemTaskParams.PARAM_PAYMENT);
Contract contract = (Contract)topTask.GetParamValue(SystemTaskParams.PARAM_CONTRACT);

View file

@ -617,7 +617,7 @@ namespace WebsitePanel.EnterpriseServer
}
}
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
topTask.ItemId = userId;
topTask.UpdateParamValue("SendLetter", sendLetter);
@ -722,7 +722,7 @@ namespace WebsitePanel.EnterpriseServer
if (homeId < 0)
result.Result = homeId;
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
topTask.ItemId = userId;
topTask.UpdateParamValue("Signup", signup);

View file

@ -342,7 +342,8 @@ namespace WebsitePanel.EnterpriseServer
}
}
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
topTask.IndicatorCurrent = topTask.IndicatorMaximum;
TaskController.UpdateTask(topTask);

View file

@ -46,7 +46,7 @@ namespace WebsitePanel.EnterpriseServer
// - BACKUP_NAME
// - ZIP_BACKUP
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
string databaseGroup = (string)topTask.GetParamValue("DATABASE_GROUP");
string databaseName = (string)topTask.GetParamValue("DATABASE_NAME");

View file

@ -54,7 +54,7 @@ namespace WebsitePanel.EnterpriseServer
string storeServerFolder;
bool deleteTempBackup;
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
try
{

View file

@ -45,10 +45,8 @@ namespace WebsitePanel.EnterpriseServer
public void CalculateDiskspace()
{
BackgroundTask topTask = TaskController.GetTopTask();
// get all space organizations recursively
List<Organization> items = ExchangeServerController.GetExchangeOrganizations(topTask.PackageId, true);
List<Organization> items = ExchangeServerController.GetExchangeOrganizations(TaskManager.TopTask.PackageId, true);
foreach (Organization item in items)
{

View file

@ -50,10 +50,8 @@ namespace WebsitePanel.EnterpriseServer
public void CalculateBandwidth()
{
BackgroundTask topTask = TaskController.GetTopTask();
// get all owned packages
List<PackageInfo> packages = PackageController.GetPackagePackages(topTask.PackageId, true);
List<PackageInfo> packages = PackageController.GetPackagePackages(TaskManager.TopTask.PackageId, true);
TaskManager.Write("Packages to calculate: " + packages.Count.ToString());
foreach (PackageInfo package in packages)

View file

@ -51,10 +51,8 @@ namespace WebsitePanel.EnterpriseServer
public void CalculateDiskspace()
{
BackgroundTask topTask = TaskController.GetTopTask();
// get all owned packages
List<PackageInfo> packages = PackageController.GetPackagePackages(topTask.PackageId, true);
List<PackageInfo> packages = PackageController.GetPackagePackages(TaskManager.TopTask.PackageId, true);
TaskManager.Write("Packages to calculate: " + packages.Count.ToString());
foreach (PackageInfo package in packages)

View file

@ -57,7 +57,7 @@ namespace WebsitePanel.EnterpriseServer
// - MAIL_SUBJECT
// - MAIL_BODY
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
// get input parameters
string url = (string)topTask.GetParamValue("URL");
@ -128,7 +128,7 @@ namespace WebsitePanel.EnterpriseServer
private void SendMailMessage(string url, string message, string content)
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
// input parameters
string mailFrom = (string)topTask.GetParamValue("MAIL_FROM");

View file

@ -46,7 +46,7 @@ namespace WebsitePanel.EnterpriseServer
// - FTP_PASSWORD
// - FTP_FOLDER
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
// get input parameters
string filePath = (string)topTask.GetParamValue("FILE_PATH");

View file

@ -51,7 +51,7 @@ namespace WebsitePanel.EnterpriseServer
{
try
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
bool isExchange = Utils.ParseBool(topTask.GetParamValue(EXCHANGE_REPORT), false);
bool isSharePoint = Utils.ParseBool(topTask.GetParamValue(SHAREPOINT_REPORT), false);

View file

@ -44,7 +44,7 @@ namespace WebsitePanel.EnterpriseServer
// - DISKSPACE_OVERUSED
// - BANDWIDTH_OVERUSED
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
// get the list of all packages
List<PackageInfo> packages = PackageController.GetPackagePackages(topTask.PackageId, false);

View file

@ -42,7 +42,7 @@ namespace WebsitePanel.EnterpriseServer
// - SERVER_NAME
// - EXECUTABLE_PATH
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
// get input parameters
string serverName = (string)topTask.GetParamValue("SERVER_NAME");

View file

@ -42,7 +42,7 @@ namespace WebsitePanel.EnterpriseServer
// - MAIL_SUBJECT
// - MAIL_BODY
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
// get input parameters
string mailFrom = (string)topTask.GetParamValue("MAIL_FROM");

View file

@ -43,7 +43,7 @@ namespace WebsitePanel.EnterpriseServer
// - DISKSPACE_OVERUSED
// - BANDWIDTH_OVERUSED
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
// get the list of all packages
List<PackageInfo> packages = PackageController.GetPackagePackages(topTask.PackageId, false);

View file

@ -40,7 +40,7 @@ namespace WebsitePanel.EnterpriseServer
// - FOLDER
// - ZIP_FILE
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
// get input parameters
string filesList = (string)topTask.GetParamValue("FOLDER");

View file

@ -115,22 +115,15 @@ namespace WebsitePanel.EnterpriseServer
var tasks = TaskController.GetProcessTasks(BackgroundTaskStatus.Starting);
foreach (var task in tasks)
{
StartManualTask(task);
new Thread(() => RunBackgroundTask(task)) {Priority = ThreadPriority.Highest}.Start();
}
tasks = TaskController.GetProcessTasks(BackgroundTaskStatus.Stopping);
foreach (var task in tasks)
{
TaskManager.StopTask(task.TaskId);
TaskManager.StopTask(task);
}
}
private static void StartManualTask(BackgroundTask backgroundTask)
{
new Thread(() => RunBackgroundTask(backgroundTask)) { Priority = ThreadPriority.Highest }.Start();
backgroundTask.Status = BackgroundTaskStatus.Run;
TaskController.UpdateTask(backgroundTask);
}
private static void RunBackgroundTask(BackgroundTask backgroundTask)
{
UserInfo user = PackageController.GetPackageOwner(backgroundTask.PackageId);
@ -138,13 +131,18 @@ namespace WebsitePanel.EnterpriseServer
SecurityContext.SetThreadPrincipal(user.UserId);
var schedule = SchedulerController.GetScheduleComplete(backgroundTask.ScheduleId);
TaskManager.StartTask(backgroundTask.Source, backgroundTask.TaskName, backgroundTask.ItemName, backgroundTask.ItemId, backgroundTask.ScheduleId, backgroundTask.PackageId, backgroundTask.MaximumExecutionTime, backgroundTask.Params);
backgroundTask.Guid = TaskManager.Guid;
backgroundTask.Status = BackgroundTaskStatus.Run;
TaskController.UpdateTask(backgroundTask);
try
{
var objTask = (SchedulerTask)Activator.CreateInstance(Type.GetType(schedule.Task.TaskType));
objTask.DoWork();
Thread.Sleep(100000);
}
catch (Exception ex)

View file

@ -55,12 +55,6 @@ namespace WebsitePanel.EnterpriseServer
DataProvider.GetScheduleTask(SecurityContext.User.UserId, taskId));
}
public static List<ScheduleInfo> GetRunningSchedules()
{
return ObjectUtils.CreateListFromDataReader<ScheduleInfo>(
DataProvider.GetRunningSchedules(SecurityContext.User.UserId));
}
public static DataSet GetSchedules(int packageId)
{
DataSet ds = DataProvider.GetSchedules(SecurityContext.User.UserId, packageId);
@ -170,6 +164,7 @@ namespace WebsitePanel.EnterpriseServer
prm => new BackgroundTaskParameter(prm.ParameterId, prm.ParameterValue)).ToList();
var backgroundTask = new BackgroundTask(
Guid.NewGuid(),
schedule.ScheduleInfo.TaskId,
SecurityContext.User.UserId,
SecurityContext.User.IsPeer
@ -197,22 +192,12 @@ namespace WebsitePanel.EnterpriseServer
if (schedule == null)
return 0;
var parameters = schedule.ScheduleInfo.Parameters.Select(
prm => new BackgroundTaskParameter(prm.ParameterId, prm.ParameterValue)).ToList();
var backgroundTask = new BackgroundTask(
schedule.ScheduleInfo.TaskId,
SecurityContext.User.UserId,
SecurityContext.User.IsPeer
? SecurityContext.User.OwnerId
: SecurityContext.User.UserId, "SCHEDULER", "STOP_SCHEDULE",
schedule.ScheduleInfo.ScheduleName,
schedule.ScheduleInfo.ScheduleId,
schedule.ScheduleInfo.ScheduleId,
schedule.ScheduleInfo.PackageId,
schedule.ScheduleInfo.MaxExecutionTime, parameters) { Status = BackgroundTaskStatus.Stopping };
TaskController.AddTask(backgroundTask);
foreach (BackgroundTask task in TaskController.GetScheduleTasks(scheduleId))
{
task.Status = BackgroundTaskStatus.Stopping;
TaskController.UpdateTask(task);
}
return 0;
@ -338,7 +323,7 @@ namespace WebsitePanel.EnterpriseServer
DataProvider.UpdateSchedule(SecurityContext.User.UserId,
schedule.ScheduleId, schedule.TaskId, schedule.ScheduleName, schedule.ScheduleTypeId,
schedule.Interval, schedule.FromTime, schedule.ToTime, schedule.StartTime,
schedule.LastRun, schedule.LastFinish, schedule.NextRun, schedule.Enabled, schedule.PriorityId,
schedule.LastRun, schedule.NextRun, schedule.Enabled, schedule.PriorityId,
schedule.HistoriesNumber, schedule.MaxExecutionTime, schedule.WeekMonthDay, xmlParameters);
// re-schedule tasks

View file

@ -40,7 +40,7 @@ namespace WebsitePanel.EnterpriseServer.Tasks
public override void OnComplete()
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
if (!TaskManager.HasErrors(topTask))
{
@ -78,7 +78,7 @@ namespace WebsitePanel.EnterpriseServer.Tasks
{
try
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
bool sendLetter = Utils.ParseBool(topTask.GetParamValue("SendLetter"), false);
@ -98,7 +98,7 @@ namespace WebsitePanel.EnterpriseServer.Tasks
{
try
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
int userId = Utils.ParseInt(topTask.GetParamValue("UserId").ToString(), 0);
bool sendLetter = Utils.ParseBool(topTask.GetParamValue("SendLetter"), false);
@ -125,7 +125,7 @@ namespace WebsitePanel.EnterpriseServer.Tasks
{
try
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
bool sendLetter = Utils.ParseBool(topTask.GetParamValue("SendLetter"), false);

View file

@ -15,32 +15,39 @@ namespace WebsitePanel.EnterpriseServer
BackgroundTask task = ObjectUtils.FillObjectFromDataReader<BackgroundTask>(
DataProvider.GetBackgroundTask(SecurityContext.User.UserId, taskId));
if (task == null)
{
return null;
}
task.Params = GetTaskParams(task.Id);
return task;
}
public static List<BackgroundTask> GetScheduleTasks(int scheduleId)
{
return ObjectUtils.CreateListFromDataReader<BackgroundTask>(
DataProvider.GetScheduleBackgroundTasks(SecurityContext.User.UserId, scheduleId));
}
public static List<BackgroundTask> GetTasks()
{
return ObjectUtils.CreateListFromDataReader<BackgroundTask>(
DataProvider.GetBackgroundTasks(SecurityContext.User.UserId));
}
public static List<BackgroundTask> GetTasks(Guid guid)
{
return ObjectUtils.CreateListFromDataReader<BackgroundTask>(
DataProvider.GetBackgroundTasks(SecurityContext.User.UserId, guid));
}
public static List<BackgroundTask> GetProcessTasks(BackgroundTaskStatus status)
{
return ObjectUtils.CreateListFromDataReader<BackgroundTask>(
DataProvider.GetProcessBackgroundTasks(SecurityContext.User.UserId, status));
}
public static BackgroundTask GetTopTask()
public static BackgroundTask GetTopTask(Guid guid)
{
BackgroundTask task = ObjectUtils.FillObjectFromDataReader<BackgroundTask>(
DataProvider.GetBackgroundTopTask(SecurityContext.User.UserId));
DataProvider.GetBackgroundTopTask(SecurityContext.User.UserId, guid));
task.Params = GetTaskParams(task.Id);
@ -49,7 +56,7 @@ namespace WebsitePanel.EnterpriseServer
public static void AddTask(BackgroundTask task)
{
int taskId = DataProvider.AddBackgroundTask(task.TaskId, task.ScheduleId, task.PackageId, task.UserId,
int taskId = DataProvider.AddBackgroundTask(task.Guid, task.TaskId, task.ScheduleId, task.PackageId, task.UserId,
task.EffectiveUserId, task.TaskName, task.ItemId, task.ItemName,
task.StartDate, task.IndicatorCurrent, task.IndicatorMaximum,
task.MaximumExecutionTime, task.Source, task.Severity, task.Completed,
@ -62,14 +69,14 @@ namespace WebsitePanel.EnterpriseServer
public static void UpdateTask(BackgroundTask task)
{
DataProvider.UpdateBackgroundTask(task.Id, task.ScheduleId, task.PackageId, task.TaskName, task.ItemId,
DataProvider.UpdateBackgroundTask(task.Guid, task.Id, task.ScheduleId, task.PackageId, task.TaskName, task.ItemId,
task.ItemName, task.FinishDate, task.IndicatorCurrent,
task.IndicatorMaximum, task.MaximumExecutionTime, task.Source,
task.Severity, task.Completed, task.NotifyOnComplete, task.Status);
AddTaskParams(task.Id, task.Params);
if (task.Completed || task.Status == BackgroundTaskStatus.Abort)
if (task.Completed || task.Status == BackgroundTaskStatus.Abort || task.Status == BackgroundTaskStatus.Stopping)
{
DeleteTaskStack(task.Id);
}
@ -82,6 +89,11 @@ namespace WebsitePanel.EnterpriseServer
public static void AddTaskParams(int taskId, List<BackgroundTaskParameter> parameters)
{
if (parameters == null)
{
return;
}
foreach (BackgroundTaskParameter param in SerializeParams(parameters))
{
DataProvider.AddBackgroundTaskParam(taskId, param.Name, param.SerializerValue);
@ -117,14 +129,11 @@ namespace WebsitePanel.EnterpriseServer
private static List<BackgroundTaskParameter> SerializeParams(List<BackgroundTaskParameter> parameters)
{
if (parameters == null)
{
return new List<BackgroundTaskParameter>();
}
foreach (BackgroundTaskParameter param in parameters)
{
XmlSerializer serializer = new XmlSerializer(param.Value.GetType());
param.TypeName = param.Value.GetType().Name;
XmlSerializer serializer = new XmlSerializer(Type.GetType(param.TypeName));
MemoryStream ms = new MemoryStream();
serializer.Serialize(ms, param.Value);
@ -141,7 +150,7 @@ namespace WebsitePanel.EnterpriseServer
{
foreach (BackgroundTaskParameter param in parameters)
{
XmlSerializer deserializer = new XmlSerializer(param.SerializerValue.GetType());
XmlSerializer deserializer = new XmlSerializer(Type.GetType(param.TypeName));
StringReader sr = new StringReader(param.SerializerValue);
param.Value = deserializer.Deserialize(sr);

View file

@ -52,6 +52,20 @@ namespace WebsitePanel.EnterpriseServer
60000, // start from 1 minute
60000); // invoke each minute
protected static Guid? _Guid;
public static Guid Guid
{
get
{
if (_Guid == null)
{
_Guid = Guid.NewGuid();
}
return _Guid.Value;
}
}
public static void StartTask(string source, string taskName)
{
@ -142,10 +156,10 @@ namespace WebsitePanel.EnterpriseServer
int effectiveUserId = SecurityContext.User.IsPeer ? SecurityContext.User.OwnerId : userId;
String itemNameStr = itemName != null ? itemName.ToString() : String.Empty;
BackgroundTask task = new BackgroundTask(taskId, userId, effectiveUserId, source, taskName, itemNameStr,
BackgroundTask task = new BackgroundTask(Guid, taskId, userId, effectiveUserId, source, taskName, itemNameStr,
itemId, scheduleId, packageId, maximumExecutionTime, parameters);
List<BackgroundTask> tasks = TaskController.GetTasks();
List<BackgroundTask> tasks = TaskController.GetTasks(Guid);
if (tasks.Count > 0)
{
@ -191,10 +205,10 @@ namespace WebsitePanel.EnterpriseServer
// ERROR
WriteLogRecord(2, ex.Message, ex.StackTrace);
BackgroundTask topTask = TaskController.GetTopTask();
return new Exception((topTask != null) ? String.Format("Error executing '{0}' task on '{1}' {2}",
topTask.TaskName, topTask.ItemName, topTask.Source) : String.Format("Error executing task"), ex);
return new Exception((TopTask != null)
? String.Format("Error executing '{0}' task on '{1}' {2}",
TopTask.TaskName, TopTask.ItemName, TopTask.Source)
: String.Format("Error executing task"), ex);
}
public static void WriteError(Exception ex, string text, params string[] textParameters)
@ -219,7 +233,7 @@ namespace WebsitePanel.EnterpriseServer
private static void WriteLogRecord(int severity, string text, string stackTrace, params string[] textParameters)
{
List<BackgroundTask> tasks = TaskController.GetTasks();
List<BackgroundTask> tasks = TaskController.GetTasks(Guid);
if (tasks.Count > 0)
{
@ -246,12 +260,12 @@ namespace WebsitePanel.EnterpriseServer
public static void CompleteTask()
{
List<BackgroundTask> tasks = TaskController.GetTasks();
List<BackgroundTask> tasks = TaskController.GetTasks(Guid);
if (tasks.Count == 0)
return;
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = tasks[tasks.Count - 1];
// call event handler
CallTaskEventHandler(topTask, true);
@ -284,7 +298,7 @@ namespace WebsitePanel.EnterpriseServer
public static void UpdateParam(String name, Object value)
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TopTask;
if (topTask == null)
return;
@ -298,7 +312,7 @@ namespace WebsitePanel.EnterpriseServer
{
set
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TopTask;
if (topTask == null)
return;
@ -313,7 +327,7 @@ namespace WebsitePanel.EnterpriseServer
{
set
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TopTask;
if (topTask == null)
return;
@ -326,7 +340,7 @@ namespace WebsitePanel.EnterpriseServer
public static void UpdateParams(Hashtable parameters)
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TopTask;
if (topTask == null)
return;
@ -393,7 +407,7 @@ namespace WebsitePanel.EnterpriseServer
static void PurgeCompletedTasks(object obj)
{
List<BackgroundTask> tasks = TaskController.GetTasks();
List<BackgroundTask> tasks = TaskController.GetTasks(Guid);
foreach (BackgroundTask task in tasks)
{
@ -411,7 +425,13 @@ namespace WebsitePanel.EnterpriseServer
{
set
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TopTask;
if (topTask == null)
{
return;
}
topTask.IndicatorMaximum = value;
TaskController.UpdateTask(topTask);
@ -422,11 +442,17 @@ namespace WebsitePanel.EnterpriseServer
{
get
{
return TaskController.GetTopTask().IndicatorCurrent;
return TopTask.IndicatorCurrent;
}
set
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TopTask;
if (topTask == null)
{
return;
}
topTask.IndicatorCurrent = value;
TaskController.UpdateTask(topTask);
@ -437,11 +463,17 @@ namespace WebsitePanel.EnterpriseServer
{
get
{
return TaskController.GetTopTask().MaximumExecutionTime;
return TopTask.MaximumExecutionTime;
}
set
{
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TopTask;
if (topTask == null)
{
return;
}
topTask.MaximumExecutionTime = value;
TaskController.UpdateTask(topTask);
@ -453,6 +485,11 @@ namespace WebsitePanel.EnterpriseServer
return task.Severity == 2;
}
public static BackgroundTask TopTask
{
get { return TaskController.GetTopTask(Guid); }
}
public static BackgroundTask GetTask(string taskId)
{
BackgroundTask task = TaskController.GetTask(taskId);

View file

@ -448,7 +448,7 @@ namespace WebsitePanel.EnterpriseServer
return BusinessErrorCodes.ERROR_USER_ALREADY_EXISTS;
}
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
topTask.ItemId = userId;
topTask.UpdateParamValue("SendLetter", sendLetter);

View file

@ -1760,7 +1760,7 @@ namespace WebsitePanel.EnterpriseServer
return res;
}
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
topTask.ItemId = machine.Id;
topTask.ItemName = machine.Name;
topTask.PackageId = machine.PackageId;

View file

@ -1803,7 +1803,7 @@ namespace WebsitePanel.EnterpriseServer
return res;
}
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
topTask.ItemId = machine.Id;
topTask.ItemName = machine.Name;
topTask.PackageId = machine.PackageId;

View file

@ -101,7 +101,8 @@ namespace WebsitePanel.EnterpriseServer
// get application info
app = GetApplication(inst.PackageId, inst.ApplicationId);
BackgroundTask topTask = TaskController.GetTopTask();
BackgroundTask topTask = TaskManager.TopTask;
topTask.ItemName = app.Name;
TaskController.UpdateTask(topTask);