update start/stop task from windows service
This commit is contained in:
parent
8577c73c4c
commit
d14b5fc01f
16 changed files with 240 additions and 93 deletions
|
@ -15,6 +15,11 @@ 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;
|
||||
|
@ -26,6 +31,12 @@ namespace WebsitePanel.EnterpriseServer
|
|||
DataProvider.GetBackgroundTasks(SecurityContext.User.UserId));
|
||||
}
|
||||
|
||||
public static List<BackgroundTask> GetProcessTasks(BackgroundTaskStatus status)
|
||||
{
|
||||
return ObjectUtils.CreateListFromDataReader<BackgroundTask>(
|
||||
DataProvider.GetProcessBackgroundTasks(SecurityContext.User.UserId, status));
|
||||
}
|
||||
|
||||
public static BackgroundTask GetTopTask()
|
||||
{
|
||||
BackgroundTask task = ObjectUtils.FillObjectFromDataReader<BackgroundTask>(
|
||||
|
@ -58,7 +69,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
AddTaskParams(task.Id, task.Params);
|
||||
|
||||
if (task.Completed)
|
||||
if (task.Completed || task.Status == BackgroundTaskStatus.Abort)
|
||||
{
|
||||
DeleteTaskStack(task.Id);
|
||||
}
|
||||
|
@ -66,10 +77,10 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
public static void DeleteTaskStack(int taskId)
|
||||
{
|
||||
DataProvider.DeleteBackgroundTaskParams(taskId);
|
||||
DataProvider.DeleteBackgroundTaskStack(taskId);
|
||||
}
|
||||
|
||||
public static void AddTaskParams(int taskId, IList<BackgroundTaskParameter> parameters)
|
||||
public static void AddTaskParams(int taskId, List<BackgroundTaskParameter> parameters)
|
||||
{
|
||||
foreach (BackgroundTaskParameter param in SerializeParams(parameters))
|
||||
{
|
||||
|
@ -77,7 +88,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
}
|
||||
}
|
||||
|
||||
public static IList<BackgroundTaskParameter> GetTaskParams(int taskId)
|
||||
public static List<BackgroundTaskParameter> GetTaskParams(int taskId)
|
||||
{
|
||||
List<BackgroundTaskParameter> parameters = ObjectUtils.CreateListFromDataReader<BackgroundTaskParameter>(
|
||||
DataProvider.GetBackgroundTaskParams(taskId));
|
||||
|
@ -104,8 +115,13 @@ namespace WebsitePanel.EnterpriseServer
|
|||
return logs;
|
||||
}
|
||||
|
||||
private static IList<BackgroundTaskParameter> SerializeParams(IList<BackgroundTaskParameter> parameters)
|
||||
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());
|
||||
|
@ -121,11 +137,11 @@ namespace WebsitePanel.EnterpriseServer
|
|||
return parameters;
|
||||
}
|
||||
|
||||
private static IList<BackgroundTaskParameter> DeserializeParams(IList<BackgroundTaskParameter> parameters)
|
||||
private static List<BackgroundTaskParameter> DeserializeParams(List<BackgroundTaskParameter> parameters)
|
||||
{
|
||||
foreach (BackgroundTaskParameter param in parameters)
|
||||
{
|
||||
XmlSerializer deserializer = new XmlSerializer(param.Value.GetType());
|
||||
XmlSerializer deserializer = new XmlSerializer(param.SerializerValue.GetType());
|
||||
StringReader sr = new StringReader(param.SerializerValue);
|
||||
|
||||
param.Value = deserializer.Deserialize(sr);
|
||||
|
|
|
@ -37,6 +37,8 @@ using System.Web.Caching;
|
|||
using System.Xml;
|
||||
using System.Reflection;
|
||||
using WebsitePanel.Providers.Common;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
|
||||
namespace WebsitePanel.EnterpriseServer
|
||||
{
|
||||
|
@ -66,7 +68,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
StartTask(source, taskName, null, itemId, parameter);
|
||||
}
|
||||
|
||||
public static void StartTask(string source, string taskName, int itemId, IList<BackgroundTaskParameter> parameters)
|
||||
public static void StartTask(string source, string taskName, int itemId, List<BackgroundTaskParameter> parameters)
|
||||
{
|
||||
StartTask(source, taskName, null, itemId, parameters);
|
||||
}
|
||||
|
@ -86,7 +88,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
StartTask(source, taskName, itemName, 0, parameter);
|
||||
}
|
||||
|
||||
public static void StartTask(string source, string taskName, object itemName, IList<BackgroundTaskParameter> parameters)
|
||||
public static void StartTask(string source, string taskName, object itemName, List<BackgroundTaskParameter> parameters)
|
||||
{
|
||||
StartTask(source, taskName, itemName, 0, parameters);
|
||||
}
|
||||
|
@ -96,14 +98,14 @@ namespace WebsitePanel.EnterpriseServer
|
|||
StartTask(source, taskName, itemName, itemId, 0, parameter);
|
||||
}
|
||||
|
||||
public static void StartTask(string source, string taskName, object itemName, int itemId, IList<BackgroundTaskParameter> parameters)
|
||||
public static void StartTask(string source, string taskName, object itemName, int itemId, List<BackgroundTaskParameter> parameters)
|
||||
{
|
||||
StartTask(source, taskName, itemName, itemId, 0, 0, -1, parameters);
|
||||
}
|
||||
|
||||
public static void StartTask(string source, string taskName, object itemName, int itemId, int packageId, BackgroundTaskParameter parameter)
|
||||
{
|
||||
IList<BackgroundTaskParameter> parameters = new List<BackgroundTaskParameter>();
|
||||
List<BackgroundTaskParameter> parameters = new List<BackgroundTaskParameter>();
|
||||
if (parameter != null)
|
||||
{
|
||||
parameters.Add(parameter);
|
||||
|
@ -123,13 +125,13 @@ namespace WebsitePanel.EnterpriseServer
|
|||
}
|
||||
|
||||
public static void StartTask(string source, string taskName, object itemName, int itemId,
|
||||
int scheduleId, int packageId, int maximumExecutionTime, IList<BackgroundTaskParameter> parameters)
|
||||
int scheduleId, int packageId, int maximumExecutionTime, List<BackgroundTaskParameter> parameters)
|
||||
{
|
||||
StartTask(null, source, taskName, itemName, itemId, scheduleId, packageId, maximumExecutionTime, new List<BackgroundTaskParameter>());
|
||||
}
|
||||
|
||||
public static void StartTask(string taskId, string source, string taskName, object itemName, int itemId,
|
||||
int scheduleId, int packageId, int maximumExecutionTime, IList<BackgroundTaskParameter> parameters)
|
||||
int scheduleId, int packageId, int maximumExecutionTime, List<BackgroundTaskParameter> parameters)
|
||||
{
|
||||
if (String.IsNullOrEmpty(taskId))
|
||||
{
|
||||
|
@ -507,13 +509,43 @@ namespace WebsitePanel.EnterpriseServer
|
|||
BackgroundTask task = GetTask(taskId);
|
||||
|
||||
if (task == null)
|
||||
{
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
task.Status = BackgroundTaskStatus.Abort;
|
||||
|
||||
StopProcess(task.TaskId);
|
||||
|
||||
TaskController.UpdateTask(task);
|
||||
}
|
||||
|
||||
public static void StopTask(BackgroundTask task)
|
||||
{
|
||||
if (task == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
task.Status = BackgroundTaskStatus.Abort;
|
||||
|
||||
StopProcess(task.TaskId);
|
||||
|
||||
TaskController.UpdateTask(task);
|
||||
}
|
||||
|
||||
private static void StopProcess(string taskId)
|
||||
{
|
||||
var process = Process.GetProcesses().FirstOrDefault(
|
||||
p => p.ProcessName.Equals(taskId, StringComparison.CurrentCultureIgnoreCase));
|
||||
|
||||
if (process != null)
|
||||
{
|
||||
process.Kill();
|
||||
process.WaitForExit(10000);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<BackgroundTask> GetUserTasks(int userId)
|
||||
{
|
||||
List<BackgroundTask> list = new List<BackgroundTask>();
|
||||
|
@ -717,7 +749,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
return res;
|
||||
}
|
||||
|
||||
public static T StartResultTask<T>(string source, string taskName, int itemId, IList<BackgroundTaskParameter> parameters) where T : ResultObject, new()
|
||||
public static T StartResultTask<T>(string source, string taskName, int itemId, List<BackgroundTaskParameter> parameters) where T : ResultObject, new()
|
||||
{
|
||||
StartTask(source, taskName, itemId, parameters);
|
||||
T res = new T();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue