You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
284 lines
6.9 KiB
284 lines
6.9 KiB
4 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Runtime.Serialization;
|
||
|
using System.ServiceModel;
|
||
|
using System.Text;
|
||
|
|
||
|
namespace QMTask.Core
|
||
|
{
|
||
|
// 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的类名“TaskService”。
|
||
|
/// <summary>
|
||
|
/// 控制服务
|
||
|
/// </summary>
|
||
|
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
|
||
|
public class TaskService : ITaskService
|
||
|
{
|
||
|
/// <summary>si
|
||
|
/// 任务服务器
|
||
|
/// </summary>
|
||
|
public static TaskServer MyTaskServer { get; set; }
|
||
|
|
||
|
/// <summary>
|
||
|
/// 服务凭据ID
|
||
|
/// </summary>
|
||
|
public static string ServiceCredentialID { get; set; }
|
||
|
|
||
|
/// <summary>
|
||
|
/// 使用凭据ID
|
||
|
/// </summary>
|
||
|
public string UseCredentialID { get; set; }
|
||
|
|
||
|
#region 获取任务列表
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取任务列表
|
||
|
/// </summary>
|
||
|
/// <returns></returns>
|
||
|
public List<TaskInfo> GetTaskList()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
this.IsLogin();
|
||
|
XmlHelper xml = new XmlHelper(Configuration.TaskConfigPath());
|
||
|
List<TaskInfo> listrs = xml.GetData<TaskInfo>("Task/TaskDetail");
|
||
|
return listrs;
|
||
|
}
|
||
|
catch(Exception ex)
|
||
|
{
|
||
|
throw new FaultException(ex.Message);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 计划管理
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取计划列表
|
||
|
/// </summary>
|
||
|
/// <returns></returns>
|
||
|
public List<PlanInfo> GetPlanList()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
this.IsLogin();
|
||
|
return new PlanInfoManage().GetPlanList();
|
||
|
}
|
||
|
catch(Exception ex)
|
||
|
{
|
||
|
throw new FaultException(ex.Message);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取计划Model
|
||
|
/// </summary>
|
||
|
/// <param name="PlanID"></param>
|
||
|
/// <returns></returns>
|
||
|
public PlanInfo GetPlanModel(string PlanID)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
this.IsLogin();
|
||
|
return new PlanInfoManage().GetPlanModel(PlanID);
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw new FaultException(ex.Message);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 添加一条计划信息
|
||
|
/// </summary>
|
||
|
/// <param name="plan"></param>
|
||
|
public bool AddPlan(PlanInfo plan)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
this.IsLogin();
|
||
|
bool r=new PlanInfoManage().AddPlan(plan);
|
||
|
MyTaskServer.AddPlan(plan);
|
||
|
|
||
|
return r;
|
||
|
}
|
||
|
catch(Exception ex)
|
||
|
{
|
||
|
throw new FaultException(ex.Message);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 更新一条计划
|
||
|
/// </summary>
|
||
|
/// <param name="plan"></param>
|
||
|
/// <returns></returns>
|
||
|
public bool UpdatePlan(PlanInfo plan)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
this.IsLogin();
|
||
|
bool r = MyTaskServer.UpdatePlan(plan);
|
||
|
if (r == false)
|
||
|
return r;
|
||
|
|
||
|
r=new PlanInfoManage().UpdatePlan(plan);
|
||
|
return r;
|
||
|
}
|
||
|
catch(Exception ex)
|
||
|
{
|
||
|
throw new FaultException(ex.Message);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 删除计划信息,返回true只说明代码运行成功,并不保证一定有数据被删除。
|
||
|
/// </summary>
|
||
|
/// <param name="PlanID"></param>
|
||
|
/// <returns></returns>
|
||
|
public bool DeletePlan(PlanInfo plan)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
this.IsLogin();
|
||
|
bool r = MyTaskServer.DeletePlan(plan);
|
||
|
|
||
|
if (r == false)
|
||
|
{
|
||
|
return r;
|
||
|
}
|
||
|
r=new PlanInfoManage().DeletePlan(plan.PlanID);
|
||
|
|
||
|
return r;
|
||
|
}
|
||
|
catch(Exception ex)
|
||
|
{
|
||
|
throw new FaultException(ex.Message);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public bool StartPlan(PlanInfo plan)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
this.IsLogin();
|
||
|
|
||
|
plan = new PlanInfoManage().GetPlanModel(plan.PlanID);
|
||
|
plan.IsUse = "true";
|
||
|
|
||
|
bool r = MyTaskServer.StartPlan(plan);
|
||
|
if (r == false)
|
||
|
return r;
|
||
|
|
||
|
r = new PlanInfoManage().UpdatePlan(plan);
|
||
|
return r;
|
||
|
}
|
||
|
catch(Exception ex)
|
||
|
{
|
||
|
throw new FaultException(ex.Message);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public bool StopPlan(PlanInfo plan)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
this.IsLogin();
|
||
|
|
||
|
plan = new PlanInfoManage().GetPlanModel(plan.PlanID);
|
||
|
plan.IsUse = "false";
|
||
|
|
||
|
bool r = MyTaskServer.StopPlan(plan);
|
||
|
if (r == false)
|
||
|
return r;
|
||
|
|
||
|
r = new PlanInfoManage().UpdatePlan(plan);
|
||
|
return r;
|
||
|
}
|
||
|
catch(Exception ex)
|
||
|
{
|
||
|
throw new FaultException(ex.Message);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 控制
|
||
|
|
||
|
public bool GetServerStatus()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
this.IsLogin();
|
||
|
return MyTaskServer.Running;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw new FaultException(ex.Message);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void Start()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
this.IsLogin();
|
||
|
MyTaskServer.Start();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw new FaultException(ex.Message);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void Stop()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
this.IsLogin();
|
||
|
MyTaskServer.Stop();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw new FaultException(ex.Message);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public List<MonitorInfo> GetPlanMonitorInfos()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
this.IsLogin();
|
||
|
return MyTaskServer.GetPlanMonitorInfos();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw new FaultException(ex.Message);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 登录
|
||
|
|
||
|
public void Login(string credentialID)
|
||
|
{
|
||
|
this.UseCredentialID = credentialID;
|
||
|
}
|
||
|
|
||
|
private void IsLogin()
|
||
|
{
|
||
|
if (this.UseCredentialID != ServiceCredentialID)
|
||
|
{
|
||
|
throw new Exception("未授权。");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
}
|
||
|
}
|