/// <summary>
        /// Displays the event categories supported by the server.
        /// </summary>
        public void ShowDialog(TsCAeServer server)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            // clear list view.
            categoriesLv_.Clear();

            // add columns.
            AddHeader("ID");
            AddHeader("Name");
            AddHeader("Event Type");

            // fetch and populate categories.
            try
            {
                FetchCategories(server, TsCAeEventType.Simple);
                FetchCategories(server, TsCAeEventType.Tracking);
                FetchCategories(server, TsCAeEventType.Condition);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, Text);
            }

            // adjust column widths.
            AdjustColumns();

            // show dialog.
            ShowDialog();
        }
Exemple #2
0
        /// <summary>
        /// Displays current subscriptions for the server.
        /// </summary>
        public void ShowSubscriptions(TsCAeServer server)
        {
            m_server = server;

            SubscriptionsLV.Items.Clear();

            // nothing more to do if no server provided.
            if (m_server == null)
            {
                return;
            }

            // add subscriptions.
            foreach (Ae.TsCAeSubscription subscription in m_server.Subscriptions)
            {
                Add(subscription);

                // send notifications.
                if (subscription.Active)
                {
                    if (m_SubscriptionAction != null)
                    {
                        m_SubscriptionAction(subscription, false);
                    }
                }
            }

            // adjust columns.
            AdjustColumns(SubscriptionsLV);
        }
        /// <summary>
        /// Displays the area hierarchy for the server.
        /// </summary>
        public void ShowAreas(TsCAeServer server)
        {
            m_server = server;

            BrowseTV.Nodes.Clear();

            // nothing more to do if no server provided.
            if (m_server == null)
            {
                return;
            }

            // create root node.
            TreeNode root = new TreeNode(m_server.ServerName);

            root.ImageIndex         = Resources.IMAGE_LOCAL_SERVER;
            root.SelectedImageIndex = Resources.IMAGE_LOCAL_SERVER;
            root.Tag = m_server;

            BrowseTV.Nodes.Add(root);

            // browse top level areas.
            BrowseArea(root.Nodes, OpcClientSdk.Ae.TsCAeBrowseType.Area, null);

            // browse top level sources.
            BrowseArea(root.Nodes, OpcClientSdk.Ae.TsCAeBrowseType.Source, null);

            // expand root node.
            root.Expand();
        }
        /// <summary>
        /// Called to disconnect from a server.
        /// </summary>
        public void OnDisconnect()
        {
            try
            {
                // close notification callbacks.
                eventListCtrl_.RemoveSubscriptions();

                // disconnect server.
                if (server_ != null)
                {
                    try { server_.Disconnect(); }
                    catch { }

                    server_.Dispose();
                    server_ = null;
                }

                // uninitialize controls.
                statusCtrl_.Start(null);
                subscriptionsCtrl_.ShowSubscriptions(null);
                outputCtrl_.Text = "";
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Disconnect Server Failed");
            }
        }
 /// <summary>
 /// Called when the Server | Connect menu item is clicked.
 /// </summary>
 private void ConnectMI_Click(object sender, EventArgs e)
 {
     if (server_ == null)
     {
         server_ = (TsCAeServer) new SelectServerDlg().ShowDialog(OpcSpecification.OPC_AE_10);
     }
     OnConnect();
 }
