|
|
@ -40,6 +40,8 @@ namespace SunlightAggregationTerminal.Class |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
await HttpClient(DataReceived.ServerIP); |
|
|
await HttpClient(DataReceived.ServerIP); |
|
|
|
|
|
|
|
|
|
|
|
HttpTransmit("{\"Command\":\"Log\"}"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -53,30 +55,26 @@ namespace SunlightAggregationTerminal.Class |
|
|
#region Http客户端获取断线通知
|
|
|
#region Http客户端获取断线通知
|
|
|
config.ConfigurePlugins(a => |
|
|
config.ConfigurePlugins(a => |
|
|
{ |
|
|
{ |
|
|
|
|
|
//处理连接断开
|
|
|
a.AddTcpClosedPlugin(async (c, e) => |
|
|
a.AddTcpClosedPlugin(async (c, e) => |
|
|
{ |
|
|
{ |
|
|
// 专门处理超时或主动取消的情况
|
|
|
//MainThread.BeginInvokeOnMainThread(() =>
|
|
|
MainThread.BeginInvokeOnMainThread(() => |
|
|
// {
|
|
|
{ |
|
|
// Application.Current!.Windows[0].Page!.DisplayAlertAsync("", "客户端断开连接", "是");
|
|
|
Application.Current!.Windows[0].Page!.DisplayAlertAsync("", "客户端断开连接", "是"); |
|
|
// });
|
|
|
}); |
|
|
// await e.InvokeNext();
|
|
|
await e.InvokeNext(); |
|
|
|
|
|
}); |
|
|
|
|
|
}); config.ConfigurePlugins(a => |
|
|
|
|
|
{ |
|
|
|
|
|
a.AddTcpConnectedPlugin(async (c, e) => |
|
|
|
|
|
{ |
|
|
|
|
|
HttpTransmit("{\"Command\":\"Log\"}"); |
|
|
|
|
|
await e.InvokeNext(); |
|
|
|
|
|
}); |
|
|
}); |
|
|
}); |
|
|
//自动重连
|
|
|
/*config.ConfigurePlugins(a => |
|
|
|
|
|
{ |
|
|
|
|
|
a.UseReconnection<TouchSocket.Http.HttpClient>(options => |
|
|
a.UseReconnection<TouchSocket.Http.HttpClient>(options => |
|
|
{ |
|
|
{ |
|
|
options.PollingInterval = TimeSpan.FromSeconds(3); |
|
|
options.PollingInterval = TimeSpan.FromSeconds(3); |
|
|
}); |
|
|
}); |
|
|
});*/ |
|
|
//处理连接
|
|
|
|
|
|
a.AddTcpConnectedPlugin(async (c, e) => |
|
|
|
|
|
{ |
|
|
|
|
|
await e.InvokeNext(); |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
#endregion
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
if (httpclient.Online)//是否重置客户端
|
|
|
if (httpclient.Online)//是否重置客户端
|
|
|
@ -93,6 +91,10 @@ namespace SunlightAggregationTerminal.Class |
|
|
/***发送信息处理***/ |
|
|
/***发送信息处理***/ |
|
|
public static async void HttpTransmit(string Dat) |
|
|
public static async void HttpTransmit(string Dat) |
|
|
{ |
|
|
{ |
|
|
|
|
|
if(!httpclient.Online) //检查连接
|
|
|
|
|
|
{ |
|
|
|
|
|
await httpclient.ConnectAsync(); |
|
|
|
|
|
} |
|
|
var dat = new DataReceived.Person() |
|
|
var dat = new DataReceived.Person() |
|
|
{ |
|
|
{ |
|
|
User = DataReceived.ServerName, |
|
|
User = DataReceived.ServerName, |
|
|
@ -119,6 +121,7 @@ namespace SunlightAggregationTerminal.Class |
|
|
// GetBodyAsync 同样需要响应取消信号,如果这里超过剩余时间也会抛出异常
|
|
|
// GetBodyAsync 同样需要响应取消信号,如果这里超过剩余时间也会抛出异常
|
|
|
var result = await response.GetBodyAsync(); |
|
|
var result = await response.GetBodyAsync(); |
|
|
DataReceived.Received(result); |
|
|
DataReceived.Received(result); |
|
|
|
|
|
//await httpclient.CloseAsync();//关闭客户端
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
catch (OperationCanceledException) |
|
|
catch (OperationCanceledException) |
|
|
@ -126,8 +129,9 @@ namespace SunlightAggregationTerminal.Class |
|
|
// 专门处理超时或主动取消的情况
|
|
|
// 专门处理超时或主动取消的情况
|
|
|
MainThread.BeginInvokeOnMainThread(() => |
|
|
MainThread.BeginInvokeOnMainThread(() => |
|
|
{ |
|
|
{ |
|
|
Application.Current!.Windows[0].Page!.DisplayAlertAsync("网络错误", "网络请求超时,请检查网络或服务器状态。", "是"); |
|
|
Application.Current!.Windows[0].Page!.DisplayAlertAsync("网络错误", "网络请求超时,请检查网络网络连接", "是"); |
|
|
}); |
|
|
}); |
|
|
|
|
|
await httpclient.CloseAsync();//关闭客户端
|
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
catch (Exception ex) |
|
|
{ |
|
|
{ |
|
|
@ -136,9 +140,7 @@ namespace SunlightAggregationTerminal.Class |
|
|
Application.Current!.Windows[0].Page!.DisplayAlertAsync("网络错误", ex.Message.ToString(), "是"); |
|
|
Application.Current!.Windows[0].Page!.DisplayAlertAsync("网络错误", ex.Message.ToString(), "是"); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|