using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; namespace QMTask.Core { // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的类名“TaskService”。 /// /// 控制服务 /// [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)] public class TaskService : ITaskService { /// si /// 任务服务器 /// public static TaskServer MyTaskServer { get; set; } /// /// 服务凭据ID /// public static string ServiceCredentialID { get; set; } /// /// 使用凭据ID /// public string UseCredentialID { get; set; } #region 获取任务列表 /// /// 获取任务列表 /// /// public List GetTaskList() { try { this.IsLogin(); XmlHelper xml = new XmlHelper(Configuration.TaskConfigPath()); List listrs = xml.GetData("Task/TaskDetail"); return listrs; } catch(Exception ex) { throw new FaultException(ex.Message); } } #endregion #region 计划管理 /// /// 获取计划列表 /// /// public List GetPlanList() { try { this.IsLogin(); return new PlanInfoManage().GetPlanList(); } catch(Exception ex) { throw new FaultException(ex.Message); } } /// /// 获取计划Model /// /// /// public PlanInfo GetPlanModel(string PlanID) { try { this.IsLogin(); return new PlanInfoManage().GetPlanModel(PlanID); } catch (Exception ex) { throw new FaultException(ex.Message); } } /// /// 添加一条计划信息 /// /// 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); } } /// /// 更新一条计划 /// /// /// 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); } } /// /// 删除计划信息,返回true只说明代码运行成功,并不保证一定有数据被删除。 /// /// /// 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 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 } }