Exemple #6
0
        /// <summary>
        /// Displays the area and event hierarchies for the server.
        /// </summary>
        /// <param name="server"></param>
        public void ShowEventsAndAreas(TsCAeServer server)
        {
            mServer_ = server;

            browseTv_.Nodes.Clear();

            // nothing more to do if no server provided.
            if (mServer_ == null)
            {
                return;
            }

            // create root node.
            TreeNode root = new TreeNode(mServer_.ServerName)
            {
                ImageIndex         = Resources.IMAGE_LOCAL_SERVER,
                SelectedImageIndex = Resources.IMAGE_LOCAL_SERVER,
                Tag = mServer_
            };

            browseTv_.Nodes.Add(root);

            // create events node.
            TreeNode events = new TreeNode(EventsText)
            {
                ImageIndex         = Resources.IMAGE_OPEN_YELLOW_FOLDER,
                SelectedImageIndex = Resources.IMAGE_CLOSED_YELLOW_FOLDER,
                Tag = EventsText
            };

            // browse event categories
            BrowseEvents(events.Nodes, TsCAeEventType.Simple);
            BrowseEvents(events.Nodes, TsCAeEventType.Tracking);
            BrowseEvents(events.Nodes, TsCAeEventType.Condition);

            root.Nodes.Add(events);

            // create areas node.
            TreeNode areas = new TreeNode(AreasText)
            {
                ImageIndex         = Resources.IMAGE_OPEN_YELLOW_FOLDER,
                SelectedImageIndex = Resources.IMAGE_CLOSED_YELLOW_FOLDER,
                Tag = AreasText
            };

            root.Nodes.Add(areas);

            // browse top level areas.
            BrowseArea(areas.Nodes, Technosoftware.DaAeHdaClient.Ae.TsCAeBrowseType.Area, null);

            // browse top level sources.
            BrowseArea(areas.Nodes, Technosoftware.DaAeHdaClient.Ae.TsCAeBrowseType.Source, null);

            // expand root node.
            root.Expand();
        }
        /// <summary>
        /// Shows the available categories in the control.
        /// </summary>
        public void ShowCategories(TsCAeServer server)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            mServer_ = server;

            ShowAvailableCategories();
        }
        /// <summary>
        /// Displays the area and event hierarchies for the server.
        /// </summary>
        /// <param name="server"></param>
        public void ShowEventsAndAreas(TsCAeServer server)
        {
            m_server = server;

            BrowseTV.Nodes.Clear();

            // nothing more to do if no server provided.
            if (m_server == null)
            {
                return;
            }

            // create root node.
            TreeNode root = new TreeNode(m_server.ServerName);

            root.ImageIndex         = Resources.IMAGE_LOCAL_SERVER;
            root.SelectedImageIndex = Resources.IMAGE_LOCAL_SERVER;
            root.Tag = m_server;

            BrowseTV.Nodes.Add(root);

            // create events node.
            TreeNode events = new TreeNode(EVENTS);

            events.ImageIndex         = Resources.IMAGE_OPEN_YELLOW_FOLDER;
            events.SelectedImageIndex = Resources.IMAGE_CLOSED_YELLOW_FOLDER;
            events.Tag = EVENTS;

            // browse event categories
            BrowseEvents(events.Nodes, TsCAeEventType.Simple);
            BrowseEvents(events.Nodes, TsCAeEventType.Tracking);
            BrowseEvents(events.Nodes, TsCAeEventType.Condition);

            root.Nodes.Add(events);

            // create areas node.
            TreeNode areas = new TreeNode(AREAS);

            areas.ImageIndex         = Resources.IMAGE_OPEN_YELLOW_FOLDER;
            areas.SelectedImageIndex = Resources.IMAGE_CLOSED_YELLOW_FOLDER;
            areas.Tag = AREAS;

            root.Nodes.Add(areas);

            // browse top level areas.
            BrowseArea(areas.Nodes, OpcClientSdk.Ae.TsCAeBrowseType.Area, null);

            // browse top level sources.
            BrowseArea(areas.Nodes, OpcClientSdk.Ae.TsCAeBrowseType.Source, null);

            // expand root node.
            root.Expand();
        }
Exemple #9
0
        /// <summary>
        /// Displays the filters supported by the server.
        /// </summary>
        public void ShowDialog(TsCAeServer server)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            FiltersCTRL.ReadOnly = true;
            FiltersCTRL.Type     = typeof(TsCAeFilterType);
            FiltersCTRL.Value    = server.QueryAvailableFilters();

            ShowDialog();
        }
        /// <summary>
        /// Displays the current server status in a modal dialog.
        /// </summary>
        public void ShowDialog(TsCAeServer server)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            m_server = server;

            GetStatus();

            ShowDialog();
        }
