Skip to content

Commit

Permalink
Merge pull request #56 from hylasoft-usa/ua-client-opts
Browse files Browse the repository at this point in the history
ua-client-opts
  • Loading branch information
jmbeach authored Aug 1, 2017
2 parents a0dc892 + 1a31768 commit c7a5ef5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
29 changes: 22 additions & 7 deletions h-opc/Ua/UaClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ public UaClient(Uri serverUrl)
Status = OpcStatus.NotConnected;
}

/// <summary>
/// Creates a server object
/// </summary>
/// <param name="serverUrl">the url of the server to connect to</param>
/// <param name="options">custom options to use with ua client</param>
public UaClient(Uri serverUrl, UaClientOptions options)
{
_serverUrl = serverUrl;
_options = options;
Status = OpcStatus.NotConnected;
}

/// <summary>
/// Options to configure the UA client session
Expand Down Expand Up @@ -466,13 +477,17 @@ private void AddNodeToCache(UaNode node)
/// <returns>AnonUser or User with name and password</returns>
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;
}

/// <summary>
Expand Down
8 changes: 7 additions & 1 deletion h-opc/Ua/UaClientOptions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Security.Cryptography.X509Certificates;
using OpcUa = Opc.Ua;

namespace Hylasoft.Opc.Ua
{
Expand Down Expand Up @@ -91,6 +92,11 @@ public class UaClientOptions
/// </summary>
public int MaxPublishRequestCount { get; set; }

/// <summary>
/// The identity to connect to the OPC server as
/// </summary>
public OpcUa.UserIdentity UserIdentity { get; set; }

internal UaClientOptions()
{
// Initialize default values:
Expand All @@ -109,4 +115,4 @@ internal UaClientOptions()
MaxPublishRequestCount = 20;
}
}
}
}

0 comments on commit c7a5ef5

Please sign in to comment.