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
2 changes: 1 addition & 1 deletion Applications/ConsoleReferenceServer/UAServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace Quickstarts
public class UAServer<T>
where T : StandardServer, new()
{
public ApplicationInstance Application { get; private set; }
public IApplicationInstance Application { get; private set; }

public ApplicationConfiguration Configuration => Application.ApplicationConfiguration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class ReferenceServer : ReverseConnectServer
/// always creates a CoreNodeManager which handles the built-in nodes defined by the specification.
/// Any additional NodeManagers are expected to handle application specific nodes.
/// </remarks>
protected override MasterNodeManager CreateMasterNodeManager(
protected override IMasterNodeManager CreateMasterNodeManager(
IServerInternal server,
ApplicationConfiguration configuration)
{
Expand Down
4 changes: 2 additions & 2 deletions Applications/Quickstarts.Servers/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static class Utils
/// <summary>
/// Applies custom settings to quickstart servers for CTT run.
/// </summary>
public static async Task ApplyCTTModeAsync(TextWriter output, StandardServer server)
public static async Task ApplyCTTModeAsync(TextWriter output, IStandardServer server)
{
var methodsToCall = new CallMethodRequestCollection();
int index = server.CurrentInstance.NamespaceUris.GetIndex(Alarms.Namespaces.Alarms);
Expand Down Expand Up @@ -97,7 +97,7 @@ public static async Task ApplyCTTModeAsync(TextWriter output, StandardServer ser
/// <summary>
/// Add all available node manager factories to the server.
/// </summary>
public static void AddDefaultNodeManagers(StandardServer server)
public static void AddDefaultNodeManagers(IStandardServer server)
{
foreach (INodeManagerFactory nodeManagerFactory in NodeManagerFactories)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public ApplicationConfigurationBuilder(ApplicationInstance applicationInstance)
/// <summary>
/// The application instance used to build the configuration.
/// </summary>
public ApplicationInstance ApplicationInstance { get; }
public IApplicationInstance ApplicationInstance { get; }

/// <summary>
/// The application configuration.
Expand Down
103 changes: 21 additions & 82 deletions Libraries/Opc.Ua.Configuration/ApplicationInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@

namespace Opc.Ua.Configuration
{
/// <summary>
/// A class that install, configures and runs a UA application.
/// </summary>
public class ApplicationInstance
/// <inheritdoc/>
public class ApplicationInstance : IApplicationInstance
{
/// <summary>
/// Obsolete constructor
Expand Down Expand Up @@ -86,71 +84,37 @@ public ApplicationInstance(
ApplicationConfiguration = applicationConfiguration;
}

/// <summary>
/// Gets or sets the name of the application.
/// </summary>
/// <value>The name of the application.</value>
/// <inheritdoc/>
public string ApplicationName { get; set; }

/// <summary>
/// Gets or sets the type of the application.
/// </summary>
/// <value>The type of the application.</value>
/// <inheritdoc/>
public ApplicationType ApplicationType { get; set; }

/// <summary>
/// Gets or sets the name of the config section containing the path
/// to the application configuration file.
/// </summary>
/// <value>The name of the config section.</value>
/// <inheritdoc/>
public string ConfigSectionName { get; set; }

/// <summary>
/// Gets or sets the type of configuration file.
/// </summary>
/// <value>The type of configuration file.</value>
/// <inheritdoc/>
public Type ConfigurationType { get; set; }

/// <summary>
/// Gets the server.
/// </summary>
/// <value>The server.</value>
public ServerBase Server { get; private set; }
/// <inheritdoc/>
public IServerBase Server { get; private set; }

/// <summary>
/// Gets the application configuration used when the Start() method was called.
/// </summary>
/// <value>The application configuration.</value>
/// <inheritdoc/>
public ApplicationConfiguration ApplicationConfiguration { get; set; }

/// <summary>
/// Get or set the message dialog.
/// </summary>
public static IApplicationMessageDlg MessageDlg { get; set; }

/// <summary>
/// Get or set the certificate password provider.
/// </summary>
/// <inheritdoc/>
public ICertificatePasswordProvider CertificatePasswordProvider { get; set; }

/// <summary>
/// Get or set bool which indicates if the auto creation
/// of a new application certificate during startup is disabled.
/// Default is enabled./>
/// </summary>
/// <remarks>
/// Prevents auto self signed cert creation in use cases
/// where an expired certificate should not be automatically
/// renewed or where it is required to only use certificates
/// provided by the user.
/// </remarks>
/// <inheritdoc/>
public bool DisableCertificateAutoCreation { get; set; }

/// <summary>
/// Starts the UA server.
/// </summary>
/// <param name="server">The server.</param>
public async Task StartAsync(ServerBase server)
/// <inheritdoc/>
public async Task StartAsync(IServerBase server)
{
Server = server;

Expand All @@ -162,9 +126,7 @@ public async Task StartAsync(ServerBase server)
await server.StartAsync(ApplicationConfiguration).ConfigureAwait(false);
}

/// <summary>
/// Stops the UA server.
/// </summary>
/// <inheritdoc/>
public ValueTask StopAsync()
{
return Server.StopAsync();
Expand All @@ -179,10 +141,7 @@ public void Stop()
Server.Stop();
}

/// <summary>
/// Loads the application configuration.
/// </summary>
/// <exception cref="ServiceResultException"></exception>
/// <inheritdoc/>
public async Task<ApplicationConfiguration> LoadApplicationConfigurationAsync(
Stream stream,
bool silent,
Expand Down Expand Up @@ -218,10 +177,7 @@ public async Task<ApplicationConfiguration> LoadApplicationConfigurationAsync(
return configuration;
}

/// <summary>
/// Loads the application configuration.
/// </summary>
/// <exception cref="ServiceResultException"></exception>
/// <inheritdoc/>
public async ValueTask<ApplicationConfiguration> LoadApplicationConfigurationAsync(
string filePath,
bool silent,
Expand Down Expand Up @@ -257,9 +213,7 @@ public async ValueTask<ApplicationConfiguration> LoadApplicationConfigurationAsy
return configuration;
}

/// <summary>
/// Loads the application configuration.
/// </summary>
/// <inheritdoc/>
public ValueTask<ApplicationConfiguration> LoadApplicationConfigurationAsync(
bool silent,
CancellationToken ct = default)
Expand Down Expand Up @@ -288,9 +242,7 @@ public static ApplicationConfiguration FixupAppConfig(
return configuration;
}

/// <summary>
/// Create a builder for a UA application configuration.
/// </summary>
/// <inheritdoc/>
public IApplicationConfigurationBuilderTypes Build(string applicationUri, string productUri)
{
// App Uri and cert subject
Expand All @@ -312,10 +264,7 @@ public IApplicationConfigurationBuilderTypes Build(string applicationUri, string
return new ApplicationConfigurationBuilder(this);
}

/// <summary>
/// Deletes all application certificates.
/// </summary>
/// <exception cref="ArgumentException"></exception>
/// <inheritdoc/>
public async ValueTask DeleteApplicationInstanceCertificateAsync(
string[] profileIds = null,
CancellationToken ct = default)
Expand All @@ -334,13 +283,7 @@ await DeleteApplicationInstanceCertificateAsync(ApplicationConfiguration, id, ct
}
}

/// <summary>
/// Checks for a valid application instance certificate.
/// </summary>
/// <param name="silent">if set to <c>true</c> no dialogs will be displayed.</param>
/// <param name="lifeTimeInMonths">The lifetime in months.</param>
/// <param name="ct">Cancellation token to cancel operation with</param>
/// <exception cref="ServiceResultException"></exception>
/// <inheritdoc/>
public async ValueTask<bool> CheckApplicationInstanceCertificatesAsync(
bool silent,
ushort? lifeTimeInMonths = null,
Expand Down Expand Up @@ -554,11 +497,7 @@ await id.LoadPrivateKeyExAsync(passwordProvider, configuration.ApplicationUri, m
return true;
}

/// <summary>
/// Adds a Certificate to the Trusted Store of the Application, needed e.g. for the GDS to trust it´s own CA
/// </summary>
/// <param name="certificate">The certificate to add to the store</param>
/// <param name="ct">The cancellation token</param>
/// <inheritdoc/>
public async Task AddOwnCertificateToTrustedStoreAsync(
X509Certificate2 certificate,
CancellationToken ct)
Expand Down
153 changes: 153 additions & 0 deletions Libraries/Opc.Ua.Configuration/IApplicationInstance.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/* ========================================================================
* Copyright (c) 2005-2025 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* The complete license agreement can be found here:
* http://opcfoundation.org/License/MIT/1.00/
* ======================================================================*/

using System;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Threading.Tasks;

namespace Opc.Ua.Configuration
{
/// <summary>
/// A class that installs, configures and runs a UA application.
/// </summary>
public interface IApplicationInstance
{
/// <summary>
/// Gets the application configuration used when the Start() method was called.
/// </summary>
/// <value>The application configuration.</value>
ApplicationConfiguration ApplicationConfiguration { get; set; }

/// <summary>
/// Gets or sets the name of the application.
/// </summary>
/// <value>The name of the application.</value>
string ApplicationName { get; set; }

/// <summary>
/// Gets or sets the type of the application.
/// </summary>
/// <value>The type of the application.</value>
ApplicationType ApplicationType { get; set; }

/// <summary>
/// Get or set the certificate password provider.
/// </summary>
ICertificatePasswordProvider CertificatePasswordProvider { get; set; }

/// <summary>
/// Gets or sets the name of the config section containing the path
/// to the application configuration file.
/// </summary>
/// <value>The name of the config section.</value>
string ConfigSectionName { get; set; }

/// <summary>
/// Gets or sets the type of configuration file.
/// </summary>
/// <value>The type of configuration file.</value>
Type ConfigurationType { get; set; }

/// <summary>
/// Get or set bool which indicates if the auto creation
/// of a new application certificate during startup is disabled.
/// Default is enabled./>
/// </summary>
/// <remarks>
/// Prevents auto self signed cert creation in use cases
/// where an expired certificate should not be automatically
/// renewed or where it is required to only use certificates
/// provided by the user.
/// </remarks>
bool DisableCertificateAutoCreation { get; set; }

/// <summary>
/// Gets the server.
/// </summary>
/// <value>The server.</value>
IServerBase Server { get; }

/// <summary>
/// Adds a Certificate to the Trusted Store of the Application, needed e.g. for the GDS to trust it´s own CA
/// </summary>
/// <param name="certificate">The certificate to add to the store</param>
/// <param name="ct">The cancellation token</param>
Task AddOwnCertificateToTrustedStoreAsync(X509Certificate2 certificate, CancellationToken ct);

/// <summary>
/// Create a builder for a UA application configuration.
/// </summary>
IApplicationConfigurationBuilderTypes Build(string applicationUri, string productUri);

/// <summary>
/// Checks for a valid application instance certificate.
/// </summary>
/// <param name="silent">if set to <c>true</c> no dialogs will be displayed.</param>
/// <param name="lifeTimeInMonths">The lifetime in months.</param>
/// <param name="ct">Cancellation token to cancel operation with</param>
/// <exception cref="ServiceResultException"></exception>
ValueTask<bool> CheckApplicationInstanceCertificatesAsync(bool silent, ushort? lifeTimeInMonths = null, CancellationToken ct = default);

/// <summary>
/// Deletes all application certificates.
/// </summary>
/// <exception cref="ArgumentException"></exception>
ValueTask DeleteApplicationInstanceCertificateAsync(string[] profileIds = null, CancellationToken ct = default);

/// <summary>
/// Loads the application configuration.
/// </summary>
/// <exception cref="ServiceResultException"></exception>
ValueTask<ApplicationConfiguration> LoadApplicationConfigurationAsync(bool silent, CancellationToken ct = default);

/// <summary>
/// Loads the application configuration.
/// </summary>
/// <exception cref="ServiceResultException"></exception>
Task<ApplicationConfiguration> LoadApplicationConfigurationAsync(Stream stream, bool silent, CancellationToken ct = default);

/// <summary>
/// Loads the application configuration.
/// </summary>
ValueTask<ApplicationConfiguration> LoadApplicationConfigurationAsync(string filePath, bool silent, CancellationToken ct = default);

/// <summary>
/// Starts the UA server.
/// </summary>
/// <param name="server">The server.</param>
Task StartAsync(IServerBase server);

/// <summary>
/// Stops the UA server.
/// </summary>
ValueTask StopAsync();
}
}
Loading
Loading