File: AddSet.cs

package info (click to toggle)
mono-tools 4.2-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 13,868 kB
  • sloc: cs: 100,909; sh: 3,845; makefile: 2,040; xml: 126
file content (72 lines) | stat: -rw-r--r-- 1,547 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Author: lupus 9/23/2008
//
//

using System;
using System.Diagnostics;
using Gtk;

namespace mperfmon
{
	
	
	public partial class AddSet : Gtk.Dialog
	{
		string csetn;
		string instance;
		TreeStore instances_store;
		Config cfg;
		
		public AddSet(Config cfg)
		{
			this.cfg = cfg;
			this.Build();
			CellRendererText renderer = new CellRendererText ();
			instances.AppendColumn ("Instance", renderer, "text", 0);
			instances_store = new TreeStore (typeof (string));
			instances.Model = instances_store;
			for (int i = 0; i <  cfg.sets.Count; ++i) {
				counterset.AppendText (cfg.sets [i].Name);
			}
			instances.Selection.Changed += delegate {
				TreeSelection ts = instances.Selection;
				TreeIter iter;
				TreeModel mod;
				if (ts.GetSelected (out mod, out iter)) {
					instance = mod.GetValue (iter, 0) as string;
				}
			};
			if (cfg.sets.Count > 0) {
				counterset.Active = 0;
			}
		}

		protected virtual void OnSetSelected (object sender, System.EventArgs e)
		{
			instances_store.Clear ();
			CounterSet cset = cfg.sets [counterset.Active];
			csetn = cset.Name;
			try {
				// we take just the first counter category into consideration
				// to retrieve an instance
				PerformanceCounterCategory cat = new PerformanceCounterCategory (cset.Counters [0]);
				foreach (string s in cat.GetInstanceNames ()) {
					instances_store.AppendValues (s);
				}
			} catch {
			}
		}

		public string CounterSet {
			get {
				return csetn;
			}
		}

		public string Instance {
			get {
				return instance;
			}
		}
	}
}