Files
UA-.NETStandard/ComIOP/Common/Client/Da/ComDaClientManager.cs
T

142 lines
5.2 KiB
C#

/* ========================================================================
* Copyright (c) 2005-2019 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.Collections.Generic;
using System.Text;
using System.Threading;
using Opc.Ua;
using Opc.Ua.Server;
using Opc.Ua.Com;
using OpcRcw.Da;
namespace Opc.Ua.Com.Client
{
/// <summary>
/// Manages the DA COM connections used by the UA server.
/// </summary>
public class ComDaClientManager : ComClientManager
{
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="ComDaClientManager"/> class.
/// </summary>
public ComDaClientManager()
{
}
#endregion
#region Public Members
/// <summary>
/// Selects the DA COM client to use for the current context.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="useDefault">True if the the default instance should be returned.</param>
/// <returns>A DA COM client instance.</returns>
public new ComDaClient SelectClient(ServerSystemContext context, bool useDefault)
{
return (ComDaClient)base.SelectClient(context, useDefault);
}
#endregion
#region Protected Members
/// <summary>
/// Gets or sets the default COM client instance.
/// </summary>
/// <value>The default client.</value>
protected new ComDaClient DefaultClient
{
get { return base.DefaultClient as ComDaClient; }
set { base.DefaultClient = value; }
}
/// <summary>
/// Gets the configuration.
/// </summary>
/// <value>The configuration.</value>
protected new ComDaClientConfiguration Configuration
{
get { return base.Configuration as ComDaClientConfiguration; }
}
/// <summary>
/// Creates a new client object.
/// </summary>
protected override ComClient CreateClient()
{
return new ComDaClient(Configuration);
}
/// <summary>
/// Updates the status node.
/// </summary>
protected override bool UpdateStatus()
{
// get the status from the server.
ComDaClient client = DefaultClient;
OPCSERVERSTATUS? status = client.GetStatus();
// check the client has been abandoned.
if (!Object.ReferenceEquals(client, DefaultClient))
{
return false;
}
// update the server status.
lock (StatusNodeLock)
{
StatusNode.ServerUrl.Value = Configuration.ServerUrl;
if (status != null)
{
StatusNode.SetStatusCode(DefaultSystemContext, StatusCodes.Good, DateTime.UtcNow);
StatusNode.ServerState.Value = Utils.Format("{0}", status.Value.dwServerState);
StatusNode.CurrentTime.Value = ComUtils.GetDateTime(status.Value.ftCurrentTime);
StatusNode.LastUpdateTime.Value = ComUtils.GetDateTime(status.Value.ftLastUpdateTime);
StatusNode.StartTime.Value = ComUtils.GetDateTime(status.Value.ftStartTime);
StatusNode.VendorInfo.Value = status.Value.szVendorInfo;
StatusNode.SoftwareVersion.Value = Utils.Format("{0}.{1}.{2}", status.Value.wMajorVersion, status.Value.wMinorVersion, status.Value.wBuildNumber);
}
else
{
StatusNode.SetStatusCode(DefaultSystemContext, StatusCodes.BadOutOfService, DateTime.UtcNow);
}
StatusNode.ClearChangeMasks(DefaultSystemContext, true);
return status != null;
}
}
#endregion
#region Private Fields
#endregion
}
}