diff --git a/Modbus.Net/ModBus.Net/FBox/Constants.cs b/Modbus.Net/ModBus.Net/FBox/Constants.cs index 5b27546..3770b42 100644 --- a/Modbus.Net/ModBus.Net/FBox/Constants.cs +++ b/Modbus.Net/ModBus.Net/FBox/Constants.cs @@ -6,17 +6,89 @@ using System.Threading.Tasks; namespace ModBus.Net.FBox { - public static class Constants + public enum SignalRServer { - public const string BaseAddress = "https://account.flexem.com/core"; + FBoxServer = 0, + DelianServer = 1 + } - public const string AuthorizeEndpoint = BaseAddress + "/connect/authorize"; - public const string LogoutEndpoint = BaseAddress + "/connect/endsession"; - public const string TokenEndpoint = BaseAddress + "/connect/token"; - public const string UserInfoEndpoint = BaseAddress + "/connect/userinfo"; - public const string IdentityTokenValidationEndpoint = BaseAddress + "/connect/identitytokenvalidation"; - public const string TokenRevocationEndpoint = BaseAddress + "/connect/revocation"; + public class Constants + { + public SignalRServer SignalRServer = SignalRServer.FBoxServer; + + public string BaseAddress + { + get + { + switch (SignalRServer) + { + case SignalRServer.FBoxServer: + { + return "https://account.flexem.com/core"; + } + case SignalRServer.DelianServer: + { + return "https://id.data.hzdelian.com/core"; + } + default: + { + return "https://account.flexem.com/core"; + } + } + } + } + + public string AuthorizeEndpoint + { + get { return BaseAddress + "/connect/authorize"; } + } + + public string LogoutEndpoint + { + get { return BaseAddress + "/connect/endsession"; } + } + + public string TokenEndpoint + { + get { return BaseAddress + "/connect/token"; } + } + + public string UserInfoEndpoint + { + get {return BaseAddress + "/connect/userinfo"; } + } + + public string IdentityTokenValidationEndpoint + { + get {return BaseAddress + "/connect/identitytokenvalidation"; } + } + + public string TokenRevocationEndpoint + { + get {return BaseAddress + "/connect/revocation"; } + } + + public string AspNetWebApiSampleApi + { + get + { + switch (SignalRServer) + { + case SignalRServer.FBoxServer: + { + return "http://fbox360.com/api/client/"; + } + case SignalRServer.DelianServer: + { + return "http://wl.data.hzdelian.com/api/client/"; + } + default: + { + return "http://fbox360.com/api/client/"; + } + } + } + } - public const string AspNetWebApiSampleApi = "http://fbox360.com/api/client/"; } } diff --git a/Modbus.Net/ModBus.Net/FBox/SignalRConnector.cs b/Modbus.Net/ModBus.Net/FBox/SignalRConnector.cs index f68a303..d90e1cd 100644 --- a/Modbus.Net/ModBus.Net/FBox/SignalRConnector.cs +++ b/Modbus.Net/ModBus.Net/FBox/SignalRConnector.cs @@ -18,6 +18,7 @@ namespace ModBus.Net.FBox public string UserId { get; set; } public string Password { get; set; } public string SigninAdditionalValues { get; set; } + public SignalRServer SignalRServer { get; set; } } public class SignalRConnector : BaseConnector @@ -36,8 +37,21 @@ namespace ModBus.Net.FBox private bool _connected; public override bool IsConnected { get { return _connected; } } + private Constants _constants; + private Constants Constants + { + get + { + if (_constants == null) _constants = new Constants(); + return _constants; + } + + } + public SignalRConnector(string machineId, SignalRSigninMsg msg) { + Constants.SignalRServer = msg.SignalRServer; + System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; ConnectionToken = machineId; if (_oauth2 == null) { @@ -50,7 +64,7 @@ namespace ModBus.Net.FBox _httpClient2 = new Dictionary(); _machineData = new Dictionary>(); _machineDataType = new Dictionary>(); - GroupNameUid = new Dictionary(); + GroupNameUid = new Dictionary(); var tokenResponse = _oauth2.RequestResourceOwnerPasswordAsync ( msg.UserId, @@ -77,15 +91,18 @@ namespace ModBus.Net.FBox await _httpClient2[ConnectionToken].PostAsync("dmon/group/" + GroupNameUid[ConnectionToken] + "/start", null); _connected = true; + Console.WriteLine("SignalR Connected success"); return true; } else { + Console.WriteLine("SignalR Connected failed"); return false; } } catch { + Console.WriteLine("SignalR Connected failed"); return false; } } @@ -351,15 +368,18 @@ namespace ModBus.Net.FBox await _httpClient2[ConnectionToken].PostAsync("dmon/group/" + GroupNameUid[ConnectionToken] + "/stop", null); _connected = false; + Console.WriteLine("SignalR Disconnect success"); return true; } else { + Console.WriteLine("SignalR Disconnect failed"); return false; } } catch { + Console.WriteLine("SignalR Disconnect failed"); return false; } }