Exemple #11
0
        /// <summary>
        /// Prompts a user to create a new subscription with a modal dialog.
        /// </summary>
        public Ae.TsCAeSubscription ShowDialog(TsCAeServer server, Ae.TsCAeSubscription subscription)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            m_server       = server;
            m_subscription = subscription;

            // go to the initial stage.
            m_stage = 0;
            ChangeStage(0);

            // initialize controls.
            StateCTRL.SetDefaults();
            FiltersCTRL.SetDefaults();
            CategoriesCTRL.ShowCategories(m_server);
            AttributesCTRL.ShowAttributes(m_server);
            BrowseCTRL.ShowAreas(m_server);

            if (m_subscription != null)
            {
                m_state      = m_subscription.GetState();
                m_filters    = m_subscription.GetFilters();
                m_attributes = m_subscription.GetAttributes();
                m_areas      = m_subscription.Areas.ToArray();
                m_sources    = m_subscription.Sources.ToArray();
            }
            else
            {
                m_state.Name = String.Format("Subscription{0,3:000}", ++m_count);
            }

            // set current values.
            StateCTRL.Set(m_state);
            FiltersCTRL.Set(m_filters);
            CategoriesCTRL.SetSelectedCategories(m_filters.Categories.ToArray());
            AttributesCTRL.SetSelectedAttributes(m_attributes);
            AreaSourcesListCTRL.AddAreas(m_areas);
            AreaSourcesListCTRL.AddSources(m_sources);

            // show dialog.
            if (ShowDialog() != DialogResult.OK)
            {
                return(null);
            }

            // return updated/created subscription.
            return(m_subscription);
        }
Exemple #12
0
        /// <summary>
        /// Prompts a user to create a new subscription with a modal dialog.
        /// </summary>
        public TsCAeSubscription ShowDialog(TsCAeServer server, TsCAeSubscription subscription)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            mServer_       = server;
            mSubscription_ = subscription;

            // go to the initial stage.
            mStage_ = 0;
            ChangeStage(0);

            // initialize controls.
            stateCtrl_.SetDefaults();
            filtersCtrl_.SetDefaults();
            categoriesCtrl_.ShowCategories(mServer_);
            attributesCtrl_.ShowAttributes(mServer_);
            browseCtrl_.ShowAreas(mServer_);

            if (mSubscription_ != null)
            {
                mState_      = mSubscription_.GetState();
                mFilters_    = mSubscription_.GetFilters();
                mAttributes_ = mSubscription_.GetAttributes();
                mAreas_      = mSubscription_.Areas.ToArray();
                mSources_    = mSubscription_.Sources.ToArray();
            }
            else
            {
                mState_.Name = String.Format("Subscription{0,3:000}", ++mCount_);
            }

            // set current values.
            stateCtrl_.Set(mState_);
            filtersCtrl_.Set(mFilters_);
            categoriesCtrl_.SetSelectedCategories(mFilters_.Categories.ToArray());
            attributesCtrl_.SetSelectedAttributes(mAttributes_);
            areaSourcesListCtrl_.AddAreas(mAreas_);
            areaSourcesListCtrl_.AddSources(mSources_);

            // show dialog.
            if (ShowDialog() != DialogResult.OK)
            {
                return(null);
            }

            // return updated/created subscription.
            return(mSubscription_);
        }
