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.
364 lines
14 KiB
364 lines
14 KiB
9 months ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.ComponentModel;
|
||
|
using System.Data;
|
||
|
using System.Drawing;
|
||
|
using System.Linq;
|
||
|
using System.Text;
|
||
|
using System.Threading;
|
||
|
using System.Threading.Tasks;
|
||
|
using System.Windows.Forms;
|
||
|
using Vlc.DotNet.Forms;
|
||
|
|
||
|
namespace CameraErrorCheck
|
||
|
{
|
||
|
public partial class Form1 : Form
|
||
|
{
|
||
|
public Form1()
|
||
|
{
|
||
|
InitializeComponent();
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 线程Task
|
||
|
/// </summary>
|
||
|
Task t = null;
|
||
|
/// <summary>
|
||
|
/// 线程内循环是否继续
|
||
|
/// </summary>
|
||
|
bool bolWhere = true;
|
||
|
/// <summary>
|
||
|
/// 是否播放下一条视频
|
||
|
/// </summary>
|
||
|
bool bolIsNexCamera = false;
|
||
|
/// <summary>
|
||
|
/// 窗体初始化
|
||
|
/// </summary>
|
||
|
/// <param name="sender"></param>
|
||
|
/// <param name="e"></param>
|
||
|
private void Form1_Load(object sender, EventArgs e)
|
||
|
{
|
||
|
t = new Task(() =>
|
||
|
{
|
||
|
while (bolWhere)
|
||
|
{
|
||
|
if (bolIsNexCamera)
|
||
|
{
|
||
|
|
||
|
if (listIndex >= listCamera.Count - 1)
|
||
|
{
|
||
|
listIndex = 0;
|
||
|
AddMsg(System.Environment.NewLine);
|
||
|
AddMsg("一轮播放结束,延迟一段时间后,再次循环");
|
||
|
AddMsg(System.Environment.NewLine);
|
||
|
AddMsg(System.Environment.NewLine);
|
||
|
MyFileLogHelper.WriteFire(new LogInfoMo() { message = System.Environment.NewLine, msgType = EnumLogMsgTypeEnum.Error, path = "Info" });
|
||
|
MyFileLogHelper.WriteFire(new LogInfoMo() { message = System.Environment.NewLine, msgType = EnumLogMsgTypeEnum.Error, path = "Info" });
|
||
|
MyFileLogHelper.WriteFire(new LogInfoMo() { message = "***************************************", msgType = EnumLogMsgTypeEnum.Error, path = "Info" });
|
||
|
MyFileLogHelper.WriteFire(new LogInfoMo() { message = "一轮播放结束,延迟一段时间后,再次循环", msgType = EnumLogMsgTypeEnum.Error, path = "Info" });
|
||
|
Thread.Sleep(1000 * 60 * 60 * 2);
|
||
|
MyFileLogHelper.WriteFire(new LogInfoMo() { message = "延迟结束,再次循环", msgType = EnumLogMsgTypeEnum.Error, path = "Info" });
|
||
|
MyFileLogHelper.WriteFire(new LogInfoMo() { message = "一轮播放结束,延迟一段时间后,再次循环", msgType = EnumLogMsgTypeEnum.Error, path = "Info" });
|
||
|
MyFileLogHelper.WriteFire(new LogInfoMo() { message = System.Environment.NewLine, msgType = EnumLogMsgTypeEnum.Error, path = "Info" });
|
||
|
MyFileLogHelper.WriteFire(new LogInfoMo() { message = System.Environment.NewLine, msgType = EnumLogMsgTypeEnum.Error, path = "Info" });
|
||
|
// Thread.Sleep(1000 * 60 * 2);
|
||
|
AddMsg(System.Environment.NewLine);
|
||
|
AddMsg("一轮播放结束,延迟一段时间后,再次循环");
|
||
|
AddMsg(System.Environment.NewLine);
|
||
|
AddMsg(System.Environment.NewLine);
|
||
|
}
|
||
|
|
||
|
AddMsg("控制播放");
|
||
|
bolIsNexCamera = false;
|
||
|
//调用播放方法
|
||
|
PalyNexCamera();
|
||
|
}
|
||
|
//Thread.Sleep(5000); //模拟工作过程
|
||
|
}
|
||
|
});
|
||
|
t.Start();
|
||
|
t.ContinueWith(task =>
|
||
|
{
|
||
|
AddMsg("任务完成,完成时候的状态为:");
|
||
|
AddMsg(string.Format("IsCanceled={0}\tIsCompleted={1}\tIsFaulted={2}",
|
||
|
task.IsCanceled, task.IsCompleted, task.IsFaulted));
|
||
|
});
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 摄像头数据缓存
|
||
|
/// </summary>
|
||
|
List<CameraInfoMo> listCamera = new List<CameraInfoMo>();
|
||
|
/// <summary>
|
||
|
/// 遍历索引
|
||
|
/// </summary>
|
||
|
int listIndex = 0;
|
||
|
/// <summary>
|
||
|
/// 初始化按钮点击
|
||
|
/// </summary>
|
||
|
/// <param name="sender"></param>
|
||
|
/// <param name="e"></param>
|
||
|
private void button1_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
//摄像头查询SQL
|
||
|
string sqlStr = @"SELECT * from tbl_camera WHERE ORG_ID in (SELECT org_id from fire_org,(select get_Org_child_list('D8DC637B8B984848A63F82A018AFAEB0') cids ) s
|
||
|
WHERE find_in_set(org_id,cids) ) and PLAYURL like 'http%' ";
|
||
|
//查询数据
|
||
|
var dt = CameraMySqlHelp.QueryTable(sqlStr);
|
||
|
//清空缓存集合
|
||
|
listCamera.Clear();
|
||
|
AddMsg("查询数据:" + dt.Rows.Count + "条");
|
||
|
for (int i = 0; i < dt.Rows.Count; i++)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
listCamera.Add(new CameraInfoMo()
|
||
|
{
|
||
|
C_NAME = dt.Rows[i]["C_NAME"] + "",
|
||
|
C_NO = dt.Rows[i]["C_NO"] + "",
|
||
|
ID = dt.Rows[i]["ID"] + "",
|
||
|
ORG_ID = dt.Rows[i]["ORG_ID"] + "",
|
||
|
ORG_NAME = dt.Rows[i]["ORG_NAME"] + "",
|
||
|
PLAYURL = dt.Rows[i]["PLAYURL"] + "",
|
||
|
});
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
AddMsg("摄像头数据加载缓存异常:索引" + i + ",异常信息:" + ex);
|
||
|
}
|
||
|
}
|
||
|
listIndex = 0;
|
||
|
AddMsg("摄像头数据加入缓存完毕");
|
||
|
//允许开始按钮点击
|
||
|
button2.Enabled = true;
|
||
|
//初始化禁用按钮点击
|
||
|
button1.Enabled = false;
|
||
|
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
AddMsg("初始化数据异常:" + ex);
|
||
|
MyFileLogHelper.WriteFire(new LogInfoMo() { message = "初始化数据异常:" + ex, msgType = EnumLogMsgTypeEnum.Error, path = "Error" });
|
||
|
}
|
||
|
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 开始监控
|
||
|
/// </summary>
|
||
|
/// <param name="sender"></param>
|
||
|
/// <param name="e"></param>
|
||
|
private void button2_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
bolIsNexCamera = true;
|
||
|
button2.Enabled = false;
|
||
|
button3.Enabled = true;
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 停止监控
|
||
|
/// </summary>
|
||
|
/// <param name="sender"></param>
|
||
|
/// <param name="e"></param>
|
||
|
private void button3_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
bolIsNexCamera = false;
|
||
|
button2.Enabled = true;
|
||
|
button1.Enabled = true;
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 控制播放
|
||
|
/// </summary>
|
||
|
private void PalyNexCamera()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
if (listCamera.Count > listIndex)
|
||
|
{
|
||
|
AddMsg("播放视频:" + listCamera[listIndex].PLAYURL);
|
||
|
vlcControl1.Play(new Uri(listCamera[listIndex].PLAYURL));
|
||
|
vlcControl1.Tag = listCamera[listIndex].ID;
|
||
|
listIndex++;
|
||
|
}
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
AddMsg("播放视频异常:" + ex);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 视频播放
|
||
|
/// </summary>
|
||
|
/// <param name="sender"></param>
|
||
|
/// <param name="e"></param>
|
||
|
private void vlcControl1_Playing(object sender, Vlc.DotNet.Core.VlcMediaPlayerPlayingEventArgs e)
|
||
|
{
|
||
|
|
||
|
var vlcObj = (VlcControl)sender;
|
||
|
MyFileLogHelper.WriteFire(new LogInfoMo() { message = "视频播放正常,信息ID:" + vlcObj.Tag, msgType = EnumLogMsgTypeEnum.Error, path = "Info" });
|
||
|
UpdCampStart(vlcObj.Tag + "", "0");
|
||
|
}
|
||
|
|
||
|
|
||
|
/// <summary>
|
||
|
/// 播放错误
|
||
|
/// </summary>
|
||
|
/// <param name="sender"></param>
|
||
|
/// <param name="e"></param>
|
||
|
private void vlcControl1_EncounteredError(object sender, Vlc.DotNet.Core.VlcMediaPlayerEncounteredErrorEventArgs e)
|
||
|
{
|
||
|
var vlcObj = (VlcControl)sender;
|
||
|
MyFileLogHelper.WriteFire(new LogInfoMo() { message = "视频播放错误,信息ID:" + vlcObj.Tag, msgType = EnumLogMsgTypeEnum.Error, path = "Info" });
|
||
|
UpdCampStart(vlcObj.Tag + "", "1");
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 播放结束
|
||
|
/// </summary>
|
||
|
/// <param name="sender"></param>
|
||
|
/// <param name="e"></param>
|
||
|
private void vlcControl1_EndReached(object sender, Vlc.DotNet.Core.VlcMediaPlayerEndReachedEventArgs e)
|
||
|
{
|
||
|
var vlcObj = (VlcControl)sender;
|
||
|
MyFileLogHelper.WriteFire(new LogInfoMo() { message = "视频播放结束,信息ID:" + vlcObj.Tag, msgType = EnumLogMsgTypeEnum.Error, path = "Info" });
|
||
|
UpdCampStart(vlcObj.Tag + "", "1");
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 播放停止
|
||
|
/// </summary>
|
||
|
/// <param name="sender"></param>
|
||
|
/// <param name="e"></param>
|
||
|
private void vlcControl1_Stopped(object sender, Vlc.DotNet.Core.VlcMediaPlayerStoppedEventArgs e)
|
||
|
{
|
||
|
var vlcObj = (VlcControl)sender;
|
||
|
MyFileLogHelper.WriteFire(new LogInfoMo() { message = "视频播放停止,信息ID:" + vlcObj.Tag, msgType = EnumLogMsgTypeEnum.Error, path = "Info" });
|
||
|
UpdCampStart(vlcObj.Tag + "", "1");
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 上一条更新摄像头ID
|
||
|
/// </summary>
|
||
|
private string SubCid = "";
|
||
|
/// <summary>
|
||
|
/// 上一条更新状态
|
||
|
/// </summary>
|
||
|
private string SubC_STATE = "";
|
||
|
/// <summary>
|
||
|
/// 更新摄像头播放状态
|
||
|
/// </summary>
|
||
|
/// <param name="cid">摄像头信息ID</param>
|
||
|
/// <param name="C_STATE">状态:0、在线;1、离线;</param>
|
||
|
private void UpdCampStart(string cid, string C_STATE)
|
||
|
{
|
||
|
//判断当前更新是否与上次更新一致
|
||
|
if (SubCid.Equals(cid) && SubC_STATE.Equals(C_STATE))
|
||
|
{
|
||
|
//设置允许继续进行下一条数据播放
|
||
|
bolIsNexCamera = true;
|
||
|
|
||
|
MyFileLogHelper.WriteFire(new LogInfoMo() { message = "状态更新与上次一致,信息ID:" + cid + ",信息状态:" + C_STATE, msgType = EnumLogMsgTypeEnum.Error, path = "Error" });
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
MyFileLogHelper.WriteFire(new LogInfoMo() { message = "更新信息状态:信息ID:" + cid + ",信息状态:" + C_STATE, msgType = EnumLogMsgTypeEnum.Error, path = "Info" });
|
||
|
try
|
||
|
{
|
||
|
|
||
|
//拼接状态更新Sql
|
||
|
string sqlUpd = " UPDATE tbl_camera set C_STATE='" + C_STATE + "' WHERE id='" + cid + "' ";
|
||
|
|
||
|
//执行Sql
|
||
|
CameraMySqlHelp.ExecuteSql(sqlUpd);
|
||
|
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
AddMsg("更新状态异常:" + ex);
|
||
|
MyFileLogHelper.WriteFire(new LogInfoMo() { message = "更新状态异常:" + ex, msgType = EnumLogMsgTypeEnum.Error, path = "Error" });
|
||
|
}
|
||
|
try
|
||
|
{
|
||
|
//实例化信息ID
|
||
|
string ID = Guid.NewGuid().ToString("N");
|
||
|
|
||
|
//拼接插入验证日志Sql
|
||
|
string sqlIns = " INSERT INTO tbl_camera_check_log (ID,CID,createtime,C_STATE) VALUES ('" + ID + "','" + cid + "',NOW(),'" + C_STATE + "') ";
|
||
|
|
||
|
//执行Sql
|
||
|
CameraMySqlHelp.ExecuteSql(sqlIns);
|
||
|
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
AddMsg("插入验证记录异常:" + ex);
|
||
|
MyFileLogHelper.WriteFire(new LogInfoMo() { message = "插入验证记录异常:" + ex, msgType = EnumLogMsgTypeEnum.Error, path = "Error" });
|
||
|
}
|
||
|
SubCid = cid;
|
||
|
SubC_STATE = C_STATE;
|
||
|
|
||
|
//控制
|
||
|
switch (C_STATE)
|
||
|
{
|
||
|
//正常播放
|
||
|
case "0":
|
||
|
//延迟10秒后继续播放下一条
|
||
|
new Thread(() =>
|
||
|
{
|
||
|
MyFileLogHelper.WriteFire(new LogInfoMo() { message = "正常播放,延迟5秒后继续播放下一条", msgType = EnumLogMsgTypeEnum.Error, path = "Info" });
|
||
|
Thread.Sleep(1000 * 5);
|
||
|
bolIsNexCamera = true;
|
||
|
MyFileLogHelper.WriteFire(new LogInfoMo() { message = "正常播放,继续播放下一条", msgType = EnumLogMsgTypeEnum.Error, path = "Info" });
|
||
|
}).Start();
|
||
|
break;
|
||
|
//异常播放
|
||
|
default:
|
||
|
//设置允许继续进行下一条数据播放
|
||
|
bolIsNexCamera = true;
|
||
|
MyFileLogHelper.WriteFire(new LogInfoMo() { message = "异常播放,继续播放下一条", msgType = EnumLogMsgTypeEnum.Error, path = "Info" });
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 添加显示消息信息
|
||
|
/// </summary>
|
||
|
/// <param name="msgStr"></param>
|
||
|
private void AddMsg(string msgStr)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
richTextBox1.Invoke(new MethodInvoker(() =>
|
||
|
{
|
||
|
//判断显示信息是否超过1万字
|
||
|
if (richTextBox1.Text.Length > 100000)
|
||
|
{
|
||
|
//文字太多,清除
|
||
|
richTextBox1.Clear();
|
||
|
}
|
||
|
//添加显示文字
|
||
|
richTextBox1.AppendText(DateTime.Now + " " + msgStr + System.Environment.NewLine);
|
||
|
|
||
|
}));
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 程序退出
|
||
|
/// </summary>
|
||
|
/// <param name="sender"></param>
|
||
|
/// <param name="e"></param>
|
||
|
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
//停止线程内循环
|
||
|
bolWhere = false;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|