|
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using DiagnosticExplorer.Silverlight.WebServices;
namespace DiagnosticExplorer.Silverlight
{
public class DiagSink : INotifyPropertyChanged
{
private int eventsReceived;
public DiagSink(string name)
{
Name = name;
Events = new ObservableCollection<SystemEvent>();
}
public ObservableCollection<SystemEvent> Events { get; private set; }
public string Name { get; private set; }
public int EventsReceived
{
get { return eventsReceived; }
set
{
if (eventsReceived != value)
{
eventsReceived = value;
OnPropertyChanged("EventsReceived");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
/// <summary>
/// Merges the given events in, which are in date order ascending
/// </summary>
public void Merge(IEnumerable<SystemEvent> evts)
{
int received = 0;
foreach (SystemEvent evt in evts)
{
Events.Insert(0, evt);
received++;
}
while (Events.Count > 1000)
Events.RemoveAt(Events.Count - 1);
EventsReceived = received;
}
public void Merge(DiagSink sink)
{
Merge(sink.Events.Reverse());
}
}
}
|
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.