diff --git a/h-opc/Ua/UaClient.cs b/h-opc/Ua/UaClient.cs index 62bac5e..2699007 100644 --- a/h-opc/Ua/UaClient.cs +++ b/h-opc/Ua/UaClient.cs @@ -33,6 +33,17 @@ public UaClient(Uri serverUrl) Status = OpcStatus.NotConnected; } + /// + /// Creates a server object + /// + /// the url of the server to connect to + /// custom options to use with ua client + public UaClient(Uri serverUrl, UaClientOptions options) + { + _serverUrl = serverUrl; + _options = options; + Status = OpcStatus.NotConnected; + } /// /// Options to configure the UA client session @@ -466,13 +477,17 @@ private void AddNodeToCache(UaNode node) /// AnonUser or User with name and password private UserIdentity GetIdentity(Uri url) { - var uriLogin = new UserIdentity(); - if (!string.IsNullOrEmpty(url.UserInfo)) - { - var uis = url.UserInfo.Split(':'); - uriLogin = new UserIdentity(uis[0], uis[1]); - } - return uriLogin; + if (_options.UserIdentity != null) + { + return _options.UserIdentity; + } + var uriLogin = new UserIdentity(); + if (!string.IsNullOrEmpty(url.UserInfo)) + { + var uis = url.UserInfo.Split(':'); + uriLogin = new UserIdentity(uis[0], uis[1]); + } + return uriLogin; } /// diff --git a/h-opc/Ua/UaClientOptions.cs b/h-opc/Ua/UaClientOptions.cs index 08dd8cf..84e401f 100644 --- a/h-opc/Ua/UaClientOptions.cs +++ b/h-opc/Ua/UaClientOptions.cs @@ -1,5 +1,6 @@ using System; using System.Security.Cryptography.X509Certificates; +using OpcUa = Opc.Ua; namespace Hylasoft.Opc.Ua { @@ -91,6 +92,11 @@ public class UaClientOptions /// public int MaxPublishRequestCount { get; set; } + /// + /// The identity to connect to the OPC server as + /// + public OpcUa.UserIdentity UserIdentity { get; set; } + internal UaClientOptions() { // Initialize default values: @@ -109,4 +115,4 @@ internal UaClientOptions() MaxPublishRequestCount = 20; } } -} \ No newline at end of file +}