添加信息通知,回复Notification请求的信息
This commit is contained in:
commit
797738c240
3 files changed
+147
-77
No files matched your search
@@ -185,8 +185,24 @@ namespace SunlightAggregationManager.UserClass
|
||||
data_.Add("QueryDetail", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable));
|
||||
ret = JsonSerializer.Serialize(data_);
|
||||
}
|
||||
if (Command == "Notification")//回复Notification请求的信息
|
||||
{
|
||||
string s_ = deserialized.GetValue("StartTime").ToString()!;
|
||||
string e_ = deserialized.GetValue("EndTime").ToString()!;
|
||||
|
||||
return ret;
|
||||
var groups = MainWindowViewModel.Selet_Memory(MainWindowViewModel._userData,
|
||||
"Groups", "User='" + deserializedPerson?.User + "'");
|
||||
|
||||
var resultTable = MainWindowViewModel.SQLiteHelpers.ExecuteDataSet("" +
|
||||
"select * from Notification WHERE Groups='" + groups + "' and Time>'" +
|
||||
s_ + "' and Time<'" + e_ + "'", null)?.Tables[0] ?? new DataTable();
|
||||
|
||||
//格式化返回信息
|
||||
data_.Add("Notification", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable));
|
||||
ret = JsonSerializer.Serialize(data_);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static List<Dictionary<string, object?>>? ToList(DataTable table)//datatable转list
|
||||
|
||||
+114
-76
@@ -33,6 +33,10 @@ namespace SunlightAggregationManager.UserClass
|
||||
|
||||
public static async Task TcpClient(TouchSocket.Sockets.TcpClient tcpClient, string ip)
|
||||
{
|
||||
|
||||
// 自定义心跳首次延迟60秒开始,之后每30秒执行一次
|
||||
Timer timer = new Timer(TimerCallback, null, TimeSpan.FromSeconds(60), TimeSpan.FromSeconds(30));
|
||||
|
||||
tcpClient.Connecting = (client, e) => { return EasyTask.CompletedTask; };//即将连接到服务器,此时已经创建socket,但是还未建立tcp
|
||||
tcpClient.Connected = (client, e) =>
|
||||
{
|
||||
@@ -82,6 +86,8 @@ namespace SunlightAggregationManager.UserClass
|
||||
{
|
||||
//从服务器收到信息。但是一般byteBlock和requestInfo会根据适配器呈现不同的值。
|
||||
var mes = e.Memory.Span.ToString(Encoding.UTF8);
|
||||
//信息处理暂停心跳定时
|
||||
timer.Change(Timeout.Infinite, Timeout.Infinite);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -95,30 +101,34 @@ namespace SunlightAggregationManager.UserClass
|
||||
if (_dat != "99")
|
||||
{
|
||||
//行为
|
||||
Dictionary<string, object> myDict = new Dictionary<string, object>();
|
||||
//myDict.Add("LinkID", client.Id);
|
||||
myDict.Add("LastLoginIP", deserializedPerson?.IP ?? client.IP);
|
||||
myDict.Add("LastActionTime", DateTime.Now);
|
||||
myDict.Add("Note", deserializedPerson?.Dat ?? "unknown");
|
||||
MainWindowViewModel.Updata_Memory(MainWindowViewModel._userData, "User='" + deserializedPerson?.User + "'", myDict);
|
||||
Dictionary<string, object> myDict = new Dictionary<string, object>();
|
||||
//myDict.Add("LinkID", client.Id);
|
||||
myDict.Add("LastLoginIP", deserializedPerson?.IP ?? client.IP);
|
||||
myDict.Add("LastActionTime", DateTime.Now);
|
||||
myDict.Add("Note", deserializedPerson?.Dat ?? "unknown");
|
||||
MainWindowViewModel.Updata_Memory(MainWindowViewModel._userData, "User='" + deserializedPerson?.User + "'", myDict);
|
||||
|
||||
Console.WriteLine("[Log on]User[" + deserializedPerson?.User + "]Note[" + (deserializedPerson?.Dat ?? "unknown") + "]");
|
||||
CommandC(deserializedPerson?.Dat ?? "NOT", deserializedPerson!);
|
||||
Console.WriteLine("[Log on]User[" + deserializedPerson?.User + "]Note[" + (deserializedPerson?.Dat ?? "unknown") + "]");
|
||||
CommandC(deserializedPerson?.Dat ?? "NOT", deserializedPerson!);
|
||||
}
|
||||
else
|
||||
{//停用账号关闭连接
|
||||
client.SendAsync("Account Deactivated");
|
||||
client.SendAsync("Account Deactivated");
|
||||
}
|
||||
}
|
||||
else
|
||||
{ //无效账号关闭连接
|
||||
client.SendAsync("Invalid Account");
|
||||
client.SendAsync("Invalid Account");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{//错误
|
||||
Console.WriteLine("Tcp:" + ex.ToString());
|
||||
client.SendAsync("Target instruction parsing error manager will close connection");
|
||||
client.SendAsync("Target instruction parsing error manager will close connection");
|
||||
}
|
||||
finally
|
||||
{//继续心跳定时
|
||||
timer.Change(TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(30));
|
||||
}
|
||||
|
||||
return EasyTask.CompletedTask;
|
||||
@@ -129,17 +139,12 @@ namespace SunlightAggregationManager.UserClass
|
||||
{
|
||||
await tcpClient.SetupAsync(new TouchSocketConfig()
|
||||
.SetSingleStreamDataHandlingAdapter(() => new PeriodPackageAdapter())//以超时周期和包
|
||||
.SetRemoteIPHost(ip)
|
||||
.SetKeepAliveValue(options => //心跳
|
||||
{
|
||||
options.AckInterval = 2000;
|
||||
options.Interval = 30 * 1000;
|
||||
})
|
||||
.SetRemoteIPHost(ip)
|
||||
.ConfigurePlugins(a =>
|
||||
{
|
||||
a.UseReconnection<TouchSocket.Sockets.TcpClient>(options =>
|
||||
{
|
||||
options.PollingInterval = TimeSpan.FromSeconds(3);
|
||||
options.PollingInterval = TimeSpan.FromSeconds(5);
|
||||
});
|
||||
|
||||
})
|
||||
@@ -149,6 +154,7 @@ namespace SunlightAggregationManager.UserClass
|
||||
}));
|
||||
|
||||
await tcpClient.ConnectAsync();//调用连接,当连接不成功时,会抛出异常。
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -156,73 +162,105 @@ namespace SunlightAggregationManager.UserClass
|
||||
Console.WriteLine("Tcp:" + ex.ToString());
|
||||
}
|
||||
}
|
||||
private static void TimerCallback(object? state)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (tcpClient.Online)
|
||||
{
|
||||
tcpClient.SendAsync("SUNLIGHT");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.ToString());
|
||||
LogGing.ERRDATA(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static async void CommandC(string dat, Person person)//
|
||||
{
|
||||
try {
|
||||
string Command = "", ret = "";
|
||||
|
||||
Dictionary<string, object> data_ = new Dictionary<string, object>();
|
||||
var deserialized = JsonSerializer.Deserialize<Dictionary<string, object>>(dat)!;
|
||||
if (deserialized.TryGetValue("Command", out var val) && val != null) Command = val.ToString()!;
|
||||
if (Command == "Log")//回复请求的信息
|
||||
try
|
||||
{
|
||||
DataRow? _user = MainWindowViewModel.Selet_Row(MainWindowViewModel._userData, "User='" +
|
||||
person?.User + "' and Password ='" + person?.Password + "'");
|
||||
string Command = "", ret = "";
|
||||
|
||||
data_.Add("Enterprise", _user?.Field<object>("Enterprise") ?? "");
|
||||
data_.Add("Department", _user?.Field<object>("Department") ?? "");
|
||||
data_.Add("Groups", _user?.Field<object>("Groups") ?? "");
|
||||
data_.Add("UserId", _user?.Field<object>("UserID") ?? "");
|
||||
data_.Add("UserName", _user?.Field<object>("Name") ?? "");
|
||||
ret = JsonSerializer.Serialize(data_);
|
||||
}
|
||||
if (Command == "Info")//回复info请求的信息
|
||||
{
|
||||
var t = ToList(MainWindowViewModel._machines).ToJsonString();
|
||||
//格式化返回信息
|
||||
data_.Add("Info", t);
|
||||
ret = JsonSerializer.Serialize(data_);
|
||||
}
|
||||
if (Command == "Query")//回复Query请求的信息
|
||||
{
|
||||
string s_ = deserialized.GetValue("StartTime").ToString()!;
|
||||
string e_ = deserialized.GetValue("EndTime").ToString()!;
|
||||
string f_ = deserialized.GetValue("Field").ToString()!;
|
||||
Dictionary<string, object> data_ = new Dictionary<string, object>();
|
||||
var deserialized = JsonSerializer.Deserialize<Dictionary<string, object>>(dat)!;
|
||||
if (deserialized.TryGetValue("Command", out var val) && val != null) Command = val.ToString()!;
|
||||
if (Command == "Log")//回复请求的信息
|
||||
{
|
||||
DataRow? _user = MainWindowViewModel.Selet_Row(MainWindowViewModel._userData, "User='" +
|
||||
person?.User + "' and Password ='" + person?.Password + "'");
|
||||
|
||||
DataTable resultTable = await MainWindowViewModel.dataBase.ExecuteQueryAsync("SELECT " +
|
||||
f_ + " FROM [dbo].[Dyelots] " + "WHERE CreationTime>'" + s_ + "'and CreationTime<'" + e_ + "'");
|
||||
//格式化返回信息
|
||||
data_.Add("Query", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable));
|
||||
ret = JsonSerializer.Serialize(data_);
|
||||
}
|
||||
if (Command == "QueryDyelot")//回复QueryDyelot请求的信息
|
||||
{
|
||||
string d_ = deserialized.GetValue("DyelotName").ToString()!;
|
||||
string f_ = deserialized.GetValue("Field").ToString()!;
|
||||
data_.Add("Enterprise", _user?.Field<object>("Enterprise") ?? "");
|
||||
data_.Add("Department", _user?.Field<object>("Department") ?? "");
|
||||
data_.Add("Groups", _user?.Field<object>("Groups") ?? "");
|
||||
data_.Add("UserId", _user?.Field<object>("UserID") ?? "");
|
||||
data_.Add("UserName", _user?.Field<object>("Name") ?? "");
|
||||
ret = JsonSerializer.Serialize(data_);
|
||||
}
|
||||
if (Command == "Info")//回复info请求的信息
|
||||
{
|
||||
var t = ToList(MainWindowViewModel._machines).ToJsonString();
|
||||
//格式化返回信息
|
||||
data_.Add("Info", t);
|
||||
ret = JsonSerializer.Serialize(data_);
|
||||
}
|
||||
if (Command == "Query")//回复Query请求的信息
|
||||
{
|
||||
string s_ = deserialized.GetValue("StartTime").ToString()!;
|
||||
string e_ = deserialized.GetValue("EndTime").ToString()!;
|
||||
string f_ = deserialized.GetValue("Field").ToString()!;
|
||||
|
||||
DataTable resultTable = await MainWindowViewModel.dataBase.ExecuteQueryAsync("SELECT " +
|
||||
f_ + " FROM [dbo].[Dyelots] " + "WHERE Dyelot LIKE '" + d_ + "%'");
|
||||
//格式化返回信息
|
||||
data_.Add("Query", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable));
|
||||
ret = JsonSerializer.Serialize(data_);
|
||||
}
|
||||
if (Command == "QueryDetail")//回复info请求的信息
|
||||
{
|
||||
string d_ = deserialized.GetValue("Dyelot").ToString()!;
|
||||
string r_ = deserialized.GetValue("ReDye").ToString()!;
|
||||
string f_ = deserialized.GetValue("Field").ToString()!;
|
||||
DataTable resultTable = await MainWindowViewModel.dataBase.ExecuteQueryAsync("SELECT " +
|
||||
f_ + " FROM [dbo].[Dyelots] " + "WHERE CreationTime>'" + s_ + "'and CreationTime<'" + e_ + "'");
|
||||
//格式化返回信息
|
||||
data_.Add("Query", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable));
|
||||
ret = JsonSerializer.Serialize(data_);
|
||||
}
|
||||
if (Command == "QueryDyelot")//回复QueryDyelot请求的信息
|
||||
{
|
||||
string d_ = deserialized.GetValue("DyelotName").ToString()!;
|
||||
string f_ = deserialized.GetValue("Field").ToString()!;
|
||||
|
||||
DataTable resultTable = await MainWindowViewModel.dataBase.ExecuteQueryAsync("SELECT " +
|
||||
f_ + " FROM [dbo].[DyelotsBulkedRecipe] " + "WHERE Dyelot='" + d_ + "'and ReDye='" + r_ + "'");
|
||||
//格式化返回信息
|
||||
data_.Add("QueryDetail", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable));
|
||||
ret = JsonSerializer.Serialize(data_);
|
||||
}
|
||||
DataTable resultTable = await MainWindowViewModel.dataBase.ExecuteQueryAsync("SELECT " +
|
||||
f_ + " FROM [dbo].[Dyelots] " + "WHERE Dyelot LIKE '" + d_ + "%'");
|
||||
//格式化返回信息
|
||||
data_.Add("Query", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable));
|
||||
ret = JsonSerializer.Serialize(data_);
|
||||
}
|
||||
if (Command == "QueryDetail")//回复QueryDetail请求的信息
|
||||
{
|
||||
string d_ = deserialized.GetValue("Dyelot").ToString()!;
|
||||
string r_ = deserialized.GetValue("ReDye").ToString()!;
|
||||
string f_ = deserialized.GetValue("Field").ToString()!;
|
||||
|
||||
person!.Dat = ret.ToString();
|
||||
var jsdat = JsonSerializer.Serialize(person);
|
||||
await tcpClient.SendAsync(jsdat);
|
||||
DataTable resultTable = await MainWindowViewModel.dataBase.ExecuteQueryAsync("SELECT " +
|
||||
f_ + " FROM [dbo].[DyelotsBulkedRecipe] " + "WHERE Dyelot='" + d_ + "'and ReDye='" + r_ + "'");
|
||||
//格式化返回信息
|
||||
data_.Add("QueryDetail", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable));
|
||||
ret = JsonSerializer.Serialize(data_);
|
||||
}
|
||||
if (Command == "Notification")//回复Notification请求的信息
|
||||
{
|
||||
string s_ = deserialized.GetValue("StartTime").ToString()!;
|
||||
string e_ = deserialized.GetValue("EndTime").ToString()!;
|
||||
|
||||
var groups = MainWindowViewModel.Selet_Memory(MainWindowViewModel._userData,
|
||||
"Groups", "User='" + person?.User + "'");
|
||||
|
||||
var resultTable = MainWindowViewModel.SQLiteHelpers.ExecuteDataSet("" +
|
||||
"select * from Notification WHERE Groups='" + groups + "' and Time>'" +
|
||||
s_ + "' and Time<'" + e_ + "'", null)?.Tables[0] ?? new DataTable();
|
||||
|
||||
//格式化返回信息
|
||||
data_.Add("Notification", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable));
|
||||
ret = JsonSerializer.Serialize(data_);
|
||||
}
|
||||
|
||||
person!.Dat = ret.ToString();
|
||||
var jsdat = JsonSerializer.Serialize(person);
|
||||
await tcpClient.SendAsync(jsdat);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -225,6 +225,22 @@ namespace SunlightAggregationManager.UserClass
|
||||
data_.Add("QueryDetail", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable));
|
||||
ret = JsonSerializer.Serialize(data_);
|
||||
}
|
||||
if (Command == "Notification")//回复Notification请求的信息
|
||||
{
|
||||
string s_ = deserialized.GetValue("StartTime").ToString()!;
|
||||
string e_ = deserialized.GetValue("EndTime").ToString()!;
|
||||
|
||||
var groups = MainWindowViewModel.Selet_Memory(MainWindowViewModel._userData,
|
||||
"Groups", "User='" + person?.User + "'");
|
||||
|
||||
var resultTable = MainWindowViewModel.SQLiteHelpers.ExecuteDataSet("" +
|
||||
"select * from Notification WHERE Groups='" + groups + "' and Time>'" +
|
||||
s_ + "' and Time<'" + e_ + "'", null)?.Tables[0] ?? new DataTable();
|
||||
|
||||
//格式化返回信息
|
||||
data_.Add("Notification", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable));
|
||||
ret = JsonSerializer.Serialize(data_);
|
||||
}
|
||||
|
||||
person.Dat=ret.ToString();
|
||||
var jsdat = JsonSerializer.Serialize(person);
|
||||
|
||||
Reference in new issue
Block a user