/// <summary> /// Determines whether a counter has already been added to the Seleted List. /// </summary> /// <param name="searchItem"></param> /// <returns></returns> private bool CanAdd(PerfMonCounterData searchItem) { return(_selectedCounters.Where(c => c.TargetHost == searchItem.TargetHost && c.Category == searchItem.Category && c.InstanceName == searchItem.InstanceName && c.Counter == searchItem.Counter).FirstOrDefault() == null); }
/// <summary> /// Initialise using the saved data /// </summary> /// <param name="entity"></param> public override void Initialize(object entity) { _perfMonCollector = entity as PerfMonCollector; if (_perfMonCollector == null) { throw new ControlTypeMismatchException(entity, typeof(PerfMonCollector)); } //Bind to the controls that make sense name_TextBox.DataBindings.Add("Text", _perfMonCollector, "Name"); PopulateServerList(); //browse throught the virtual resource metadata and add them to our listbox foreach (VirtualResourceMetadata vmdata in _perfMonCollector.VirtualResourceMetadataSet) { PerfMonCounterData tempCounter = LegacySerializer.DeserializeXml <PerfMonCounterData>(vmdata.Metadata); tempCounter.VirtualResourceMetadataId = vmdata.VirtualResourceMetadataId; _selectedCountersDataList.Add(tempCounter); } platform_ComboBox.SetPlatform(_perfMonCollector.Platform, VirtualResourceType.PerfMonCollector); LoadSystemSetting(); selectedCounters_DataGridView.DataSource = _selectedCountersDataList; }
private void add_Button_Click(object sender, EventArgs e) { PerfMonCounterData selectedItem = _perfMonControl.SelectedItem; if (selectedItem != null && CanAdd(selectedItem)) { _selectedCounters.Add(selectedItem); } }
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); } }
private void remove_Button_Click(object sender, EventArgs e) { if (_selectedCounters.Count > 0) { if (selectedCounters_DataGridView.SelectedRows.Count > 0) { PerfMonCounterData dataItem = selectedCounters_DataGridView.SelectedRows[0].DataBoundItem as PerfMonCounterData; if (dataItem != null) { _selectedCounters.Remove(dataItem); } } else { MessageBox.Show(this, "Please select a counter to remove.", "Remove Selected Counter", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
public PerfMonCounterCollector(PerfMonCounterData counterConfig, string machineName) { _interval = new TimeSpan(0, 0, counterConfig.CollectionInterval); _counterConfig = counterConfig; _machineName = machineName; }