Exemple #13
0
		/// <summary>
		/// Displays the event conditions supported by the server.
		/// </summary>
		public void ShowDialog(TsCAeServer server, bool modal)
		{
			if (server == null) throw new ArgumentNullException("server");

			BrowseCTRL.ShowAreas(server);

			if (modal)
			{
				ShowDialog();
			}
			else
			{
				Show();
			}
		}
        /// <summary>
        /// Populates the tree view with the sub-conditions.
        /// </summary>
        private void FetchSubConditions(TreeNode parent, TsCAeServer server, string conditionName)
        {
            string[] subconditions = server.QuerySubConditionNames(conditionName);

            for (int ii = 0; ii < subconditions.Length; ii++)
            {
                TreeNode node = new TreeNode(subconditions[ii]);

                node.ImageIndex         = Resources.IMAGE_YELLOW_SCROLL;
                node.SelectedImageIndex = Resources.IMAGE_YELLOW_SCROLL;
                node.Tag = subconditions[ii];

                parent.Nodes.Add(node);
            }
        }
Exemple #15
0
        /// <summary>
        /// Populates the list box with the categories.
        /// </summary>
        private void FetchCategories(TsCAeServer server, TsCAeEventType eventType)
        {
            OpcClientSdk.Ae.TsCAeCategory[] categories = server.QueryEventCategories((int)eventType);

            foreach (OpcClientSdk.Ae.TsCAeCategory category in categories)
            {
                ListViewItem item = new ListViewItem(category.ID.ToString());

                item.SubItems.Add(category.Name);
                item.SubItems.Add(eventType.ToString());

                item.Tag = category;

                CategoriesLV.Items.Add(item);
            }
        }
        /// <summary>
        /// Populates the list box with the categories.
        /// </summary>
        private void FetchCategories(TsCAeServer server, TsCAeEventType eventType)
        {
            Technosoftware.DaAeHdaClient.Ae.TsCAeCategory[] categories = server.QueryEventCategories((int)eventType);

            foreach (Technosoftware.DaAeHdaClient.Ae.TsCAeCategory category in categories)
            {
                ListViewItem item = new ListViewItem(category.ID.ToString());

                item.SubItems.Add(category.Name);
                item.SubItems.Add(eventType.ToString());

                item.Tag = category;

                categoriesLv_.Items.Add(item);
            }
        }
        /// <summary>
        /// Begins polling the status of the server.
        /// </summary>
        public void Start(TsCAeServer server)
        {
            m_server = server;

            if (m_server == null)
            {
                UpdateTimer.Enabled = false;
                ShowPanels          = false;
                Text = "Server not connected.";
            }
            else
            {
                UpdateTimer.Enabled = true;
                UpdateTimer_Tick(this, null);
            }
        }
