Example #1
0
        /// <summary>
        /// Connects to a endpoint.
        /// </summary>
        private void Connect(ConfiguredEndpoint endpoint, bool useAnsiCStack, ushort keySize)
        {
            try
            {
                TestEvent e = new TestEvent();

                e.Timestamp = DateTime.Now;
                e.TestId    = 0;
                e.Iteration = 0;
                e.EventType = TestEventType.Started;
                e.Details   = endpoint.ToString();

                this.TestEventsCTRL.AddEvent(e);

                CreateClient(useAnsiCStack, keySize);

                m_client.BeginExecuteTestSequence(endpoint);
                TestCancelMI.Enabled = true;
            }
            catch (Exception exception)
            {
                MessageBox.Show("Connect");
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
                TestCancelMI.Enabled = false;
            }
        }
        private void EndpointCB_PointerPressed(object sender, PointerRoutedEventArgs e)
        {
            ConfiguredEndpoint endpoint = EndpointCB.SelectedValue as ConfiguredEndpoint;

            if (endpoint != null)
            {
                InputTB.Text = endpoint.ToString();
            }
            else
            {
                InputTB.Text = "opc.tcp://";
            }
            InputTB.Visibility    = Visibility.Visible;
            EndpointCB.Visibility = Visibility.Collapsed;
        }
 private void InputTB_LostFocus(object sender, RoutedEventArgs e)
 {
     try
     {
         InputTB.Visibility    = Visibility.Collapsed;
         EndpointCB.Visibility = Visibility.Visible;
         ConfiguredEndpoint endpoint = EndpointCB.SelectedValue as ConfiguredEndpoint;
         if (endpoint == null ||
             InputTB.Text != endpoint.ToString())
         {
             endpoint         = m_endpoints.Create(InputTB.Text);
             SelectedEndpoint = endpoint;
         }
     }
     catch (Exception exception)
     {
         GuiUtils.HandleException(String.Empty, GuiUtils.CallerName(), exception);
     }
 }
        private void DiscoveryTreeView_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                if (DiscoveryTreeView.SelectedNode == null || !RootFolders.Add.Equals(DiscoveryTreeView.SelectedNode.Tag))
                {
                    return;
                }

                string url = new EndpointUrlDialog().ShowDialog(null);

                if (url != null)
                {
                    ConfiguredEndpoint ce = m_endpoints.Add(new EndpointDescription(url));
                    ce.Description.Server.ApplicationUri  = null;
                    ce.Description.Server.ApplicationName = null;

                    TreeNode node = new TreeNode(Utils.Format("{0}", ce.ToString()));
                    node.SelectedImageIndex = node.ImageIndex = ImageIndex.InSecure;
                    node.Tag = ce;

                    DiscoveryTreeView.SelectedNode.Parent.Nodes.Add(node);
                    DiscoveryTreeView.SelectedNode = node;

                    try
                    {
                        m_endpoints.Save();
                    }
                    catch
                    {
                        // ignore.
                    }
                }
            }
            catch (Exception ex)
            {
                Opc.Ua.Client.Controls.ExceptionDlg.Show(Text, ex);
            }
        }
