Skip to content

Commit b088bca

Browse files
committed
update
1 parent 435ada5 commit b088bca

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

Samples/GDS/Client/Controls/ApplicationCertificateControl.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
using System;
3232
using System.Drawing;
3333
using System.IO;
34+
using System.Linq;
3435
using System.Security.Cryptography.X509Certificates;
3536
using System.Threading;
3637
using System.Threading.Tasks;
@@ -254,7 +255,7 @@ private async Task RequestNewCertificatePullModeAsync(object sender, EventArgs e
254255
{
255256
//create temporary cert to generate csr from
256257
m_certificate = CertificateFactory.CreateCertificate(
257-
X509Utils.GetApplicationUriFromCertificate(m_certificate),
258+
X509Utils.GetApplicationUrisFromCertificate(m_certificate)[0],
258259
m_application.ApplicationName,
259260
Utils.ReplaceDCLocalhost(m_application.CertificateSubjectName),
260261
m_application.GetDomainNames(m_certificate))

Samples/Opc.Ua.Sample/SampleServer.UserAuthentication.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
using System;
3131
using System.Security.Cryptography.X509Certificates;
3232
using System.Text;
33+
using Microsoft.Extensions.Logging;
3334
using Opc.Ua.Server;
3435

3536
namespace Opc.Ua.Sample
@@ -81,7 +82,7 @@ private void SessionManager_ImpersonateUser(ISession session, ImpersonateEventAr
8182
{
8283
VerifyPassword(userNameToken.UserName, Encoding.UTF8.GetString(userNameToken.DecryptedPassword));
8384
args.Identity = new UserIdentity(userNameToken);
84-
Utils.Trace("UserName Token Accepted: {0}", args.Identity.DisplayName);
85+
m_logger.LogInformation("UserName Token Accepted: {0}", args.Identity.DisplayName);
8586
return;
8687
}
8788

@@ -92,7 +93,7 @@ private void SessionManager_ImpersonateUser(ISession session, ImpersonateEventAr
9293
{
9394
VerifyCertificate(x509Token.Certificate);
9495
args.Identity = new UserIdentity(x509Token);
95-
Utils.Trace("X509 Token Accepted: {0}", args.Identity.DisplayName);
96+
m_logger.LogInformation("X509 Token Accepted: {0}", args.Identity.DisplayName);
9697
return;
9798
}
9899
}
@@ -129,11 +130,11 @@ private void VerifyCertificate(X509Certificate2 certificate)
129130
{
130131
if (m_certificateValidator != null)
131132
{
132-
m_certificateValidator.Validate(certificate);
133+
m_certificateValidator.ValidateAsync(certificate, System.Threading.CancellationToken.None).GetAwaiter().GetResult();
133134
}
134135
else
135136
{
136-
CertificateValidator.Validate(certificate);
137+
CertificateValidator.ValidateAsync(certificate, System.Threading.CancellationToken.None).GetAwaiter().GetResult();
137138
}
138139
}
139140
catch (Exception e)

Workshop/Aggregation/Server/AggregationNodeManager.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ protected override void OnDeleteMonitoredItemsComplete(ServerSystemContext conte
872872
}
873873
catch (Exception e)
874874
{
875-
Utils.Trace(e, "Could not access external system.");
875+
m_logger.LogError(e, "Could not access external system.");
876876
}
877877
}
878878
}
@@ -1093,13 +1093,13 @@ public override ServiceResult SubscribeToEvents(
10931093

10941094
if (ServiceResult.IsBad(request.Status.Error))
10951095
{
1096-
Utils.Trace((int)Utils.TraceMasks.Error, "Could not create event item. {0}", request.Status.Error.ToLongString());
1096+
m_logger.LogError("Could not create event item. {0}", request.Status.Error.ToLongString());
10971097
}
10981098
}
10991099
}
11001100
catch (Exception e)
11011101
{
1102-
Utils.Trace(e, "Could not access external system.");
1102+
m_logger.LogError(e, "Could not access external system.");
11031103
}
11041104

11051105
return ServiceResult.Good;
@@ -1262,7 +1262,7 @@ Opc.Ua.Client.ISession GetClientSession(ServerSystemContext context)
12621262

