/// <summary> /// Respond to button click to delete node from subscription list /// -- refresh content display accordingly /// </summary> private void ContextMenu_OnDelete(object sender, RoutedEventArgs e) { Button CommandBTN = sender as Button; try { var monitoredItem = CommandBTN.Tag as MonitoredItem; if (monitoredItem == null) { return; } var subscription = monitoredItem.Subscription; SessionsCTRL.Delete(monitoredItem); if (subscription.MonitoredItemCount == 0) { // Remove subscription if no more items CommandBTN.Tag = subscription; ContextMenu_OnCancelSubscription(sender, e); } } catch (Exception exception) { GuiUtils.HandleException(String.Empty, GuiUtils.CallerName(), exception); } }
private void StandardClient_Server_ReconnectComplete(object sender, EventArgs e) { if (InvokeRequired) { BeginInvoke(new EventHandler(StandardClient_Server_ReconnectComplete), sender, e); return; } try { // ignore callbacks from discarded objects. if (!Object.ReferenceEquals(sender, m_reconnectHandler)) { return; } m_session = m_reconnectHandler.Session; m_reconnectHandler.Dispose(); m_reconnectHandler = null; BrowseCTRL.SetView(m_session, BrowseViewType.Objects, null); SessionsCTRL.Reload(m_session); StandardClient_KeepAlive(m_session, null); } catch (Exception exception) { GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception); } }
/// <summary> /// UI: connects to a specified server endpoint, and create subscription list according to configuration /// </summary> private async Task <bool> Connect(ConfiguredEndpoint endpoint) { bool result = false; if (endpoint == null) { return(false); } // connect dialogs Session session = await SessionsCTRL.Connect(endpoint, m_sessionConfig?.sessionname); if (session != null) { if (m_sessionConfig != null) { NamespaceTable namespaceTable = new NamespaceTable(); DataValue namespaceArrayNodeValue = session.ReadValue(VariableIds.Server_NamespaceArray); namespaceTable.Update(namespaceArrayNodeValue.GetValue <string[]>(null)); m_sessionConfig.endpoint = session.ConfiguredEndpoint; foreach (MonitoredNode x in m_sessionConfig.monitoredlist) { CreateMonitoredItem(x.description, session, null, ExpandedNodeId.Parse(x.nodeid, namespaceTable), x.displayname, MonitoringMode.Reporting); } } m_design_session = session; result = true; } return(result); }
private void ContextMenu_OnCancel(object sender, RoutedEventArgs e) { try { SessionsCTRL.Delete(CommandBTN.Tag as Subscription); } catch (Exception exception) { GuiUtils.HandleException(String.Empty, GuiUtils.CallerName(), exception); } }
private void ContextMenu_OnCancel(IUICommand command) { try { SessionsCTRL.Delete(command.Id as Subscription); } catch (Exception exception) { GuiUtils.HandleException(String.Empty, GuiUtils.CallerName(), exception); } }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { try { SessionsCTRL.Close(); } catch (Exception exception) { GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception); } }
/// <summary> /// Updates the status control when a keep alive event occurs. /// </summary> async void StandardClient_KeepAlive(Session sender, KeepAliveEventArgs e) { if (!Dispatcher.HasThreadAccess) { await Dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => { StandardClient_KeepAlive(sender, e); }); return; } if (sender != null && sender.Endpoint != null) { ServerUrlTB.Text = Utils.Format( "{0} ({1}) {2}", sender.Endpoint.EndpointUrl, sender.Endpoint.SecurityMode, (sender.EndpointConfiguration.UseBinaryEncoding) ? "UABinary" : "XML"); } else { ServerUrlTB.Text = "None"; } if (e != null && m_session != null) { SessionsCTRL.UpdateSessionNode(m_session); if (ServiceResult.IsGood(e.Status)) { ServerStatusTB.Text = Utils.Format( "Server Status: {0} {1:yyyy-MM-dd HH:mm:ss} {2}/{3}", e.CurrentState, e.CurrentTime.ToLocalTime(), m_session.OutstandingRequestCount, m_session.DefunctRequestCount); ServerStatusTB.Foreground = new SolidColorBrush(Colors.Black); ServerStatusTB.FontWeight = FontWeights.Normal; } else { ServerStatusTB.Text = String.Format( "{0} {1}/{2}", e.Status, m_session.OutstandingRequestCount, m_session.DefunctRequestCount); ServerStatusTB.Foreground = new SolidColorBrush(Colors.Red); ServerStatusTB.FontWeight = FontWeights.Bold; } } }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { try { SessionsCTRL.Close(); if (m_masterForm == null) { m_application.Stop(); } } catch (Exception exception) { GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception); } }
private void MainPage_PageClosing(object sender, RoutedEventArgs e) { try { SessionsCTRL.Close(); if (m_masterPage == null) { m_application.Stop(); } } catch (Exception exception) { GuiUtils.HandleException(String.Empty, GuiUtils.CallerName(), exception); } }
/// <summary> /// Connects to a server. /// </summary> public void Connect(ConfiguredEndpoint endpoint) { if (endpoint == null) { return; } Session session = SessionsCTRL.Connect(endpoint); if (session != null) { m_session = session; m_session.KeepAlive += new KeepAliveEventHandler(StandardClient_KeepAlive); BrowseCTRL.SetView(m_session, BrowseViewType.Objects, null); StandardClient_KeepAlive(m_session, null); } }
/// <summary> /// Respond to button click to delete whole subscription list /// -- refresh content display accordingly /// </summary> private void ContextMenu_OnCancelSubscription(object sender, RoutedEventArgs e) { Button CommandBTN = sender as Button; try { foreach (MonitoredItem x in (CommandBTN.Tag as Subscription).MonitoredItems) { SessionsCTRL.Delete(x); } SessionsCTRL.Delete(CommandBTN.Tag as Subscription); } catch (Exception exception) { GuiUtils.HandleException(String.Empty, GuiUtils.CallerName(), exception); } }
/// <summary> /// UI: close current server session, and clear related contents from UI /// <summary> public void CloseSessionView_OpcuaClient(bool resetUIButton = true) { Opcua_EndpointDisconnect(); if (resetUIButton) { var ignored = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { BrowseCTRL.Clear(); SessionsCTRL.Clear(); gridEndpointSelector.Visibility = Visibility.Collapsed; EndpointSelectorCTRL.Visibility = Visibility.Visible; EndpointSelectorCTRL.IsEnabled = true; EnableSessionOpButtons(true); }); } }
/// <summary> /// UI: open server session, and display contents from server /// <summary> private async Task OpenSessionView_OpcuaClient() { try { var sessionname = "NewSession"; if (sessionMgmtAction == SESSIONMGMT_ACTION.EDIT) { sessionname = sessionInfo.sessionName; } var session = await Opcua_EndpointConnect(sessionname, m_sessionConfig.endpoint); if (session != null) { m_design_session = session; var ignored = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { SessionsCTRL.AddNode(session); gridEndpointSelector.Visibility = Visibility.Visible; txtEndpointSelector.Text = m_design_session.Endpoint.EndpointUrl.ToString(); EndpointSelectorCTRL.Visibility = Visibility.Collapsed; BrowseCTRL.IsEnabled = true; SessionsCTRL.IsEnabled = true; EnableSessionOpButtons(true); }); } } catch (Exception exception) { GuiUtils.HandleException(String.Empty, GuiUtils.CallerName(), exception); } finally { var ignored = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { progringConnection.IsActive = false; }); } }
private void ContextMenu_OnDelete(IUICommand command) { try { var monitoredItem = command.Id as MonitoredItem; if (monitoredItem == null) { return; } var subscription = monitoredItem.Subscription; SessionsCTRL.Delete(monitoredItem); if (subscription.MonitoredItemCount == 0) { // Remove subscription if no more items command.Id = subscription; ContextMenu_OnCancel(command); } } catch (Exception exception) { GuiUtils.HandleException(String.Empty, GuiUtils.CallerName(), exception); } }
/// <summary> /// Connects to a server. /// </summary> public async Task <bool> Connect(ConfiguredEndpoint endpoint) { bool result = false; if (endpoint == null) { return(false); } // connect dialogs Session session = await SessionsCTRL.Connect(endpoint); if (session != null) { //hook up new session session.KeepAlive += new KeepAliveEventHandler(StandardClient_KeepAlive); StandardClient_KeepAlive(session, null); result = true; } return(result); }
/// <summary> /// Connects to a server. /// </summary> public async void Connect(ConfiguredEndpoint endpoint) { if (endpoint == null) { return; } Session session = await SessionsCTRL.Connect(endpoint); if (session != null) { // stop any reconnect operation. if (m_reconnectHandler != null) { m_reconnectHandler.Dispose(); m_reconnectHandler = null; } m_session = session; m_session.KeepAlive += new KeepAliveEventHandler(StandardClient_KeepAlive); BrowseCTRL.SetView(m_session, BrowseViewType.Objects, null); StandardClient_KeepAlive(m_session, null); } }