Exemple #18
0
        /// <summary>
        /// Displays the available attributes in a heirarchy.
        /// </summary>
        public void ShowAttributes(TsCAeServer server)
        {
            mServer_ = server;

            attributesTv_.Nodes.Clear();

            // nothing more to do if no server provided.
            if (mServer_ == null)
            {
                return;
            }

            // display all event categories
            ShowEventCategories(attributesTv_.Nodes, TsCAeEventType.Simple);
            ShowEventCategories(attributesTv_.Nodes, TsCAeEventType.Tracking);
            ShowEventCategories(attributesTv_.Nodes, TsCAeEventType.Condition);
        }
        /// <summary>
        /// Creates a server object for the specified URL.
        /// </summary>
        public static OpcServer GetServerForURL(OpcUrl url)
        {
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }

            OpcServer server = null;

            // create an unconnected server object for XML based servers.
            if (url.Scheme == OpcUrlScheme.HTTP)
            {
                new NotSupportedException("XML not supported with .NET 4.6 and later.");
            }

            // create an unconnected server object for COM based servers.
            else
            {
                // DA
                if (url.Scheme == OpcUrlScheme.DA)
                {
                    server = new TsCDaServer(new Technosoftware.DaAeHdaClient.Com.Factory(), url);
                }

                // AE
                else if (url.Scheme == OpcUrlScheme.AE)
                {
                    server = new TsCAeServer(new Technosoftware.DaAeHdaClient.Com.Factory(), url);
                }

                // HDA
                else if (url.Scheme == OpcUrlScheme.HDA)
                {
                    server = new TsCHdaServer(new Technosoftware.DaAeHdaClient.Com.Factory(), url);
                }

                // Other specifications not supported yet.
                else
                {
                    throw new NotSupportedException(url.Scheme);
                }
            }

            return(server);
        }
        /// <summary>
        /// Populates the tree view with the conditions.
        /// </summary>
        private void FetchConditions(TreeNode parent, TsCAeServer server, int categoryID)
        {
            string[] conditions = server.QueryConditionNames(categoryID);

            for (int ii = 0; ii < conditions.Length; ii++)
            {
                TreeNode node = new TreeNode(conditions[ii]);

                node.ImageIndex         = Resources.IMAGE_YELLOW_SCROLL;
                node.SelectedImageIndex = Resources.IMAGE_YELLOW_SCROLL;
                node.Tag = conditions[ii];

                // add sub-conditions.
                FetchSubConditions(node, server, conditions[ii]);

                parent.Nodes.Add(node);
            }
        }
        /// <summary>
        /// Called to connect to a server.
        /// </summary>
        public void OnConnect()
        {
            Cursor = Cursors.WaitCursor;

            try
            {
                OpcUserIdentity credentials = null;

                do
                {
                    try
                    {
                        m_server.Connect(new OpcConnectData(credentials, m_proxy));
                        break;
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message);
                    }

                    credentials = new NetworkCredentialsDlg().ShowDialog(credentials);
                }while (credentials != null);

                // initialize controls.
                SelectServerCTRL.OnConnect(m_server);
                StatusCTRL.Start(m_server);
                SubscriptionsCTRL.ShowSubscriptions(m_server);

                // register for shutdown events.
                m_server.ServerShutdownEvent += new OpcServerShutdownEventHandler(Server_ServerShutdown);

                // save settings.
                SaveSettings();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "On Connect");
                m_server = null;
            }

            Cursor = Cursors.Default;
        }
Exemple #22
0
        /// <summary>
        /// Displays the condition state for specified source and condition.
        /// </summary>
        public void ShowDialog(TsCAeServer server, string source, string condition)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            mServer_    = server;
            mSource_    = source;
            mCondition_ = condition;

            // find attributes for condition.
            FindAttributes();

            // get the current enabled state.
            ShowCondition();

            // show the dialog.
            Show();
        }
        /// <summary>
        /// Populates the tree view with the attributes.
        /// </summary>
        private void FetchAttributes(TreeNode parent, TsCAeServer server, int categoryID)
        {
            OpcClientSdk.Ae.TsCAeAttribute[] attributes = server.QueryEventAttributes(categoryID);

            foreach (OpcClientSdk.Ae.TsCAeAttribute attribute in attributes)
            {
                string label = String.Format(
                    "[{0}] {1} ({2})",
                    attribute.ID,
                    attribute.Name,
                    OpcClientSdk.OpcConvert.ToString(attribute.DataType));

                TreeNode node = new TreeNode(label);

                node.ImageIndex         = Resources.IMAGE_EXPLODING_BOX;
                node.SelectedImageIndex = Resources.IMAGE_EXPLODING_BOX;
                node.Tag = attribute;

                parent.Nodes.Add(node);
            }
        }
        /// <summary>
        /// Populates the tree view with the attributes.
        /// </summary>
        private void FetchAttributes(TreeNode parent, TsCAeServer server, int categoryId)
        {
            Technosoftware.DaAeHdaClient.Ae.TsCAeAttribute[] attributes = server.QueryEventAttributes(categoryId);

            foreach (Technosoftware.DaAeHdaClient.Ae.TsCAeAttribute attribute in attributes)
            {
                string label = String.Format(
                    "[{0}] {1} ({2})",
                    attribute.ID,
                    attribute.Name,
                    Technosoftware.DaAeHdaClient.OpcConvert.ToString(attribute.DataType));

                TreeNode node = new TreeNode(label)
                {
                    ImageIndex         = Resources.IMAGE_EXPLODING_BOX,
                    SelectedImageIndex = Resources.IMAGE_EXPLODING_BOX,
                    Tag = attribute
                };

                parent.Nodes.Add(node);
            }
        }
        /// <summary>
        /// Called to connect to a server.
        /// </summary>
        public void OnConnect(OpcClientSdk.OpcServer server)
        {
            // disconnect from the current server.
            OnDisconnect();

            // create a default file name for the server.
            m_configFile = server.ServerName + ".config";

            // load server object from config file if it exists.
            if (File.Exists(m_configFile))
            {
                if (OnLoad(false, server.Url))
                {
                    return;
                }
            }

            // use the specified server object directly.
            m_server = (TsCAeServer)server;

            // connect with an empty configuration.
            OnConnect();
        }
