temporary update
This commit is contained in:
@@ -124,9 +124,11 @@ namespace Modbus.Net.FBox
|
|||||||
_connected = true;
|
_connected = true;
|
||||||
_timer = new Timer(ChangeToken, null, 3600*1000*4, 3600*1000*4);
|
_timer = new Timer(ChangeToken, null, 3600*1000*4, 3600*1000*4);
|
||||||
Console.WriteLine("SignalR Connected success");
|
Console.WriteLine("SignalR Connected success");
|
||||||
|
_connectionState = 1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_connectionState = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -134,6 +136,7 @@ namespace Modbus.Net.FBox
|
|||||||
_oauth2 = null;
|
_oauth2 = null;
|
||||||
Console.WriteLine("SignalR Connected failed " + e.Message);
|
Console.WriteLine("SignalR Connected failed " + e.Message);
|
||||||
Clear();
|
Clear();
|
||||||
|
_connectionState = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -175,14 +178,8 @@ namespace Modbus.Net.FBox
|
|||||||
var signalrUrl = box.Box.CommServer.SignalRUrl;
|
var signalrUrl = box.Box.CommServer.SignalRUrl;
|
||||||
var boxUid = box.Box.Uid;
|
var boxUid = box.Box.Uid;
|
||||||
var boxNo = box.Box.BoxNo;
|
var boxNo = box.Box.BoxNo;
|
||||||
var connectionState = box.Box.ConnectionState;
|
|
||||||
|
|
||||||
if (boxNo != MachineId) continue;
|
if (boxNo != MachineId) continue;
|
||||||
if (connectionState != 1)
|
|
||||||
{
|
|
||||||
_connected = false;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
_httpClient2 = new HttpClient
|
_httpClient2 = new HttpClient
|
||||||
{
|
{
|
||||||
@@ -206,7 +203,6 @@ namespace Modbus.Net.FBox
|
|||||||
|
|
||||||
_boxSessionId = sessionId;
|
_boxSessionId = sessionId;
|
||||||
_boxNo = boxNo;
|
_boxNo = boxNo;
|
||||||
_connectionState = connectionState;
|
|
||||||
|
|
||||||
_hubConnection = new HubConnection(signalrUrl);
|
_hubConnection = new HubConnection(signalrUrl);
|
||||||
_hubConnection.Headers.Add("Authorization", "Bearer " + token);
|
_hubConnection.Headers.Add("Authorization", "Bearer " + token);
|
||||||
@@ -282,7 +278,7 @@ namespace Modbus.Net.FBox
|
|||||||
sessionId = newConnectionToken;
|
sessionId = newConnectionToken;
|
||||||
_boxSessionId = sessionId;
|
_boxSessionId = sessionId;
|
||||||
|
|
||||||
_connectionState = newStatus;
|
//_connectionState = newStatus;
|
||||||
|
|
||||||
if (!IsConnected || _httpClient2 == null || _hubConnection == null)
|
if (!IsConnected || _httpClient2 == null || _hubConnection == null)
|
||||||
{
|
{
|
||||||
@@ -302,31 +298,32 @@ namespace Modbus.Net.FBox
|
|||||||
|
|
||||||
_hubConnection.Headers["X-FBox-Session"] = sessionId.ToString();
|
_hubConnection.Headers["X-FBox-Session"] = sessionId.ToString();
|
||||||
await _hubConnection.Start();
|
await _hubConnection.Start();
|
||||||
|
_data.Clear();
|
||||||
if (newStatus == 1)
|
//if (newStatus == 1)
|
||||||
{
|
//{
|
||||||
if (IsConnected)
|
//if (IsConnected)
|
||||||
{
|
//{
|
||||||
await
|
await
|
||||||
_httpClient2.PostAsync(
|
_httpClient2.PostAsync(
|
||||||
"dmon/group/" + _dataGroup.Uid + "/start", null);
|
"dmon/group/" + _dataGroup.Uid + "/start", null);
|
||||||
}
|
//}
|
||||||
}
|
//}
|
||||||
|
|
||||||
else
|
//else
|
||||||
{
|
//{
|
||||||
lock (_data)
|
//lock (_data)
|
||||||
{
|
//{
|
||||||
_data.Clear();
|
//_data.Clear();
|
||||||
}
|
//}
|
||||||
//await DisconnectAsync();
|
//await DisconnectAsync();
|
||||||
//_connected = false;
|
//_connected = false;
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine("SignalR boxSessionId change error: " + ex.Message);
|
Console.WriteLine("SignalR boxSessionId change error: " + ex.Message);
|
||||||
await DisconnectAsync();
|
await DisconnectAsync();
|
||||||
|
_connected = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -350,11 +347,11 @@ namespace Modbus.Net.FBox
|
|||||||
var groupUid = _dataGroup.Uid;
|
var groupUid = _dataGroup.Uid;
|
||||||
var groupName = _dataGroup.Name;
|
var groupName = _dataGroup.Name;
|
||||||
|
|
||||||
if (groupName != "(Default)" && groupName != "默认组" && _connectionState == 1)
|
if (groupName != "(Default)" && groupName != "默认组")
|
||||||
{
|
{
|
||||||
_groupUid = groupUid;
|
_groupUid = groupUid;
|
||||||
}
|
}
|
||||||
if (groupName != "(Default)" && groupName != "默认组" && _connectionState == 1)
|
if (groupName != "(Default)" && groupName != "默认组")
|
||||||
{
|
{
|
||||||
_boxUid = boxUid;
|
_boxUid = boxUid;
|
||||||
}
|
}
|
||||||
@@ -490,6 +487,7 @@ namespace Modbus.Net.FBox
|
|||||||
}
|
}
|
||||||
Clear();
|
Clear();
|
||||||
Console.WriteLine("SignalR Disconnect success");
|
Console.WriteLine("SignalR Disconnect success");
|
||||||
|
_connectionState = 0;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -497,6 +495,7 @@ namespace Modbus.Net.FBox
|
|||||||
{
|
{
|
||||||
Console.WriteLine("SignalR Disconnect failed " + e.Message);
|
Console.WriteLine("SignalR Disconnect failed " + e.Message);
|
||||||
Clear();
|
Clear();
|
||||||
|
_connectionState = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user