/// <summary> /// Initializes a new instance of the <see cref="UaApplication"/> class. /// </summary> /// <param name="localDescription">The <see cref="ApplicationDescription"/> of the local application.</param> /// <param name="certificateStore">The local certificate store.</param> /// <param name="identityProvider">An asynchronous function that provides the user identity. Provide an <see cref="AnonymousIdentity"/>, <see cref="UserNameIdentity"/>, <see cref="IssuedIdentity"/> or <see cref="X509Identity"/>.</param> /// <param name="mappedEndpoints">The mapped endpoints.</param> /// <param name="loggerFactory">The logger factory.</param> /// <param name="options">The application options.</param> /// <param name="additionalTypes">Any additional types to be registered with encoder.</param> public UaApplication( ApplicationDescription localDescription, ICertificateStore certificateStore, Func <EndpointDescription, Task <IUserIdentity> > identityProvider, IEnumerable <MappedEndpoint> mappedEndpoints, ILoggerFactory loggerFactory = null, UaApplicationOptions options = null, IEnumerable <Type> additionalTypes = null) { if (localDescription == null) { throw new ArgumentNullException(nameof(localDescription)); } this.LocalDescription = localDescription; this.CertificateStore = certificateStore; this.UserIdentityProvider = identityProvider; this.MappedEndpoints = mappedEndpoints; this.LoggerFactory = loggerFactory; this.Options = options ?? new UaApplicationOptions(); this.AdditionalTypes = additionalTypes; this.logger = loggerFactory?.CreateLogger <UaApplication>(); this.channelMap = new ConcurrentDictionary <string, Lazy <Task <UaTcpSessionChannel> > >(); lock (globalLock) { if (appInstance != null) { throw new InvalidOperationException("You can only create a single instance of this type."); } appInstance = this; } }
/// <summary> /// Specify the <see cref="UaApplicationOptions"/>. /// </summary> /// <param name="options">The options.</param> /// <returns>The <see cref="UaApplicationBuilder"/>.</returns> public UaApplicationBuilder UseOptions(UaApplicationOptions options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } if (this.options != null) { throw new InvalidOperationException("The options has already been specified."); } this.options = options; return(this); }
/// <summary> /// Specify the <see cref="UaApplicationOptions"/>. /// </summary> /// <param name="options">The <see cref="UaApplicationOptions"/>.</param> /// <returns>The <see cref="UaApplicationBuilder"/>.</returns> public UaApplicationBuilder SetOptions(UaApplicationOptions options) { this.options = options ?? throw new ArgumentNullException(nameof(options)); return(this); }
/// <summary> /// This Service returns the Endpoints supported by a Server and all of the configuration information required to establish a SecureChannel and a Session. /// </summary> /// <param name="request">a request.</param> /// <param name="loggerFactory">The logger factory.</param> /// <param name="options">The secure channel options.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> public static async Task <GetEndpointsResponse> GetEndpointsAsync(GetEndpointsRequest request, ILoggerFactory loggerFactory = null, UaApplicationOptions options = null) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var client = new UaTcpDiscoveryService( new EndpointDescription { EndpointUrl = request.EndpointUrl, SecurityMode = MessageSecurityMode.None, SecurityPolicyUri = SecurityPolicyUris.None }, loggerFactory, options); try { await client.OpenAsync().ConfigureAwait(false); var response = await client.innerChannel.RequestAsync(request).ConfigureAwait(false); await client.CloseAsync().ConfigureAwait(false); return((GetEndpointsResponse)response); } catch (Exception) { await client.AbortAsync().ConfigureAwait(false); throw; } }