|
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.
I am a software developer originally from Auckland, New Zealand. I have lived and worked in London since 2005.