20240128
This commit is contained in:
parent
eb9ab319e7
commit
c597921c60
|
@ -13,8 +13,6 @@
|
|||
<ItemGroup>
|
||||
<Compile Remove="._Program.cs" />
|
||||
<Compile Remove="._ReadMe.cs" />
|
||||
<Compile Remove="Peripheral\._DataBase.cs" />
|
||||
<Compile Remove="Peripheral\._MonitorServer.cs" />
|
||||
<Compile Remove="Utils\._FileUtils.cs" />
|
||||
<Compile Remove="Utils\._JsonUtils.cs" />
|
||||
<Compile Remove="Utils\._LiteDBUtils.cs" />
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HxServer;
|
||||
|
||||
|
@ -14,14 +10,14 @@ public class ReadMe
|
|||
{
|
||||
public static string AppName { get => "HxServer"; }
|
||||
|
||||
public static string VersionString { get => $"{AppName} V{Version.First().Key.Split(' ')[0]} ({Version.First().Key.Split(' ')[3]})"; }
|
||||
public static string VersionString => $"{AppName} V{Version.First().Key.Split(' ')[0]} ({Version.First().Key.Split(' ')[3]})";
|
||||
|
||||
static Dictionary<string, List<string>> Version = new Dictionary<string, List<string>>()
|
||||
{
|
||||
["1.00 Alpha Bulid 20240111"] = new List<string>()
|
||||
static readonly Dictionary<string, List<string>> Version = new()
|
||||
{
|
||||
["1.00 Alpha Bulid 20240111"] =
|
||||
[
|
||||
"版本名称格式变换",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
[RequiresAssemblyFiles()]
|
||||
|
@ -33,9 +29,9 @@ public class ReadMe
|
|||
|
||||
using (FileStream fr = new(Path.Combine(path, "ReadMe.md"), FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite))
|
||||
{
|
||||
using (StreamWriter sw = new StreamWriter(fr, Encoding.UTF8))
|
||||
using (StreamWriter sw = new(fr, Encoding.UTF8))
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
StringBuilder sb = new();
|
||||
sb.AppendLine($"# {AppName}").AppendLine();
|
||||
foreach (var item in Version)
|
||||
{
|
||||
|
|
|
@ -1,10 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HxServer.Utils
|
||||
namespace HxServer.Utils
|
||||
{
|
||||
public class DebugTrace
|
||||
{
|
||||
|
|
|
@ -1,48 +1,49 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Text;
|
||||
|
||||
namespace HxServer.Utils;
|
||||
|
||||
public class FileUtils
|
||||
{
|
||||
public static long Size(string fullpath) { try { return new FileInfo(fullpath).Length; } catch { return 0; } }
|
||||
|
||||
public static string GetName(string fullpath) { try { return new FileInfo(fullpath).Name; } catch { return ""; } }
|
||||
|
||||
public static string ReadString(string fullpath) { try { return File.ReadAllText(fullpath); } catch { return ""; } }
|
||||
|
||||
public static byte[] ReadBytes(string fullpath) { try { return File.ReadAllBytes(fullpath); } catch { return null; } }
|
||||
|
||||
public static void Append(string fullpath, string contents)
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(fullpath.Substring(0, fullpath.LastIndexOf("/")));
|
||||
Directory.CreateDirectory(fullpath[..fullpath.LastIndexOf('/')]);
|
||||
|
||||
using FileStream fr = new FileStream(fullpath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
|
||||
using StreamWriter sw = new StreamWriter(fr, Encoding.UTF8);
|
||||
using FileStream fr = new(fullpath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
|
||||
using StreamWriter sw = new(fr, Encoding.UTF8);
|
||||
sw.WriteLine(contents);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
public static void Append(string fullpath, byte[] contents)
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(fullpath.Substring(0, fullpath.LastIndexOf("/")));
|
||||
Directory.CreateDirectory(fullpath[..fullpath.LastIndexOf('/')]);
|
||||
|
||||
using FileStream fr = new FileStream(fullpath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
|
||||
using FileStream fr = new(fullpath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
|
||||
fr.Write(contents, 0, contents.Length);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
public static void Append(string fullpath, byte[] contents, int offset, int count)
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(fullpath.Substring(0, fullpath.LastIndexOf("/")));
|
||||
Directory.CreateDirectory(fullpath[..fullpath.LastIndexOf('/')]);
|
||||
|
||||
using FileStream fr = new FileStream(fullpath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
|
||||
using FileStream fr = new(fullpath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
|
||||
fr.Write(contents, offset, count);
|
||||
}
|
||||
catch { }
|
||||
|
@ -52,23 +53,22 @@ public class FileUtils
|
|||
{
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(fullpath.Substring(0, fullpath.LastIndexOf("/")));
|
||||
Directory.CreateDirectory(fullpath[..fullpath.LastIndexOf('/')]);
|
||||
|
||||
using FileStream fr = new FileStream(fullpath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
|
||||
using StreamWriter sw = new StreamWriter(fr, Encoding.UTF8);
|
||||
using FileStream fr = new(fullpath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
|
||||
using StreamWriter sw = new(fr, Encoding.UTF8);
|
||||
sw.WriteLine(contents);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
|
||||
public static void WriteFile(string fullpath, byte[] contents)
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(fullpath.Substring(0, fullpath.LastIndexOf("/")));
|
||||
Directory.CreateDirectory(fullpath[..fullpath.LastIndexOf('/')]);
|
||||
|
||||
using FileStream fr = new FileStream(fullpath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
|
||||
using FileStream fr = new(fullpath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
|
||||
fr.Write(contents, 0, contents.Length);
|
||||
}
|
||||
catch { }
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Net;
|
||||
|
||||
namespace HxServer.Utils;
|
||||
|
||||
|
@ -57,7 +54,7 @@ public class HttpUtils
|
|||
/* 设置返回数据为JSON类 */
|
||||
Context.Response.AddHeader("Content-Type", "application/json");
|
||||
|
||||
System.Threading.Tasks.Task.Factory.StartNew(() => ListenCallBack?.Invoke(null, Context));
|
||||
Task.Factory.StartNew(() => ListenCallBack?.Invoke(null, Context));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -71,7 +68,7 @@ public class HttpUtils
|
|||
{
|
||||
result = string.Empty;
|
||||
|
||||
using var client = new HttpClient() { Timeout = TimeSpan.FromSeconds(seconds) };
|
||||
using HttpClient client = new() { Timeout = TimeSpan.FromSeconds(seconds) };
|
||||
var response = client.GetAsync(url).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
|
@ -97,8 +94,8 @@ public class HttpUtils
|
|||
|
||||
HttpContent content = new StringContent(data.ToString());
|
||||
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/josn");
|
||||
using HttpClient client = new();
|
||||
HttpResponseMessage res = client.PostAsync(url, content).Result;
|
||||
using HttpClient client = new() { Timeout = TimeSpan.FromSeconds(seconds) };
|
||||
var res = client.PostAsync(url, content).Result;
|
||||
if (res.IsSuccessStatusCode)
|
||||
{
|
||||
result = res.Content.ReadAsStringAsync().Result;
|
||||
|
|
|
@ -12,9 +12,9 @@ namespace HxServer.Utils;
|
|||
#pragma warning disable IL2026 // Using dynamic types might cause types or members to be removed by trimmer.
|
||||
public class TaskUtils
|
||||
{
|
||||
private static ConcurrentDictionary<Guid, Task> TaskQueue = new ConcurrentDictionary<Guid, Task>();
|
||||
private static ConcurrentDictionary<Guid, Task> TaskQueue = new();
|
||||
|
||||
private static ConcurrentDictionary<Guid, CancellationTokenSource> Dispatchers = new ConcurrentDictionary<Guid, CancellationTokenSource>();
|
||||
private static ConcurrentDictionary<Guid, CancellationTokenSource> Dispatchers = new();
|
||||
|
||||
public static bool TryCancel(Guid guid)
|
||||
{
|
||||
|
|
212
ReadMe.md
Normal file
212
ReadMe.md
Normal file
|
@ -0,0 +1,212 @@
|
|||
# 通讯协议
|
||||
|
||||
- [协议结构](#协议结构)
|
||||
- [数据格式](#数据格式)
|
||||
- [心跳](#心跳)
|
||||
- [查询软件参数信息](#查询软件参数信息)
|
||||
- [修改软件参数信息](#修改软件参数信息)
|
||||
- [查询日志](#查询日志)
|
||||
- [添加日志](#添加日志)
|
||||
- [查询录像](#查询录像)
|
||||
- [更新录像数据](#更新录像数据)
|
||||
- [删除录像数据](#删除录像数据)
|
||||
|
||||
## 协议结构
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| action_type | int | 操作类型 |
|
||||
| msgInfo | object | 每个接口特有的参数,详见每个接口定义 |
|
||||
|
||||
## 数据格式
|
||||
|
||||
### 心跳
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| action_type | int | 0 |
|
||||
| msgInfo | object | |
|
||||
|
||||
**msgInfo** 参数如下
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| name | string | 程序名称 |
|
||||
| version | string | 版本信息 |
|
||||
|
||||
### 查询软件参数信息
|
||||
|
||||
* 请求
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| action_type | int | 1 |
|
||||
|
||||
* 回复
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| action_type | int | 1 |
|
||||
| msgInfo | Dictionary < string, string > | 设置信息 |
|
||||
|
||||
|
||||
### 修改软件参数信息
|
||||
|
||||
* 请求
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| action_type | int | 2 |
|
||||
| msgInfo | Dictionary < string, string > | 设置信息 |
|
||||
|
||||
* 回复
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| action_type | int | 2 |
|
||||
| msgInfo | object | |
|
||||
|
||||
**msgInfo** 参数如下
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| status | bool | true: 成功; false: 失败; |
|
||||
| message | string | 异常信息 |
|
||||
|
||||
### 查询日志
|
||||
|
||||
* 请求
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| action_type | int | 3 |
|
||||
| msgInfo | object | |
|
||||
|
||||
**msgInfo** 参数如下
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| type | int | 0: 系统事件; 1: 用户操作; 2: 视频通道; |
|
||||
| date | string | 日期 |
|
||||
| index | int | 通道号(仅视频通道日志有效) |
|
||||
| month | bool | true: 检索全月; false: 不检索全月 |
|
||||
|
||||
* 回复
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| action_type | int | 3 |
|
||||
| msgInfo | object[] | |
|
||||
|
||||
**msgInfo ** 参数如下
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| timestamp | DateTime | 事件事件 |
|
||||
| type | int | 事件类型 |
|
||||
| index | int | 视频通道日志类型时为通道号,其他为空 |
|
||||
| message | string | 消息 |
|
||||
| data | string | 详细信息 |
|
||||
|
||||
|
||||
### 添加日志
|
||||
|
||||
* 请求
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| action_type | int | 4 |
|
||||
| msgInfo | object | |
|
||||
|
||||
**msgInfo** 参数如下
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| timestamp | DateTime | 事件事件 |
|
||||
| type | int | 事件类型 |
|
||||
| index | int | 视频通道日志类型时为通道号,其他为空 |
|
||||
| message | string | 消息 |
|
||||
| data | string | 详细信息 |
|
||||
|
||||
### 查询录像
|
||||
|
||||
* 请求
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| action_type | int | 5 |
|
||||
| msgInfo | object | |
|
||||
|
||||
> **msgInfo** 参数为空,查询最早的一条录像数据
|
||||
|
||||
> **msgInfo** 参数如下, 按通道、开始日期、结束日期参数查询录像数据
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| channel | int | 通道号 |
|
||||
| start_date | DateTime | 开始日期 |
|
||||
| end_date | DateTime | 结束日期 |
|
||||
|
||||
> **msgInfo** 参数如下, 按日期查询录像数据
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| date | DateTime | 日期 |
|
||||
|
||||
|
||||
* 回复
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| action_type | int | 5 |
|
||||
| msgInfo | object[] | |
|
||||
|
||||
**msgInfo ** 参数如下
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| channel | int | 通道号 |
|
||||
| start_date | DateTime | 开始日期 |
|
||||
| end_date | DateTime | 结束日期 |
|
||||
| duration | int | 录像时长 |
|
||||
| name | string | 文件名称 |
|
||||
| path | string | 文件路径 |
|
||||
|
||||
### 更新录像数据
|
||||
|
||||
* 请求
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| action_type | int | 6 |
|
||||
| msgInfo | object | |
|
||||
|
||||
**msgInfo ** 参数如下
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| channel | int | 通道号 |
|
||||
| start_date | DateTime | 开始日期 |
|
||||
| end_date | DateTime | 结束日期 |
|
||||
| duration | int | 录像时长 |
|
||||
| name | string | 文件名称 |
|
||||
| path | string | 文件路径 |
|
||||
|
||||
### 删除录像数据
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| action_type | int | 7 |
|
||||
| msgInfo | object | |
|
||||
|
||||
> **msgInfo** 参数如下, 按文件路径删除录像
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| path | string | 文件路径 |
|
||||
|
||||
> **msgInfo** 参数如下, 按录像日期删除录像
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| date | DateTime | 日期 |
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user