ctrlX Data Layer .NET API  4.3.0
Loading...
Searching...
No Matches
Remote.cs
1using System;
2
3namespace Datalayer
4{
57 public class Remote
58 {
62 public string Ip { get; private set; }
63
67 public string User { get; private set; }
68
72 public string Password { get; private set; }
73
77 public int? Port { get; private set; }
78
82 public int SslPort { get; private set; }
83
87 public ProtocolScheme ProtocolScheme { get; private set; }
88
100 public Remote(ProtocolScheme protocolScheme = ProtocolScheme.AUTO, string ip = "192.168.1.1", string user = "boschrexroth", string password = "boschrexroth", int sslPort = 443, int? port = null)
101 {
102 ProtocolScheme = protocolScheme;
103 Ip = ip ?? throw new ArgumentNullException(nameof(ip));
104 User = user ?? throw new ArgumentNullException(nameof(user));
105 Password = password ?? throw new ArgumentNullException(nameof(password));
106 SslPort = sslPort;
107
108 if (port.HasValue)
109 {
110 Port = port >= 0 ? port.Value : throw new ArgumentException("invalid port");
111 }
112 }
113
118 public override string ToString()
119 {
121 {
123 }
124
125 return !Port.HasValue ?
126 $"{Protocol}{User}:{Password}@{Ip}?sslport={SslPort}" :
127 $"{Protocol}{User}:{Password}@{Ip}:{Port.Value}?sslport={SslPort}";
128 }
129
134 public string Protocol
135 {
136 get
137 {
138 switch (ProtocolScheme)
139 {
140 case ProtocolScheme.AUTO:
141 return AutodetectProtocol();
142 case ProtocolScheme.TCP:
144 case ProtocolScheme.IPC:
146 default:
147 throw new NotSupportedException("Unknown protocol scheme");
148 }
149 }
150 }
151
156 private static string AutodetectProtocol()
157 {
158 if (Environment.GetEnvironmentVariable("SNAP") != null &&
159 Environment.GetEnvironmentVariable("SNAP_NAME") != "dotnet-sdk")
160 {
162 }
163
164 return DatalayerSystem.ProtocolSchemeTcp;
165 }
166
172 //private static bool IsLocalHost(string hostNameOrIpAddress)
173 //{
174 // if (string.IsNullOrEmpty(hostNameOrIpAddress))
175 // {
176 // return false;
177 // }
178
179 // var hostName = Dns.GetHostName();
180
181 // // Known localhost identifiers for IPv4 and IPv6
182 // if (hostNameOrIpAddress.Equals("localhost", StringComparison.OrdinalIgnoreCase) ||
183 // hostNameOrIpAddress.Equals(hostName, StringComparison.OrdinalIgnoreCase) ||
184 // hostNameOrIpAddress.Equals("127.0.0.1", StringComparison.Ordinal) ||
185 // hostNameOrIpAddress.Equals("::1", StringComparison.Ordinal) ||
186 // hostNameOrIpAddress.Equals("0:0:0:0:0:0:0:1", StringComparison.Ordinal))
187 // {
188 // return true;
189 // }
190
191 // try
192 // {
193 // var testIPs = Dns.GetHostAddresses(hostNameOrIpAddress);
194
195 // //1. Test IP's against LoopBack
196 // if (testIPs.Any(IPAddress.IsLoopback))
197 // {
198 // return true;
199 // }
200
201 // //2. Test IP's against local machine IP's
202 // var localIPs = Dns.GetHostAddresses(hostName);
203 // foreach (var testIp in testIPs)
204 // {
205 // foreach (var localIp in localIPs)
206 // {
207 // if (string.Equals(testIp.ToString(), localIp.ToString(), StringComparison.Ordinal))
208 // {
209 // return true;
210 // }
211 // }
212 // }
213 // return false;
214 // }
215 // catch (SocketException)
216 // {
217 // return false;
218 // }
219 //}
220 }
221}
Provides the implementation for IDatalayerSystem.
static readonly string ProtocolSchemeTcp
Gets the protocol scheme for TCP communication. Recommended to connect to a DatalayerSystem not runni...
static readonly string ProtocolSchemeIpc
Gets the protocol scheme for IPC communication. Recommended to connect to a DatalayerSystem running o...
Provides a container for a TCP remote connection string.
Definition: Remote.cs:58
string Protocol
The communication protocol scheme scheme.
Definition: Remote.cs:135
int SslPort
Gets the port number of the SSL connection.
Definition: Remote.cs:82
int? Port
Gets the port number of the connection.
Definition: Remote.cs:77
string Password
Gets the user password.
Definition: Remote.cs:72
string User
Gets the user name.
Definition: Remote.cs:67
override string ToString()
Creates the remote connection string for TCP or IPC.
Definition: Remote.cs:118
Remote(ProtocolScheme protocolScheme=ProtocolScheme.AUTO, string ip="192.168.1.1", string user="boschrexroth", string password="boschrexroth", int sslPort=443, int? port=null)
Initializes a new instance of the Remote class.
Definition: Remote.cs:100
string Ip
Gets the IP address of the ctrlX CORE.
Definition: Remote.cs:62