Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 22 additions & 32 deletions Applications/ConsoleReferenceClient/ClientSamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public async Task ReadNodesAsync(ISession session, CancellationToken ct = defaul
{
if (session == null || !session.Connected)
{
m_logger.LogInformation("Session not connected!");
Console.WriteLine("Session not connected!");
return;
}

Expand Down Expand Up @@ -132,7 +132,7 @@ public async Task ReadNodesAsync(ISession session, CancellationToken ct = defaul
};

// Read the node attributes
m_logger.LogInformation("Reading nodes...");
Console.WriteLine("Reading nodes...");

// Call Read Service
ReadResponse response = await session.ReadAsync(
Expand All @@ -151,18 +151,15 @@ public async Task ReadNodesAsync(ISession session, CancellationToken ct = defaul
// Display the results.
foreach (DataValue result in resultsValues)
{
m_logger.LogInformation(
"Read Value = {Value} , StatusCode = {StatusCode}",
result.Value,
result.StatusCode);
Console.WriteLine($"Read Value = {result.Value} , StatusCode = {result.StatusCode}");
}

// Read Server NamespaceArray
m_logger.LogInformation("Reading Value of NamespaceArray node...");
Console.WriteLine("Reading Value of NamespaceArray node...");
DataValue namespaceArray = await session.ReadValueAsync(Variables.Server_NamespaceArray, ct)
.ConfigureAwait(false);
// Display the result
m_logger.LogInformation("NamespaceArray Value = {NamespaceArray}", namespaceArray);
Console.WriteLine($"NamespaceArray Value = {namespaceArray}");
}
catch (Exception ex)
{
Expand All @@ -178,7 +175,7 @@ public async Task WriteNodesAsync(ISession session, CancellationToken ct = defau
{
if (session == null || !session.Connected)
{
m_logger.LogInformation("Session not connected!");
Console.WriteLine("Session not connected!");
return;
}

Expand Down Expand Up @@ -215,7 +212,7 @@ public async Task WriteNodesAsync(ISession session, CancellationToken ct = defau
nodesToWrite.Add(stringWriteVal);

// Write the node attributes
m_logger.LogInformation("Writing nodes...");
Console.WriteLine("Writing nodes...");

// Call Write Service
WriteResponse response = await session.WriteAsync(
Expand All @@ -230,11 +227,11 @@ public async Task WriteNodesAsync(ISession session, CancellationToken ct = defau
m_validateResponse(results, nodesToWrite);

// Display the results.
m_logger.LogInformation("Write Results :");
Console.WriteLine("Write Results :");

foreach (StatusCode writeResult in results)
{
m_logger.LogInformation(" {Result}", writeResult);
Console.WriteLine($" {writeResult}");
}
}
catch (Exception ex)
Expand All @@ -251,7 +248,7 @@ public async Task BrowseAsync(ISession session, CancellationToken ct = default)
{
if (session == null || !session.Connected)
{
m_logger.LogInformation("Session not connected!");
Console.WriteLine("Session not connected!");
return;
}

Expand All @@ -270,19 +267,16 @@ public async Task BrowseAsync(ISession session, CancellationToken ct = default)
NodeId nodeToBrowse = ObjectIds.Server;

// Call Browse service
m_logger.LogInformation("Browsing {Count} node...", nodeToBrowse);
Console.WriteLine($"Browsing {nodeToBrowse} node...");
ReferenceDescriptionCollection browseResults =
await browser.BrowseAsync(nodeToBrowse, ct).ConfigureAwait(false);

// Display the results
m_logger.LogInformation("Browse returned {Count} results:", browseResults.Count);
Console.WriteLine($"Browse returned {browseResults.Count} results:");

foreach (ReferenceDescription result in browseResults)
{
m_logger.LogInformation(
" DisplayName = {DisplayName}, NodeClass = {NodeClass}",
result.DisplayName.Text,
result.NodeClass);
Console.WriteLine($" DisplayName = {result.DisplayName.Text}, NodeClass = {result.NodeClass}");
}
}
catch (Exception ex)
Expand All @@ -299,7 +293,7 @@ public async Task CallMethodAsync(ISession session, CancellationToken ct = defau
{
if (session == null || !session.Connected)
{
m_logger.LogInformation("Session not connected!");
Console.WriteLine("Session not connected!");
return;
}

Expand All @@ -317,21 +311,19 @@ public async Task CallMethodAsync(ISession session, CancellationToken ct = defau
IList<object> outputArguments = null;

// Invoke Call service
m_logger.LogInformation("Calling UAMethod for method node id {NodeId} ...", methodId);
Console.WriteLine($"Calling UAMethod for node {methodId} ...");
outputArguments = await session.CallAsync(
objectId,
methodId,
ct,
inputArguments).ConfigureAwait(false);

// Display results
m_logger.LogInformation(
"Method call returned {Count} output argument(s):",
outputArguments.Count);
Console.WriteLine($"Method call returned {outputArguments.Count} output argument(s):");

foreach (object outputArgument in outputArguments)
{
m_logger.LogInformation(" OutputValue = {Value}", outputArgument);
Console.WriteLine($" OutputValue = {outputArgument}");
}
}
catch (Exception ex)
Expand All @@ -350,7 +342,7 @@ public async Task EnableEventsAsync(
{
if (session == null || !session.Connected)
{
m_logger.LogInformation("Session not connected!");
Console.WriteLine("Session not connected!");
return;
}

Expand All @@ -368,21 +360,19 @@ public async Task EnableEventsAsync(
IList<object> outputArguments = null;

// Invoke Call service
m_logger.LogInformation("Calling UAMethod for method node id {NodeId} ...", methodId);
Console.WriteLine($"Calling UAMethod for node {methodId} ...");
outputArguments = await session.CallAsync(
objectId,
methodId,
ct,
inputArguments).ConfigureAwait(false);

// Display results
m_logger.LogInformation(
"Method call returned {Count} output argument(s):",
outputArguments.Count);
Console.WriteLine($"Method call returned {outputArguments.Count} output argument(s):");

foreach (object outputArgument in outputArguments)
{
m_logger.LogInformation(" OutputValue = {Value}", outputArgument);
Console.WriteLine($" OutputValue = {outputArgument}");
}
}
catch (Exception ex)
Expand All @@ -404,7 +394,7 @@ public async Task<bool> SubscribeToDataChangesAsync(

if (session == null || !session.Connected)
{
m_logger.LogInformation("Session not connected!");
Console.WriteLine("Session not connected!");
return isDurable;
}

Expand Down
59 changes: 18 additions & 41 deletions Applications/ConsoleReferenceClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,7 @@ await application.DeleteApplicationInstanceCertificateAsync()
if (reverseConnectUrlString != null)
{
// start the reverse connection manager
logger.LogInformation(
"Create reverse connection endpoint at {Url}.",
reverseConnectUrlString);
Console.WriteLine($"Create reverse connection endpoint at {reverseConnectUrlString}.");
reverseConnectManager = new ReverseConnectManager(telemetry);
reverseConnectManager.AddEndpoint(new Uri(reverseConnectUrlString));
reverseConnectManager.StartService(config);
Expand All @@ -377,15 +375,11 @@ await application.DeleteApplicationInstanceCertificateAsync()
{
if (userpassword == null)
{
logger.LogInformation(
"No password provided for user {Username}, using empty password.",
username);
Console.WriteLine($"No password provided for user {username}, using empty password.");
}

userIdentity = new UserIdentity(username, userpassword ?? ""u8);
logger.LogInformation(
"Connect with user identity for user {Username}",
username);
Console.WriteLine($"Connect with user identity for user {username}");
}

// set user identity of type certificate
Expand All @@ -410,15 +404,11 @@ CertificateIdentifier userCertificateIdentifier
ct
).GetAwaiter().GetResult();

logger.LogInformation(
"Connect with user certificate with Thumbprint {UserCertificateThumbprint}",
userCertificateThumbprint);
Console.WriteLine($"Connect with user certificate with Thumbprint {userCertificateThumbprint}");
}
else
{
logger.LogInformation(
"Failed to load user certificate with Thumbprint {UserCertificateThumbprint}",
userCertificateThumbprint);
Console.WriteLine($"Failed to load user certificate with Thumbprint {userCertificateThumbprint}");
}
}

Expand Down Expand Up @@ -470,7 +460,7 @@ CertificateIdentifier userCertificateIdentifier
.ConfigureAwait(false);
if (connected)
{
logger.LogInformation("Connected! Ctrl-C to quit.");
Console.WriteLine("Connected! Ctrl-C to quit.");

// enable subscription transfer
uaClient.ReconnectPeriod = 1000;
Expand Down Expand Up @@ -500,7 +490,7 @@ ReferenceDescriptionCollection referenceDescriptionsFromManagedBrowse

if (browseall)
{
logger.LogInformation("Browse the full address space.");
Console.WriteLine("Browse the full address space.");
referenceDescriptions = await samples
.BrowseFullAddressSpaceAsync(uaClient, Objects.RootFolder, ct: ct)
.ConfigureAwait(false);
Expand All @@ -519,7 +509,7 @@ .. referenceDescriptions

if (managedbrowseall)
{
logger.LogInformation("ManagedBrowse the full address space.");
Console.WriteLine("ManagedBrowse the full address space.");
referenceDescriptionsFromManagedBrowse = await samples
.ManagedBrowseFullAddressSpaceAsync(
uaClient,
Expand Down Expand Up @@ -631,9 +621,7 @@ await samples
.ConfigureAwait(false);

// Wait for DataChange notifications from MonitoredItems
logger.LogInformation(
"Subscribed to {Count} variables. Press Ctrl-C to exit.",
maxVariables);
Console.WriteLine($"Subscribed to {maxVariables} variables. Press Ctrl-C to exit.");

// free unused memory
uaClient.Session.NodeCache.Clear();
Expand All @@ -655,18 +643,11 @@ await samples
.Session.ReadValueAsync(
variableIterator.Current.NodeId, ct)
.ConfigureAwait(false);
logger.LogInformation(
"Value of {NodeId} is {Value}",
variableIterator.Current.NodeId,
value
);
Console.WriteLine($"Value of {variableIterator.Current.NodeId} is {value}");
}
catch (Exception ex)
{
logger.LogInformation(ex,
"Error reading value of {NodeId}",
variableIterator.Current.NodeId
);
Console.WriteLine($"Error reading value of {variableIterator.Current.NodeId}: {ex.Message}");
}
}
else
Expand Down Expand Up @@ -714,7 +695,7 @@ await samples.SubscribeToDataChangesAsync(
enableDurableSubscriptions,
ct).ConfigureAwait(false);

logger.LogInformation("Waiting...");
Console.WriteLine("Waiting...");

// Wait for some DataChange notifications from MonitoredItems
int waitCounters = 0;
Expand All @@ -732,17 +713,14 @@ await samples.SubscribeToDataChangesAsync(
if (waitCounters == closeSessionTime &&
uaClient.Session.SubscriptionCount == 1)
{
logger.LogInformation(
"Closing Session (CurrentTime: {Time})",
DateTime.Now.ToLongTimeString());
Console.WriteLine($"Closing Session (CurrentTime: {DateTime.Now.ToLongTimeString()})");
await uaClient.Session.CloseAsync(closeChannel: false, ct: ct)
.ConfigureAwait(false);
}

if (waitCounters == restartSessionTime)
{
logger.LogInformation("Restarting Session (CurrentTime: {Time})",
DateTime.Now.ToLongTimeString());
Console.WriteLine($"Restarting Session (CurrentTime: {DateTime.Now.ToLongTimeString()})");
await uaClient
.DurableSubscriptionTransferAsync(
serverUrl.ToString(),
Expand All @@ -764,23 +742,22 @@ await uaClient
}
}

logger.LogInformation("Client disconnected.");
Console.WriteLine("Client disconnected.");

await uaClient.DisconnectAsync(leakChannels, ct).ConfigureAwait(false);
}
else
{
logger.LogInformation(
"Could not connect to server! Retry in 10 seconds or Ctrl-C to quit.");
Console.WriteLine("Could not connect to server! Retry in 10 seconds or Ctrl-C to quit.");
quit = quitEvent.WaitOne(Math.Min(10_000, waitTime));
}
} while (!quit);

logger.LogInformation("Client stopped.");
Console.WriteLine("Client stopped.");
}
catch (Exception ex)
{
logger.LogInformation("{Error}", ex.Message);
Console.WriteLine($"{ex.Message}");
}
finally
{
Expand Down
Loading
Loading