Files
UA-.NETStandard/SampleApplications/Samples/Server/ServerPage.xaml.cs
T

97 lines
3.2 KiB
C#

/* Copyright (c) 1996-2016, OPC Foundation. All rights reserved.
The source code in this file is covered under a dual-license scenario:
- RCL: for OPC Foundation members in good-standing
- GPL V2: everybody else
RCL license terms accompanied with this source code. See http://opcfoundation.org/License/RCL/1.00/
GNU General Public License as published by the Free Software Foundation;
version 2 of the License are accompanied with this source code. See http://opcfoundation.org/License/GPLv2
This source code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
using System;
using Windows.UI.Xaml.Controls;
using System.Threading;
using Windows.UI.Core;
using Opc.Ua.Server;
using Opc.Ua.Configuration;
using Opc.Ua.Client.Controls;
namespace Opc.Ua.SampleServer
{
/// <summary>
/// The primary form displayed by the application.
/// </summary>
public partial class ServerPage : Page
{
#region Constructors
/// <summary>
/// Creates an empty page.
/// </summary>
public ServerPage()
{
InitializeComponent();
}
/// <summary>
/// Creates a form which displays the status for a UA server.
/// </summary>
public ServerPage(ApplicationInstance application)
{
InitializeComponent();
m_application = application;
if (application.Server is StandardServer)
{
ServerDiagnosticsCTRL.Initialize((StandardServer)application.Server, application.ApplicationConfiguration);
}
if (!application.ApplicationConfiguration.SecurityConfiguration.AutoAcceptUntrustedCertificates)
{
application.ApplicationConfiguration.CertificateValidator.CertificateValidation += new CertificateValidationEventHandler(CertificateValidator_CertificateValidation);
}
}
#endregion
#region Private Fields
private ApplicationInstance m_application;
#endregion
#region Event Handlers
/// <summary>
/// Handles a certificate validation error.
/// </summary>
void CertificateValidator_CertificateValidation(CertificateValidator validator, CertificateValidationEventArgs e)
{
ManualResetEvent ev = new ManualResetEvent(false);
Dispatcher.RunAsync(
CoreDispatcherPriority.Normal,
async () =>
{
await GuiUtils.HandleCertificateValidationError(this, validator, e);
ev.Set();
}
).AsTask().Wait();
ev.WaitOne();
}
private void ServerPage_FormClosed(object sender)
{
try
{
m_application.Stop();
}
catch (Exception exception)
{
Utils.Trace(exception, "Error stopping server.");
}
}
#endregion
}
}