Example #5
0
        /// <summary>
        /// Connects to a server.
        /// </summary>
        /// <param name="endpoint">The server endpoint</param>
        /// <param name="oldlvi">null if a new connection. non-null if an existing disconnected connection</param>
        public void Connect(ConfiguredEndpoint endpoint, ListViewItem oldlvi)
        {
            try
            {
                if (endpoint == null)
                {
                    return;
                }

                if (ServerListView.Items.ContainsKey(endpoint.ToString()))
                {
                    MessageBox.Show("endpoint already in use");
                    return;
                }

                ServerConnection connection = new ServerConnection(endpoint);

                if (connection.m_Endpoint.UpdateBeforeConnect)
                {
                    UpdateEndpoint(connection.m_Endpoint);
                }

                // create the channel.            
                connection.m_channel = SessionChannel.Create(
                    m_configuration,
                    connection.m_Endpoint.Description,
                    connection.m_Endpoint.Configuration,
                    m_bindingFactory,
                    m_configuration.SecurityConfiguration.ApplicationCertificate.Find(),
                    null);

                connection.m_session = new Session(connection.m_channel, m_configuration, connection.m_Endpoint);
                connection.m_session.ReturnDiagnostics = DiagnosticsMasks.All;

                // Set up good defaults 
                connection.m_session.DefaultSubscription.PublishingInterval = 1000;
                connection.m_session.DefaultSubscription.KeepAliveCount = 3;
                connection.m_session.DefaultSubscription.Priority = 0;
                connection.m_session.DefaultSubscription.PublishingEnabled = true;
                connection.m_session.DefaultSubscription.DefaultItem.SamplingInterval = 1000;

                if (new SessionOpenDlg().ShowDialog(connection.m_session, new List<string>()) == true)
                {

                    NodeId ServerStartTimeNodeId = new NodeId(Variables.Server_ServerStatus_StartTime);
                    NodeId ServerCurrentTimeNodeId = new NodeId(Variables.Server_ServerStatus_CurrentTime);
                    NodeId ServerStateNodeId = new NodeId(Variables.Server_ServerStatus_State);

                    // Save in the map
                    m_Connections.Add(connection.m_Endpoint.Description.EndpointUrl.ToString(), connection);
                    // Add to list control
                    ListViewItem lvi = ServerListView.Items.Add(connection.m_session.SessionId.ToString(), "", -1);
                    lvi.SubItems.Add("").Name = ServerStartTimeNodeId.Identifier.ToString();
                    lvi.SubItems.Add("").Name = ServerCurrentTimeNodeId.Identifier.ToString();
                    lvi.SubItems.Add("").Name = ServerStateNodeId.Identifier.ToString();
                    lvi.SubItems.Add("");
                    lvi.SubItems.Add("");
                    lvi.SubItems.Add("");
                    lvi.SubItems.Add("");
                    lvi.Tag = connection;
                    if (oldlvi != null)
                    {
                        ServerListView.Items.Remove(oldlvi);
                    }

                    connection.m_session.KeepAlive += new KeepAliveEventHandler(StandardClient_KeepAlive);
                    connection.m_Subscription = new Subscription(connection.m_session.DefaultSubscription);

                    connection.m_Subscription.DisplayName = connection.m_session.ToString();
                    bool bResult = connection.m_session.AddSubscription(connection.m_Subscription);
                    connection.m_Subscription.Create();

                    MonitoredItem startTimeItem = new MonitoredItem(connection.m_Subscription.DefaultItem);
                    INode node = connection.m_session.NodeCache.Find(ServerStartTimeNodeId);
                    startTimeItem.DisplayName = connection.m_session.NodeCache.GetDisplayText(node);
                    startTimeItem.StartNodeId = ServerStartTimeNodeId;
                    startTimeItem.NodeClass = (NodeClass)node.NodeClass;
                    startTimeItem.AttributeId = Attributes.Value;
                    connection.m_Subscription.AddItem(startTimeItem);
                    startTimeItem.Notification += m_ItemNotification;

                    MonitoredItem currentTimeItem = new MonitoredItem(connection.m_Subscription.DefaultItem);
                    INode currentTimeNode = connection.m_session.NodeCache.Find(ServerCurrentTimeNodeId);
                    currentTimeItem.DisplayName = connection.m_session.NodeCache.GetDisplayText(currentTimeNode);
                    currentTimeItem.StartNodeId = ServerCurrentTimeNodeId;
                    currentTimeItem.NodeClass = (NodeClass)currentTimeNode.NodeClass;
                    currentTimeItem.AttributeId = Attributes.Value;
                    connection.m_Subscription.AddItem(currentTimeItem);
                    currentTimeItem.Notification += m_ItemNotification;

                    MonitoredItem stateItem = new MonitoredItem(connection.m_Subscription.DefaultItem);
                    INode stateNode = connection.m_session.NodeCache.Find(ServerStateNodeId);
                    stateItem.DisplayName = connection.m_session.NodeCache.GetDisplayText(stateNode);
                    stateItem.StartNodeId = ServerStateNodeId;
                    stateItem.NodeClass = (NodeClass)stateNode.NodeClass;
                    stateItem.AttributeId = Attributes.Value;
                    connection.m_Subscription.AddItem(stateItem);
                    connection.m_Subscription.ApplyChanges();
                    stateItem.Notification += m_ItemNotification;
                }

            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }
Example #6
0
        /// <summary>
        /// Connects to a endpoint.
        /// </summary>
        private void Connect(ConfiguredEndpoint endpoint, bool useAnsiCStack, ushort keySize)
        {    
            try
            {
                TestEvent e = new TestEvent();

                e.Timestamp = DateTime.Now;
                e.TestId = 0;
                e.Iteration = 0;
                e.EventType = TestEventType.Started;
                e.Details = endpoint.ToString();

                this.TestEventsCTRL.AddEvent(e);

                CreateClient(useAnsiCStack, keySize);

                m_client.BeginExecuteTestSequence(endpoint);
                TestCancelMI.Enabled = true; 
            }
            catch (Exception exception)
            {
                MessageBox.Show("Connect");
				GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
                TestCancelMI.Enabled = false;
            }       
        }
Example #7
0
        /// <summary>
        /// Connects to a server.
        /// </summary>
        /// <param name="endpoint">The server endpoint</param>
        /// <param name="oldlvi">null if a new connection. non-null if an existing disconnected connection</param>
        public void Connect(ConfiguredEndpoint endpoint, ListViewItem oldlvi)
        {
            try
            {
                if (endpoint == null)
                {
                    return;
                }

                if (ServerListView.Items.ContainsKey(endpoint.ToString()))
                {
                    MessageBox.Show("endpoint already in use");
                    return;
                }

                ServerConnection connection = new ServerConnection(endpoint);

                if (connection.m_Endpoint.UpdateBeforeConnect)
                {
                    UpdateEndpoint(connection.m_Endpoint);
                }

                // create the channel.
                connection.m_channel = SessionChannel.Create(
                    m_configuration,
                    connection.m_Endpoint.Description,
                    connection.m_Endpoint.Configuration,
                    m_bindingFactory,
                    m_configuration.SecurityConfiguration.ApplicationCertificate.Find(),
                    null);

                connection.m_session = new Session(connection.m_channel, m_configuration, connection.m_Endpoint);
                connection.m_session.ReturnDiagnostics = DiagnosticsMasks.All;

                // Set up good defaults
                connection.m_session.DefaultSubscription.PublishingInterval           = 1000;
                connection.m_session.DefaultSubscription.KeepAliveCount               = 3;
                connection.m_session.DefaultSubscription.Priority                     = 0;
                connection.m_session.DefaultSubscription.PublishingEnabled            = true;
                connection.m_session.DefaultSubscription.DefaultItem.SamplingInterval = 1000;

                if (new SessionOpenDlg().ShowDialog(connection.m_session, new List <string>()) == true)
                {
                    NodeId ServerStartTimeNodeId   = new NodeId(Variables.Server_ServerStatus_StartTime);
                    NodeId ServerCurrentTimeNodeId = new NodeId(Variables.Server_ServerStatus_CurrentTime);
                    NodeId ServerStateNodeId       = new NodeId(Variables.Server_ServerStatus_State);

                    // Save in the map
                    m_Connections.Add(connection.m_Endpoint.Description.EndpointUrl.ToString(), connection);
                    // Add to list control
                    ListViewItem lvi = ServerListView.Items.Add(connection.m_session.SessionId.ToString(), "", -1);
                    lvi.SubItems.Add("").Name = ServerStartTimeNodeId.Identifier.ToString();
                    lvi.SubItems.Add("").Name = ServerCurrentTimeNodeId.Identifier.ToString();
                    lvi.SubItems.Add("").Name = ServerStateNodeId.Identifier.ToString();
                    lvi.SubItems.Add("");
                    lvi.SubItems.Add("");
                    lvi.SubItems.Add("");
                    lvi.SubItems.Add("");
                    lvi.Tag = connection;
                    if (oldlvi != null)
                    {
                        ServerListView.Items.Remove(oldlvi);
                    }

                    connection.m_session.KeepAlive += new KeepAliveEventHandler(StandardClient_KeepAlive);
                    connection.m_Subscription       = new Subscription(connection.m_session.DefaultSubscription);

                    connection.m_Subscription.DisplayName = connection.m_session.ToString();
                    bool bResult = connection.m_session.AddSubscription(connection.m_Subscription);
                    connection.m_Subscription.Create();

                    MonitoredItem startTimeItem = new MonitoredItem(connection.m_Subscription.DefaultItem);
                    INode         node          = connection.m_session.NodeCache.Find(ServerStartTimeNodeId);
                    startTimeItem.DisplayName = connection.m_session.NodeCache.GetDisplayText(node);
                    startTimeItem.StartNodeId = ServerStartTimeNodeId;
                    startTimeItem.NodeClass   = (NodeClass)node.NodeClass;
                    startTimeItem.AttributeId = Attributes.Value;
                    connection.m_Subscription.AddItem(startTimeItem);
                    startTimeItem.Notification += m_ItemNotification;

                    MonitoredItem currentTimeItem = new MonitoredItem(connection.m_Subscription.DefaultItem);
                    INode         currentTimeNode = connection.m_session.NodeCache.Find(ServerCurrentTimeNodeId);
                    currentTimeItem.DisplayName = connection.m_session.NodeCache.GetDisplayText(currentTimeNode);
                    currentTimeItem.StartNodeId = ServerCurrentTimeNodeId;
                    currentTimeItem.NodeClass   = (NodeClass)currentTimeNode.NodeClass;
                    currentTimeItem.AttributeId = Attributes.Value;
                    connection.m_Subscription.AddItem(currentTimeItem);
                    currentTimeItem.Notification += m_ItemNotification;

                    MonitoredItem stateItem = new MonitoredItem(connection.m_Subscription.DefaultItem);
                    INode         stateNode = connection.m_session.NodeCache.Find(ServerStateNodeId);
                    stateItem.DisplayName = connection.m_session.NodeCache.GetDisplayText(stateNode);
                    stateItem.StartNodeId = ServerStateNodeId;
                    stateItem.NodeClass   = (NodeClass)stateNode.NodeClass;
                    stateItem.AttributeId = Attributes.Value;
                    connection.m_Subscription.AddItem(stateItem);
                    connection.m_Subscription.ApplyChanges();
                    stateItem.Notification += m_ItemNotification;
                }
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }