2015-11-17 update 1 add Delian Server

This commit is contained in:
parallelbgls@outlook.com
2015-11-17 10:55:18 +08:00
parent 856c4e21af
commit bc2db78435
2 changed files with 102 additions and 10 deletions

View File

@@ -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/";
}
}

View File

@@ -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<string, HttpClient>();
_machineData = new Dictionary<string, Dictionary<string, double>>();
_machineDataType = new Dictionary<string, Dictionary<string, Type>>();
GroupNameUid = new Dictionary<string, string>();
GroupNameUid = new Dictionary<string, string>();
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;
}
}