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.
184 lines
5.6 KiB
184 lines
5.6 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Threading.Tasks;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using QMTask.Client.TaskService;
|
|
using QMTask.Client.Until;
|
|
|
|
namespace QMTask.Client
|
|
{
|
|
public partial class PlanMonitorForm : Form
|
|
{
|
|
//任务调度服务
|
|
TaskService.TaskServiceClient tsc = ServiceUtil.GetTaskService();
|
|
|
|
//任务列表
|
|
List<TaskInfo> _tasks = null;
|
|
|
|
//计划列表
|
|
List<PlanInfo> _plans = null;
|
|
|
|
/// <summary>
|
|
/// 监控信息
|
|
/// </summary>
|
|
List<MonitorInfo> _monitors = null;
|
|
|
|
//异常计划列表
|
|
Dictionary<string, DateTime> ExceptionPlans = new Dictionary<string, DateTime>();
|
|
|
|
public PlanMonitorForm()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
#region 定时刷新
|
|
|
|
private void timer1_Tick(object sender, EventArgs e)
|
|
{
|
|
_monitors = tsc.GetPlanMonitorInfos().ToList();
|
|
this.BindDisplay();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 窗体载入
|
|
|
|
private void PlanMonitorForm_Load(object sender, EventArgs e)
|
|
{
|
|
this.dataGridView1.AutoGenerateColumns = false;
|
|
_monitors = tsc.GetPlanMonitorInfos().ToList();
|
|
|
|
this.dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = System.Drawing.Color.Black;
|
|
|
|
_tasks = tsc.GetTaskList().ToList();
|
|
|
|
_plans = tsc.GetPlanList().ToList();
|
|
|
|
this.BindDisplay();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 显示监控信息
|
|
|
|
private void BindDisplay()
|
|
{
|
|
dataGridView1.Rows.Clear();
|
|
for (int i = 0; i < _monitors.Count; i++)
|
|
{
|
|
TaskInfo task = _tasks.Find(p => p.TaskID == _monitors[i].TaskID);
|
|
PlanInfo plan = _plans.Find(p => p.PlanID == _monitors[i].PlanID);
|
|
|
|
string periodType = "";
|
|
string intervalType = "";
|
|
|
|
switch (plan.IntervalType)
|
|
{
|
|
case "s":
|
|
intervalType = "秒";
|
|
break;
|
|
case "m":
|
|
intervalType = "分";
|
|
break;
|
|
case "h":
|
|
intervalType = "小时";
|
|
break;
|
|
}
|
|
|
|
switch (plan.PeriodType)
|
|
{
|
|
case "d":
|
|
if (string.IsNullOrEmpty(plan.OnceTime) == false)
|
|
{
|
|
periodType = "每天";
|
|
}
|
|
else
|
|
{
|
|
periodType = "每" + plan.Interval + intervalType;
|
|
}
|
|
break;
|
|
case "w":
|
|
periodType = "每周";
|
|
break;
|
|
case "m":
|
|
if (plan.Period == 1)
|
|
{
|
|
periodType = "每月";
|
|
}
|
|
else
|
|
{
|
|
periodType = "每" + plan.Period.ToString() + "月";
|
|
}
|
|
break;
|
|
}
|
|
|
|
|
|
_monitors[i].ExecuteInterval = periodType;
|
|
dataGridView1.Rows.Add("", _monitors[i].PlanName, _monitors[i].Remark, _monitors[i].ExecuteInterval, _monitors[i].IsUse == true ? "是" : "否", _monitors[i].LastExecuteTime
|
|
, _monitors[i].Running == true ? "执行中" : "空闲");
|
|
if (_monitors[i].IsNormal == true)
|
|
{
|
|
this.dataGridView1.Rows[i].Cells[0].Style.BackColor = System.Drawing.Color.Green;
|
|
this.dataGridView1.Rows[i].Cells[0].ToolTipText = "运行正常";
|
|
|
|
this.SendWarnInfo(plan.PlanName+"在"+_monitors[i].LastExecuteTime.ToString("yyyy年MM月dd日 HH点mm分ss秒时出现异常。")
|
|
,plan.PlanName,_monitors[i].LastExecuteTime);
|
|
}
|
|
else
|
|
{
|
|
this.dataGridView1.Rows[i].Cells[0].Style.BackColor = System.Drawing.Color.Red;
|
|
this.dataGridView1.Rows[i].Cells[0].ToolTipText = "运行异常";
|
|
|
|
//声音报警
|
|
|
|
//邮件报警
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 报警处理
|
|
|
|
private void SendWarnInfo(string info,string planName,DateTime lastExecuteTime)
|
|
{
|
|
if (ServiceUtil.SoundWarn == true)
|
|
{
|
|
//声音报警
|
|
if (ExceptionPlans.ContainsKey(planName) == true)
|
|
{
|
|
if (ExceptionPlans[planName] == lastExecuteTime)
|
|
return;
|
|
|
|
ExceptionPlans[planName] = lastExecuteTime;
|
|
}
|
|
else
|
|
{
|
|
ExceptionPlans.Add(planName, lastExecuteTime);
|
|
}
|
|
new TaskFactory().StartNew(() => { SpeechHelper.OutputWordToSpeech(info); });
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 窗体大小改变
|
|
|
|
private void PlanMonitorForm_Resize(object sender, EventArgs e)
|
|
{
|
|
this.dataGridView1.Height = this.Height - 80;
|
|
}
|
|
|
|
private void PlanMonitorForm_ResizeEnd(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|