12631263
try
12641264
{
1265-
Utils.Trace($"Create Connect Session: {m_endpoint} for {sessionName}");
1265+
m_logger.LogInformation($"Create Connect Session: {m_endpoint} for {sessionName}");
12661266
var session = Opc.Ua.Client.Session.CreateAsync(
12671267
m_configuration,
12681268
m_reverseConnectManager,
@@ -1299,7 +1299,7 @@ Opc.Ua.Client.ISession GetClientSession(ServerSystemContext context)
12991299
}
13001300
catch (Exception e)
13011301
{
1302-
Utils.Trace(e, "Could not connect to server.");
1302+
m_logger.LogError(e, "Could not connect to server.");
13031303

13041304
lock (m_clientsLock)
13051305
{
@@ -1441,7 +1441,7 @@ private async void DoMetadataUpdateAsync(object state)
14411441
}
14421442
catch (Exception e)
14431443
{
1444-
Utils.Trace(e, "Unexpected error updating event type cache.");
1444+
m_logger.LogError(e, "Unexpected error updating event type cache.");
14451445
}
14461446
finally
14471447
{
@@ -1655,7 +1655,7 @@ private void Client_KeepAlive(Opc.Ua.Client.ISession session, Opc.Ua.Client.Keep
16551655
{
16561656
if (e.Status != null && ServiceResult.IsNotGood(e.Status))
16571657
{
1658-
Utils.Trace("{0} {1}/{2}", e.Status, session.OutstandingRequestCount, session.DefunctRequestCount);
1658+
m_logger.LogDebug("{ 0} {1}/{2}", e.Status, session.OutstandingRequestCount, session.DefunctRequestCount);
16591659
var totalBadRequestCount = session.OutstandingRequestCount + session.DefunctRequestCount;
16601660
Opc.Ua.Client.SessionReconnectHandler reconnectHandler;
16611661
if (totalBadRequestCount >= 3 &&
@@ -1666,15 +1666,15 @@ private void Client_KeepAlive(Opc.Ua.Client.ISession session, Opc.Ua.Client.Keep
16661666
AggregationClientSession clientSession = m_clients.Where(c => c.Value?.SessionSessionId == session.SessionId).FirstOrDefault().Value;
16671667
if (clientSession != null && clientSession.ReconnectHandler == null)
16681668
{
1669-
Utils.Trace($"--- RECONNECTING --- SessionId: {clientSession.ClientSessionId}");
1669+
m_logger.LogInformation($"--- RECONNECTING --- SessionId: {clientSession.ClientSessionId}");
16701670
reconnectHandler = new Opc.Ua.Client.SessionReconnectHandler(true);
16711671
reconnectHandler.BeginReconnect(session, m_reverseConnectManager, DefaultReconnectPeriod, Client_ReconnectComplete);
16721672
clientSession.ReconnectHandler = reconnectHandler;
16731673
e.CancelKeepAlive = true;
16741674
}
16751675
else if (clientSession == null)
16761676
{
1677-
Utils.Trace($"--- KEEP ALIVE for stale session --- SessionId: {session.SessionId}");
1677+
m_logger.LogWarning($"--- KEEP ALIVE for stale session --- SessionId: {session.SessionId}");
16781678
}
16791679
}
16801680
}
@@ -1696,7 +1696,7 @@ private void Client_ReconnectComplete(object sender, EventArgs e)
16961696
AggregationClientSession clientSession = m_clients.Where(c => Object.ReferenceEquals(reconnectHandler, c.Value?.ReconnectHandler)).FirstOrDefault().Value;
16971697
if (clientSession == null)
16981698
{
1699-
Utils.Trace($"--- RECONNECTED --- SessionId: {clientSession.ClientSessionId} but client session was not found.");
1699+
m_logger.LogInformation($"--- RECONNECTED --- SessionId: {clientSession.ClientSessionId} but client session was not found.");
17001700
return;
17011701
}
17021702

@@ -1711,7 +1711,7 @@ private void Client_ReconnectComplete(object sender, EventArgs e)
17111711
Utils.SilentDispose(oldSession);
17121712
}
17131713
reconnectHandler.Dispose();
1714-
Utils.Trace($"--- RECONNECTED --- SessionId: {clientSession.ClientSessionId}");
1714+
m_logger.LogInformation($"--- RECONNECTED --- SessionId: {clientSession.ClientSessionId}");
17151715
}
17161716
}
17171717

Workshop/UserAuthentication/Server/UserAuthenticationServer.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
using System.Runtime.InteropServices;
4141
using Opc.Ua;
4242
using Opc.Ua.Server;
43+
using Microsoft.Extensions.Logging;
4344

4445
namespace Quickstarts.UserAuthenticationServer
4546
{
@@ -96,7 +97,7 @@ protected override void OnServerStarted(IServerInternal server)
9697
/// </remarks>
9798
protected override MasterNodeManager CreateMasterNodeManager(IServerInternal server, ApplicationConfiguration configuration)
9899
{
99-
Utils.Trace("Creating the Node Managers.");
100+
m_logger.LogInformation("Creating the Node Managers.");
100101

101102
List<INodeManager> nodeManagers = new List<INodeManager>();
102103

@@ -169,8 +170,7 @@ private void CreateUserIdentityValidators(ApplicationConfiguration configuration
169170

170171
if (trustedIssuers == null)
171172
{
172-
Utils.Trace(
173-
(int)Utils.TraceMasks.Error,
173+
m_logger.LogError(
174174
"Could not load CertificateTrustList for UserTokenPolicy {0}",
175175
policy.PolicyId);
176176

@@ -208,7 +208,7 @@ private void SessionManager_ImpersonateUser(ISession session, ImpersonateEventAr
208208
{
209209
VerifyPassword(userNameToken.UserName, Encoding.UTF8.GetString(userNameToken.DecryptedPassword));
210210
args.Identity = new UserIdentity(userNameToken);
211-
Utils.Trace("UserName Token Accepted: {0}", args.Identity.DisplayName);
211+
m_logger.LogInformation("UserName Token Accepted: {0}", args.Identity.DisplayName);
212212
return;
213213
}
214214

@@ -219,7 +219,7 @@ private void SessionManager_ImpersonateUser(ISession session, ImpersonateEventAr
219219
{
220220
VerifyCertificate(x509Token.Certificate);
221221
args.Identity = new UserIdentity(x509Token);
222-
Utils.Trace("X509 Token Accepted: {0}", args.Identity.DisplayName);
222+
m_logger.LogInformation("X509 Token Accepted: {0}", args.Identity.DisplayName);
223223
return;
224224
}
225225
}

0 commit comments

Comments
 (0)