Compare commits
12
Commits
1b9791f32a
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
46e32f24d1 | ||
|
|
a470d9fa34 | ||
|
|
2e2eb1be5b | ||
|
|
0946d595ed | ||
|
|
acdf42509e | ||
|
|
8e686efd6d | ||
|
|
1ba85300a9 | ||
|
|
1f8e9cd4c9 | ||
|
|
01a7d8c12c | ||
|
|
4004177313 | ||
|
|
ae1dd1a353 | ||
|
|
5d6cebc982 |
No files matched your search
+3
-1
@@ -10,6 +10,7 @@ using TouchSocket.Core;
|
|||||||
using TouchSocket.Http;
|
using TouchSocket.Http;
|
||||||
using TouchSocket.Http.WebSockets;
|
using TouchSocket.Http.WebSockets;
|
||||||
using TouchSocket.Sockets;
|
using TouchSocket.Sockets;
|
||||||
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||||
|
|
||||||
|
|
||||||
namespace ForwardingServer
|
namespace ForwardingServer
|
||||||
@@ -117,7 +118,8 @@ namespace ForwardingServer
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{//错误
|
{//错误
|
||||||
Console.WriteLine("Http:" + ex.ToString());
|
Console.WriteLine("[" + DateTime.Now.ToString("yyyy-MM-DD HH:mm:ss:fff") + "] Http:" + ex.ToString());
|
||||||
|
LogGing.ERRDATA(ex);
|
||||||
//client.SendAsync("Target instruction parsing error manager will close connection");
|
//client.SendAsync("Target instruction parsing error manager will close connection");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+44
-27
@@ -37,7 +37,7 @@ namespace ForwardingServer
|
|||||||
{
|
{
|
||||||
DATA.MachineTable.Rows.Remove(row);
|
DATA.MachineTable.Rows.Remove(row);
|
||||||
}
|
}
|
||||||
Console.WriteLine("NOT ID " + client.Id + " IP " + client.IP);
|
Console.WriteLine("[" + DateTime.Now.ToString("yyyy-MM-DD HH:mm:ss:fff") + "] NOT ID " + client.Id + " IP " + client.IP);
|
||||||
|
|
||||||
return EasyTask.CompletedTask;
|
return EasyTask.CompletedTask;
|
||||||
};//有客户端断开连接
|
};//有客户端断开连接
|
||||||
@@ -45,41 +45,48 @@ namespace ForwardingServer
|
|||||||
string DAT = e.Memory.Span.ToString(Encoding.UTF8);
|
string DAT = e.Memory.Span.ToString(Encoding.UTF8);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DataRow[] r_ = DATA.MachineTable.Select("ID='" + client.Id + "'");
|
if (DAT.Length > 5)
|
||||||
if (r_.Length > 0)
|
|
||||||
{
|
{
|
||||||
int? s_ = r_.First().Field<int?>("Start");
|
DataRow[] r_ = DATA.MachineTable.Select("ID='" + client.Id + "'");
|
||||||
|
if (r_.Length > 0)
|
||||||
if (s_ == 30)
|
|
||||||
{
|
{
|
||||||
if (DAT.StartsWith("{") || DAT.StartsWith("["))
|
int? s_ = r_.First().Field<int?>("Start");
|
||||||
{
|
|
||||||
DATA.Person deserializedPerson = JsonSerializer.Deserialize<DATA.Person>(DAT)!;
|
|
||||||
//转发逻辑
|
|
||||||
var dr = DATA.UserTable.Select("Terminal='" + deserializedPerson.Terminal + "'");
|
|
||||||
if (dr.Length > 0)
|
|
||||||
{
|
|
||||||
DataRow drEmployee = dr.First();
|
|
||||||
drEmployee.BeginEdit();
|
|
||||||
drEmployee["RDAT"] = DAT;
|
|
||||||
drEmployee.EndEdit();
|
|
||||||
drEmployee.AcceptChanges();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (s_ == 30)
|
||||||
|
{
|
||||||
|
if (DAT.StartsWith("{") || DAT.StartsWith("["))
|
||||||
|
{
|
||||||
|
DATA.Person deserializedPerson = JsonSerializer.Deserialize<DATA.Person>(DAT)!;
|
||||||
|
//转发逻辑
|
||||||
|
var dr = DATA.UserTable.Select("Terminal='" + deserializedPerson.Terminal + "'");
|
||||||
|
if (dr.Length > 0)
|
||||||
|
{
|
||||||
|
DataRow drEmployee = dr.First();
|
||||||
|
drEmployee.BeginEdit();
|
||||||
|
drEmployee["RDAT"] = DAT;
|
||||||
|
drEmployee.EndEdit();
|
||||||
|
drEmployee.AcceptChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (IsValidJson(DAT))
|
||||||
|
{
|
||||||
|
Personm deserializedPerson = JsonSerializer.Deserialize<Personm>(DAT)!;
|
||||||
|
DATA.MachineTable.Rows.Add(client.Id, client.IP, 30, "/" + deserializedPerson.SERVEREnterprise,
|
||||||
|
deserializedPerson.SERVERMachineName, deserializedPerson.MachineVer);
|
||||||
|
Console.WriteLine("[" + DateTime.Now.ToString("yyyy-MM-DD HH:mm:ss:fff") + " [LINK ID " + client.Id + " IP " + client.IP + "]\nDATA =" + DAT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Personm deserializedPerson = JsonSerializer.Deserialize<Personm>(DAT)!;
|
|
||||||
DATA.MachineTable.Rows.Add(client.Id, client.IP, 30, "/" + deserializedPerson.SERVEREnterprise,
|
|
||||||
deserializedPerson.SERVERMachineName, deserializedPerson.MachineVer);
|
|
||||||
Console.WriteLine("LINK ID "+client.Id+" IP "+ client.IP+" DATA "+ DAT);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{//错误
|
{//错误
|
||||||
Console.WriteLine("Tcp:" + ex.ToString());
|
Console.WriteLine("Tcp:" + ex.ToString());
|
||||||
|
LogGing.ERRDATA(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return EasyTask.CompletedTask;
|
return EasyTask.CompletedTask;
|
||||||
@@ -104,5 +111,15 @@ namespace ForwardingServer
|
|||||||
Console.WriteLine("TcpServer:Run");
|
Console.WriteLine("TcpServer:Run");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 辅助方法检查JSON格式
|
||||||
|
private static bool IsValidJson(string jsonString)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(jsonString))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
jsonString = jsonString.Trim();
|
||||||
|
return (jsonString.StartsWith("{") && jsonString.EndsWith("}")) ||
|
||||||
|
(jsonString.StartsWith("[") && jsonString.EndsWith("]"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+118
@@ -0,0 +1,118 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace ForwardingServer
|
||||||
|
{
|
||||||
|
public class LogGing
|
||||||
|
{
|
||||||
|
public static void LogGingDATA(string dat)
|
||||||
|
{
|
||||||
|
string logpath = System.Environment.CurrentDirectory + "\\Log";//日志文件目录
|
||||||
|
string logPath = "" + System.Environment.CurrentDirectory + "\\Log\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";//日志文件
|
||||||
|
string Log_time = "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:";
|
||||||
|
|
||||||
|
if (Directory.Exists(logpath))//检查日志路径
|
||||||
|
{
|
||||||
|
if (!File.Exists(logPath))//检查日志文件并写入启动日志
|
||||||
|
{
|
||||||
|
FileStream fs = new FileStream(logPath, FileMode.CreateNew, FileAccess.Write);//创建写入文件
|
||||||
|
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||||
|
wr.WriteLine(Log_time + dat);
|
||||||
|
wr.Close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write);
|
||||||
|
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||||
|
wr.WriteLine(Log_time + dat);
|
||||||
|
wr.Close();
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DirectoryInfo directoryInfo = new DirectoryInfo(logpath);
|
||||||
|
directoryInfo.Create();//创建日志路径
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void ERRDATA(System.Exception dat)
|
||||||
|
{
|
||||||
|
string Log_time = DateTime.Now.ToString("yyyy-MM-dd");
|
||||||
|
string logpath = System.Environment.CurrentDirectory + "\\ERR";//日志文件目录
|
||||||
|
// string logPathtxt = "" + System.Environment.CurrentDirectory + "\\Log\\"+ Log_time + "Log.txt";//日志文件
|
||||||
|
// System.IO.DirectoryInfo log = new System.IO.DirectoryInfo();//生成日志文件目录
|
||||||
|
string log_path = logpath + "\\ERR" + Log_time + ".txt";
|
||||||
|
string Log_timehms = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||||
|
if (Directory.Exists(logpath))//检查日志路径
|
||||||
|
{
|
||||||
|
if (!File.Exists(log_path))//检查文件并写入
|
||||||
|
{
|
||||||
|
// FileStream fs = new FileStream(log_path, FileMode.CreateNew, FileAccess.Write);//创建文件
|
||||||
|
// StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||||
|
// wr.Close();
|
||||||
|
FileStream fil = new FileStream(log_path, FileMode.CreateNew, FileAccess.Write);//创建写入文件
|
||||||
|
StreamWriter wfil = new StreamWriter(fil);//创建文件
|
||||||
|
wfil.WriteLine("[" + Log_timehms + "];[Error] ||" + Environment.NewLine.ToString());
|
||||||
|
wfil.WriteLine("[" + Log_timehms + "];[Error source] ||" + dat.Source.ToString() + Environment.NewLine.ToString());
|
||||||
|
wfil.WriteLine("[" + Log_timehms + "];[Error message] ||" + dat.Message.ToString() + Environment.NewLine.ToString());
|
||||||
|
wfil.WriteLine("[" + Log_timehms + "];[Error area] ||" + dat.StackTrace.ToString());
|
||||||
|
wfil.Close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FileStream fs = new FileStream(log_path, FileMode.Append, FileAccess.Write);//创建写入文件
|
||||||
|
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||||
|
wr.WriteLine("[" + Log_timehms + "];[Error] ||" + Environment.NewLine.ToString());
|
||||||
|
wr.WriteLine("[" + Log_timehms + "];[Error source] ||" + dat.ToString() + Environment.NewLine.ToString());
|
||||||
|
wr.WriteLine("[" + Log_timehms + "];[Error message] ||" + dat.Message.ToString() + Environment.NewLine.ToString());
|
||||||
|
wr.WriteLine("[" + Log_timehms + "];[Error area] ||" + dat.ToString());
|
||||||
|
wr.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DirectoryInfo directoryInfo = new DirectoryInfo(logpath);
|
||||||
|
directoryInfo.Create();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void ExchangeDATA(string dat)
|
||||||
|
{
|
||||||
|
string Log_time = DateTime.Now.ToString("yyyy-MM-dd");
|
||||||
|
string logpath = System.Environment.CurrentDirectory + "\\Exchange";//日志文件目录
|
||||||
|
// string logPathtxt = "" + System.Environment.CurrentDirectory + "\\Log\\"+ Log_time + "Log.txt";//日志文件
|
||||||
|
// System.IO.DirectoryInfo log = new System.IO.DirectoryInfo();//生成日志文件目录
|
||||||
|
string log_path = logpath + "\\Exchange" + Log_time + ".txt";
|
||||||
|
string Log_timehms = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||||
|
if (Directory.Exists(logpath))//检查日志路径
|
||||||
|
{
|
||||||
|
if (!File.Exists(log_path))//检查文件并写入
|
||||||
|
{
|
||||||
|
// FileStream fs = new FileStream(log_path, FileMode.CreateNew, FileAccess.Write);//创建文件
|
||||||
|
// StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||||
|
// wr.Close();
|
||||||
|
FileStream fil = new FileStream(log_path, FileMode.CreateNew, FileAccess.Write);//创建写入文件
|
||||||
|
StreamWriter wfil = new StreamWriter(fil);//创建文件
|
||||||
|
wfil.WriteLine("[" + Log_timehms + "];[Exchange] ||" + dat);
|
||||||
|
wfil.Close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FileStream fs = new FileStream(log_path, FileMode.Append, FileAccess.Write);//创建写入文件
|
||||||
|
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||||
|
wr.WriteLine("[" + Log_timehms + "];[Exchange] ||" + dat);
|
||||||
|
wr.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DirectoryInfo directoryInfo = new DirectoryInfo(logpath);
|
||||||
|
directoryInfo.Create();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user