private void instance_ListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            addCounter_ToolStripButton.Enabled = false;

            if (instance_ListBox.SelectedIndex < 0)
            {
                return;
            }

            counter_ListBox.DataSource = null;
            counter_ListBox.Items.Clear();
            counter_ListBox.SelectedIndexChanged -= counter_ListBox_SelectedIndexChanged;
            addCounter_ToolStripButton.Enabled    = false;

            if (_loadFromMachine)
            {
                LoadCounters(_selectedServer.HostName);
            }
            else
            {
                if (SelectedCategory.ToString() == PrintQueueCategory)
                {
                    LoadCounters(PrintQueueCategory);
                }
                else
                {
                    LoadCounters(SelectedInstance);
                }
            }
            counter_ListBox.SelectedIndexChanged += counter_ListBox_SelectedIndexChanged;
        }
        private void addCounter_ToolStripButton_Click(object sender, EventArgs e)
        {
            if (ValidateSelection())
            {
                PerfMonCounterData tempCounterData = new PerfMonCounterData();

                if (_loadFromMachine)
                {
                    PerformanceCounter selectedCounter = SelectedCounter as PerformanceCounter;
                    tempCounterData.Category     = selectedCounter.CategoryName;
                    tempCounterData.Counter      = selectedCounter.CounterName;
                    tempCounterData.InstanceName = selectedCounter.InstanceName;
                }
                else
                {
                    string selectedInstance = SelectedInstance;
                    tempCounterData.Category = SelectedCategory.ToString();
                    tempCounterData.Counter  = ((ResourceWindowsCategory)SelectedCounter).Name;
                    /// Don't insert "N/A" into the counter data, use empty string instead.
                    tempCounterData.InstanceName = (selectedInstance == PerfMonController.InstanceDoesNotApply) ? string.Empty : selectedInstance;
                }

                tempCounterData.TargetHost = _selectedServer.HostName;

                //if the user has entered the username and password then use it
                if (!string.IsNullOrEmpty(userName_textBox.Text) || !string.IsNullOrEmpty(password_textBox.Text))
                {
                    tempCounterData.Credentials = new PerfMonCounterCredential(userName_textBox.Text, password_textBox.Text, string.IsNullOrEmpty(domain_textBox.Text) ? "." : domain_textBox.Text);
                }
                else
                {
                    tempCounterData.Credentials = new PerfMonCounterCredential();
                }

                tempCounterData.Interval = interval_TimeSpanControl.Value.TotalMilliseconds;

                VirtualResourceMetadata tempMetaData = new VirtualResourceMetadata(VirtualResourceType.PerfMonCollector.ToString(), "PerfMonCounter");

                //associate the GUID of the tempMetaData to the perfmoncounterdata item
                tempCounterData.VirtualResourceMetadataId = tempMetaData.VirtualResourceMetadataId;

                tempMetaData.VirtualResourceId = _perfMonCollector.VirtualResourceId;
                tempMetaData.Name = tempCounterData.TargetHost + "-" + tempCounterData.Category + "/" + tempCounterData.InstanceName + "/" + tempCounterData.Counter;
                string metadataxml = LegacySerializer.SerializeXml(tempCounterData).ToString();
                tempMetaData.Metadata = metadataxml;

                //we are not currently connected to DB or using the existing data, so add this to the virtual resource metadata collection
                _perfMonCollector.VirtualResourceMetadataSet.Add(tempMetaData);
                _perfMonCollector.Platform = (string)platform_ComboBox.SelectedValue;

                //populate the listview in the newly added item
                _selectedCountersDataList.Add(tempCounterData);
            }
        }
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            StoreCategories();

            // Fire the CategorySelected event...
            var args = new CommandEventArgs(SelectedCategory.ToString(), null);

            if (CategorySelectedChangedEvent != null)
            {
                CategorySelectedChangedEvent(this, args);
            }
        }
        private void category_ListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (category_ListBox.SelectedIndex > -1)
            {
                instance_ListBox.SelectedIndexChanged -= instance_ListBox_SelectedIndexChanged;
                instance_ListBox.DataSource            = null;

                if (_loadFromMachine)
                {
                    LoadInstances(SelectedCategory as PerformanceCounterCategory);
                }
                else
                {
                    LoadInstances(SelectedCategory.ToString(), _selectedServer.HostName);
                }
                instance_ListBox.SelectedIndexChanged += instance_ListBox_SelectedIndexChanged;
            }
        }
        private void OnInfoTapped(Category categoryTapped)
        {
            string selectedCategoryString = SelectedCategory == null ? "null" : SelectedCategory.ToString();

            Debug.WriteLine($"**** {this.GetType().Name}.{nameof(OnInfoTapped)}:  {categoryTapped}\n\tFYI, the SelectedPerson is {selectedCategoryString}");
        }