mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-22 01:26:20 +08:00
171 lines
5.6 KiB
C#
171 lines
5.6 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.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using System.Reflection;
|
|
|
|
using Opc.Ua.Client;
|
|
using Opc.Ua.Client.Controls;
|
|
|
|
namespace Opc.Ua.Sample.Controls
|
|
{
|
|
public partial class CreateMonitoredItemsDlg : Form
|
|
{
|
|
#region Constructors
|
|
public CreateMonitoredItemsDlg()
|
|
{
|
|
InitializeComponent();
|
|
this.Icon = ClientUtils.GetAppIcon();
|
|
m_SubscriptionStateChanged = new SubscriptionStateChangedEventHandler(Subscription_StateChanged);
|
|
}
|
|
#endregion
|
|
|
|
#region Private Fields
|
|
private Subscription m_subscription;
|
|
private SubscriptionStateChangedEventHandler m_SubscriptionStateChanged;
|
|
#endregion
|
|
|
|
#region Public Interface
|
|
/// <summary>
|
|
/// Displays the dialog.
|
|
/// </summary>
|
|
public void Show(Subscription subscription, bool useTypeModel)
|
|
{
|
|
if (subscription == null) throw new ArgumentNullException("subscription");
|
|
|
|
Show();
|
|
BringToFront();
|
|
|
|
// remove previous subscription.
|
|
if (m_subscription != null)
|
|
{
|
|
m_subscription.StateChanged -= m_SubscriptionStateChanged;
|
|
}
|
|
|
|
// start receiving notifications from the new subscription.
|
|
m_subscription = subscription;
|
|
|
|
if (subscription != null)
|
|
{
|
|
m_subscription.StateChanged += m_SubscriptionStateChanged;
|
|
}
|
|
|
|
m_subscription = subscription;
|
|
|
|
BrowseCTRL.AllowPick = true;
|
|
BrowseCTRL.SetView(subscription.Session, (useTypeModel)?BrowseViewType.ObjectTypes:BrowseViewType.Objects, null);
|
|
|
|
MonitoredItemsCTRL.Initialize(subscription);
|
|
}
|
|
#endregion
|
|
|
|
#region Event Handlers
|
|
/// <summary>
|
|
/// Handles a change to the state of the subscription.
|
|
/// </summary>
|
|
void Subscription_StateChanged(Subscription subscription, SubscriptionStateChangedEventArgs e)
|
|
{
|
|
if (InvokeRequired)
|
|
{
|
|
BeginInvoke(m_SubscriptionStateChanged, subscription, e);
|
|
return;
|
|
}
|
|
else if (!IsHandleCreated)
|
|
{
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
// ignore notifications for other subscriptions.
|
|
if (!Object.ReferenceEquals(m_subscription, subscription))
|
|
{
|
|
return;
|
|
}
|
|
|
|
// notify controls of the change.
|
|
MonitoredItemsCTRL.SubscriptionChanged(e);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
|
|
}
|
|
}
|
|
|
|
private void BrowseCTRL_ItemsSelected(object sender, NodesSelectedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
foreach (ReferenceDescription reference in e.References)
|
|
{
|
|
if (reference.ReferenceTypeId == ReferenceTypeIds.HasProperty || reference.IsForward)
|
|
{
|
|
MonitoredItemsCTRL.AddItem(reference);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
|
|
}
|
|
}
|
|
|
|
private void ApplyBTN_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
MonitoredItemsCTRL.ApplyChanges(true);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
|
|
}
|
|
}
|
|
|
|
private void CancelBTN_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
Close();
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|