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.
129 lines
5.1 KiB
129 lines
5.1 KiB
using System;
|
|
using System.IO;
|
|
using System.Web;
|
|
using HardWareInteface.Common;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace HardWareInteface.Handle
|
|
{
|
|
/// <summary>
|
|
/// 云睿设备报警消息存储(测试)
|
|
/// </summary>
|
|
public class YunRuiAlarmReceptionTest : IHttpHandler
|
|
{
|
|
public void ProcessRequest(HttpContext context)
|
|
{
|
|
context.Response.ContentType = "text/plain";
|
|
string returnStr = "";
|
|
|
|
returnStr = ReceiveAlarmInfoPlate(context);
|
|
context.Response.Write(returnStr);
|
|
}
|
|
private string ReceiveAlarmInfoPlate(HttpContext context)
|
|
{
|
|
lock (hikAlarmQueueTaskXZ.infoQueue)
|
|
{
|
|
WriteLog("进入!");
|
|
HttpRequest request = context.Request;
|
|
Stream stream = request.InputStream;
|
|
string data = string.Empty;
|
|
if (stream.Length != 0)
|
|
{
|
|
try
|
|
{
|
|
using (StreamReader streamReader = new StreamReader(stream))
|
|
{
|
|
data = streamReader.ReadToEnd();
|
|
streamReader.Close();
|
|
}
|
|
//{
|
|
// "alarmType": 2,
|
|
// "msgType": "videoMotion",
|
|
// "picUrlArray": ["https://yr-temp-storage-oss-bucket.oss-cn-hangzhou.aliyuncs.com/7day/617440/20240108/00/88e1d3b9-5218-4d5a-aafc-3cfbb84efac3.jpg?Expires=1705248006&OSSAccessKeyId=LTAI5tJw3rLMG3qjhWqCz26J&Signature=kz%2BxUUFxknmHi5iSAf7XHqGA43g%3D", "https://yr-temp-storage-oss-bucket.oss-cn-hangzhou.aliyuncs.com/7day/617440/20240108/00/14c104b9-52f5-4458-95e6-ec41689a3f81.jpg?Expires=1705248006&OSSAccessKeyId=LTAI5tJw3rLMG3qjhWqCz26J&Signature=MFh4ehB%2FHmWXVBxJub%2FHlV7Tm%2FA%3D"],
|
|
// "alarmId": "2202826988477120",
|
|
// "messageId": "d1595c38-dd13-4627-9572-590cdff2685e",
|
|
// "channelName": "岗亭离岗-1",
|
|
// "time": 1704643206000,
|
|
// "storeId": 807243840299364352,
|
|
// "deviceId": "7G09AF6PBV657EA",
|
|
// "deviceName": "岗亭离岗",
|
|
// "channelId": "0"
|
|
//}
|
|
|
|
string redata_string = data.Replace(Environment.NewLine, "");
|
|
string redata_string_json = "[";
|
|
if (redata_string.Contains("} {"))
|
|
{
|
|
redata_string = redata_string.Replace("} {", "},{");
|
|
}
|
|
else if (redata_string.Contains("}{"))
|
|
{
|
|
redata_string = redata_string.Replace("}{", "},{");
|
|
}
|
|
redata_string_json += redata_string;
|
|
redata_string_json += "]";
|
|
|
|
try
|
|
{
|
|
JArray jsonStr = JsonConvert.DeserializeObject<JArray>(redata_string_json);
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
WriteLog("\r\n 数据有误: 字符串不是json格式");
|
|
}
|
|
|
|
hikAlarmQueueTaskXZ.infoQueueFun(data); //添加 入队列
|
|
return "true";
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
WriteLog(e.Message);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
WriteLog("输入流的长度为0!");
|
|
}
|
|
return "true";
|
|
}
|
|
}
|
|
|
|
#region 记录日志
|
|
private void WriteLog(string msg)
|
|
{
|
|
FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo() { message = msg, msgType = FangYar.Common.EnumLogMsgTypeEnum.Error, path = "YunRuiAlarmReceptionTest" });
|
|
//string path = AppDomain.CurrentDomain.BaseDirectory + "log\\YunRuiAlarmReceptionTest\\";
|
|
//string filename = DateTime.Now.ToString("yyyyMMdd") + ".txt";
|
|
|
|
//if (Directory.Exists(path) == false)//如果不存在就创建文件夹
|
|
//{
|
|
// Directory.CreateDirectory(path);
|
|
//}
|
|
//FileInfo file = new FileInfo(path + filename);
|
|
//if (!file.Exists)
|
|
//{
|
|
// FileStream fs;
|
|
// fs = File.Create(path + filename);
|
|
// fs.Close();
|
|
//}
|
|
|
|
//using (FileStream fs = new FileStream(path + filename, FileMode.Append, FileAccess.Write))
|
|
//{
|
|
// using (StreamWriter sw = new StreamWriter(fs))
|
|
// {
|
|
// sw.WriteLine("时间:" + DateTime.Now.ToString() + " 信息:" + msg);
|
|
// }
|
|
//}
|
|
}
|
|
#endregion
|
|
public bool IsReusable
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|