Files
UA-.NETStandard/SampleApplications/Samples/Server/ServerPage.xaml.cs
T
Erich Barnstedt 1ac35fdec0 .Net Core 1.0 Release Upgrade (VS2015 Update3 is now required!):
1. Upgraded from UWP 5.1.0 to 5.2.0
2. Upgraded all assemblies from RC to RTM bits
3. Renamed Common directory to Opc.Ua.Sample
4. Reimplemented HTTP transport due to removed classes in .Net Standard
5. Small UWP XML class cleanup due to changes in UWP 5.2.0
2016-06-29 10:09:34 +02:00

96 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
}
}