Exemple #26
0
        /// <summary>
        /// Prompts the user to select the enabled state.
        /// </summary>
        public bool ShowDialog(
            TsCAeServer server,
            Technosoftware.DaAeHdaClient.Ae.TsCAeBrowseElement element,
            out bool enabled,
            ref bool recursive)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            mServer_ = server;

            // get current enabled state.
            enabledChk_.Checked = enabled = GetEnabledState(element);

            if (element != null)
            {
                recursiveChk_.Checked = recursive;
                recursiveChk_.Enabled = true;
            }
            else
            {
                recursiveChk_.Checked = true;
                recursiveChk_.Enabled = false;
            }

            // show dialog.
            if (ShowDialog() == DialogResult.OK)
            {
                enabled   = enabledChk_.Checked;
                recursive = recursiveChk_.Checked;
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Prompts the user to select the enabled state.
        /// </summary>
        public bool ShowDialog(
            TsCAeServer server,
            OpcClientSdk.Ae.TsCAeBrowseElement element,
            out bool enabled,
            ref bool recursive)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            m_server = server;

            // get current enabled state.
            EnabledCHK.Checked = enabled = GetEnabledState(element);

            if (element != null)
            {
                RecursiveCHK.Checked = recursive;
                RecursiveCHK.Enabled = true;
            }
            else
            {
                RecursiveCHK.Checked = true;
                RecursiveCHK.Enabled = false;
            }

            // show dialog.
            if (ShowDialog() == DialogResult.OK)
            {
                enabled   = EnabledCHK.Checked;
                recursive = RecursiveCHK.Checked;
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Displays the enabled states for the specified browse elements.
        /// </summary>
        public void ShowDialog(TsCAeServer server, OpcClientSdk.Ae.TsCAeBrowseElement[] elements)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            m_server = server;

            // sort elements in areas and sources.
            m_areas.Clear();
            m_sources.Clear();

            for (int ii = 0; ii < elements.Length; ii++)
            {
                if (elements[ii].NodeType == OpcClientSdk.Ae.TsCAeBrowseType.Area)
                {
                    if (!m_areas.Contains(elements[ii].QualifiedName))
                    {
                        m_areas.Add(elements[ii].QualifiedName);
                    }
                }
                else
                {
                    if (!m_sources.Contains(elements[ii].QualifiedName))
                    {
                        m_sources.Add(elements[ii].QualifiedName);
                    }
                }
            }

            // get the current enabled state.
            GetEnabledState();

            // show the dialog.
            Show();
        }
        /// <summary>
        /// Displays the event conditions supported by the server.
        /// </summary>
        public void ShowDialog(TsCAeServer server)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            // clear tree view.
            ConditionsTV.Nodes.Clear();

            // fetch and populate conditions and sub-conditions.
            try
            {
                TreeNode root = new TreeNode("Categories");

                root.ImageIndex         = Resources.IMAGE_CLOSED_YELLOW_FOLDER;
                root.SelectedImageIndex = Resources.IMAGE_OPEN_YELLOW_FOLDER;

                ConditionsTV.Nodes.Add(root);
                root.Expand();

                // add categories.
                OpcClientSdk.Ae.TsCAeCategory[] categories = server.QueryEventCategories((int)TsCAeEventType.Condition);

                foreach (OpcClientSdk.Ae.TsCAeCategory category in categories)
                {
                    TreeNode node = new TreeNode(category.Name);

                    node.ImageIndex         = Resources.IMAGE_LIST_BOX;
                    node.SelectedImageIndex = Resources.IMAGE_LIST_BOX;
                    node.Tag = category;

                    // add conditions.
                    TreeNode folder = new TreeNode("Conditions");

                    folder.ImageIndex         = Resources.IMAGE_CLOSED_YELLOW_FOLDER;
                    folder.SelectedImageIndex = Resources.IMAGE_OPEN_YELLOW_FOLDER;

                    node.Nodes.Add(folder);

                    FetchConditions(folder, server, category.ID);

                    // add attributes.
                    folder = new TreeNode("Attributes");

                    folder.ImageIndex         = Resources.IMAGE_CLOSED_YELLOW_FOLDER;
                    folder.SelectedImageIndex = Resources.IMAGE_OPEN_YELLOW_FOLDER;

                    node.Nodes.Add(folder);

                    FetchAttributes(folder, server, category.ID);

                    // add category to tree.
                    root.Nodes.Add(node);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, this.Text);
            }

            // show dialog.
            ShowDialog();
        }
        public void Run()
        {
            try
            {
                const string serverUrl = "opcae://localhost/Technosoftware.AeSample";

                Console.WriteLine();
                Console.WriteLine("Simple OPC AE Client based on the OPC AE Client SDK .NET Standard");
                Console.WriteLine("-----------------------------------------------------------------");
                Console.Write("   Press <Enter> to connect to "); Console.WriteLine(serverUrl);
                Console.ReadLine();
                Console.WriteLine("   Please wait...");

                TsCAeServer myAeServer = new TsCAeServer();

                // Connect to the server
                myAeServer.Connect(serverUrl);

                Console.WriteLine("   Connected, press <Enter> to create an active subscription and press <Enter>");
                Console.WriteLine("   again to deactivate the subscription. This stops the reception of new events.");
                Console.ReadLine();

                TsCAeSubscriptionState state = new TsCAeSubscriptionState {
                    Active = true, BufferTime = 0, MaxSize = 0, ClientHandle = 100, Name = "Simple Event Subscription"
                };

                TsCAeCategory[]  categories = myAeServer.QueryEventCategories((int)TsCAeEventType.Condition);
                TsCAeAttribute[] attributes = null;
                attributes = myAeServer.QueryEventAttributes(categories[0].ID);

                int[] attributeIDs = new int[2];

                attributeIDs[0] = attributes[0].ID;
                attributeIDs[1] = attributes[1].ID;

                TsCAeSubscription subscription;
                subscription = (TsCAeSubscription)myAeServer.CreateSubscription(state);
                subscription.DataChangedEvent += OnDataChangedEvent;
                subscription.SelectReturnedAttributes(categories[0].ID, attributeIDs);
                Console.ReadLine();

                subscription.DataChangedEvent -= OnDataChangedEvent;
                Console.WriteLine("   Subscription deactivated, press <Enter> to remove the subscription and disconnect from the server.");

                subscription.Dispose();                                                                 // Remove subscription
                myAeServer.Disconnect();                                                                // Disconnect from server
                myAeServer.Dispose();                                                                   // Dispose server object

                Console.ReadLine();
                Console.WriteLine("   Disconnected from the server.");
                Console.WriteLine();
            }
            catch (OpcResultException e)
            {
                Console.WriteLine(String.Format("   {0}", e.Message));
                Console.ReadLine();
                return;
            }
            catch (Exception e)
            {
                Console.WriteLine(String.Format("   {0}", e.Message));
                Console.ReadLine();
                return;
            }
        }