Click here to Skip to main content
15,886,006 members
Articles / Desktop Programming / XAML

Diagnostic Explorer

Rate me:
Please Sign up or sign in to vote.
4.93/5 (41 votes)
29 Nov 2010LGPL315 min read 82.3K   1.5K   120  
A .NET library and website which allows developers to expose and view arbitrary diagnostic information about their .NET processes.
using System;
using System.Collections.ObjectModel;
using System.Linq;

namespace DiagnosticExplorer.Silverlight
{
	public class DiagCat
	{
		private const StringComparison _ignoreCase = StringComparison.CurrentCultureIgnoreCase;
		public ObservableCollection<DiagSink> Sinks { get; set; }
		public ObservableCollection<DiagBag> Bags { get; set; }

		public DiagCat(string name)
		{
			Name = name;
			Bags = new ObservableCollection<DiagBag>();
			Sinks = new ObservableCollection<DiagSink>();
		}

		public string Name { get; private set; }

		public DiagSink FindSink(string name, bool createIfNotFound)
		{
			DiagSink sink = Sinks.FirstOrDefault(s => string.Equals(s.Name, name, _ignoreCase));
			if (sink == null && createIfNotFound)
			{
				sink = new DiagSink(name);
				Sinks.Add(sink);
			}

			return sink;
		}

		public void Merge(DiagCat cat2)
		{
			foreach (DiagBag bag in cat2.Bags)
				FindBag(bag.Name, true).Merge(bag);

			for (int i = Bags.Count - 1; i >= 0; i--)
				if (cat2.FindBag(Bags[i].Name, false) == null)
					Bags.RemoveAt(i);


			foreach (DiagSink sink in cat2.Sinks)
				FindSink(sink.Name, true).Merge(sink);
		}

		public DiagBag FindBag(string name, bool createIfNotFound)
		{
			DiagBag bag = Bags.FirstOrDefault(b => string.Equals(b.Name, name, _ignoreCase));
			if (bag == null && createIfNotFound)
			{
				bag = new DiagBag(name);
				Bags.Add(bag);
			}
			return bag;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Software Developer
United Kingdom United Kingdom
I am a software developer originally from Auckland, New Zealand. I have lived and worked in London since 2005.

Comments and Discussions