添加http连接功能
This commit is contained in:
commit
cd7a6df16c
7 files changed
+248
-6
No files matched your search
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using SunlightAggregationTerminal.Models;
|
||||
using System.Text.Json;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
|
||||
namespace SunlightAggregationTerminal.Class
|
||||
{
|
||||
public class DataReceived
|
||||
{
|
||||
public static void Received(string dat)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = JsonSerializer.Deserialize<Dictionary<string, object>>(dat);
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
//处理服务器发送信息
|
||||
if (data.TryGetValue("Enterprise", out var val) && val != null) App.GlobalData.Enterprise = val.ToString() ?? "";
|
||||
if (data.TryGetValue("Department", out val) && val != null) App.GlobalData.Department = val.ToString() ?? "";
|
||||
if (data.TryGetValue("Groups", out val) && val != null) App.GlobalData.Groups = val.ToString() ?? "";
|
||||
if (data.TryGetValue("UserName", out val) && val != null) App.GlobalData.UserName = val.ToString() ?? "";
|
||||
if (data.TryGetValue("UserId", out val) && val != null)
|
||||
{
|
||||
App.GlobalData.UserId = val.ToString() ?? "";
|
||||
App.GlobalData.LogNo = true;
|
||||
|
||||
HttpServer.HttpTransmit("{\"Command\":\"Info\"}");
|
||||
}
|
||||
|
||||
if (data.TryGetValue("UserData", out var value_UserData))
|
||||
{
|
||||
|
||||
}
|
||||
if (data.TryGetValue("SysData", out var value_SysData))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if (data.TryGetValue("Info", out val) && val != null)//机台信息接受
|
||||
{
|
||||
DataModel.Info_data = JsonSerializer.Deserialize<List<Dictionary<string, object>>>(val.ToString()!)!;
|
||||
//发送消息
|
||||
WeakReferenceMessenger.Default.Send(new object());
|
||||
}
|
||||
if (data.TryGetValue("Query", out val) && val != null)//查询接受
|
||||
{
|
||||
QueryPage.Query_data(val.ToString()!);
|
||||
}
|
||||
if (data.TryGetValue("QueryDetail", out val) && val != null)//查询接受
|
||||
{
|
||||
QueryDetail.Query_data(val.ToString()!);
|
||||
}
|
||||
if (data.TryGetValue("Notification", out val) && val != null)//信息通知接受
|
||||
{
|
||||
var dataNotification = JsonSerializer.Deserialize<Dictionary<string, object>>(val.ToString()!);
|
||||
|
||||
string _Title = "", _Content = "";
|
||||
int _Type = 0;
|
||||
|
||||
if (dataNotification!.TryGetValue("Title", out var value_Notification_Title))
|
||||
{
|
||||
_Title = value_Notification_Title.ToString() ?? "";
|
||||
}
|
||||
if (dataNotification!.TryGetValue("Content", out var value_Notification_Content))
|
||||
{
|
||||
_Content = value_Notification_Content.ToString() ?? "";
|
||||
}
|
||||
if (dataNotification!.TryGetValue("Type", out var value_Notification_Type))
|
||||
{
|
||||
string temp = value_Notification_Type?.ToString() ?? "";
|
||||
// 转换
|
||||
_Type = temp switch
|
||||
{
|
||||
"System" => 2,
|
||||
"Message" => 1,
|
||||
_ => 0
|
||||
};
|
||||
}
|
||||
|
||||
Models.AppModels.INSERT("INSERT INTO Notification (Title,Content,Time,Type)VALUES('" +
|
||||
_Title + "','" + _Content + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "','" + _Type + "');");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MainThread.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
Application.Current!.Windows[0].Page!.DisplayAlertAsync("", ex.Message.ToString(), "是");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static void Transmit(string Dat)
|
||||
{
|
||||
if (App.GlobalData.LocalAreaNetworkMode)
|
||||
{ TcpServer.TcpTransmit(Dat); }
|
||||
else { HttpServer.HttpTransmit(Dat); }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user