#region Copyright
// Diagnostic Explorer, a .Net diagnostic toolset
// Copyright (C) 2010 Cameron Elliot
//
// This file is part of Diagnostic Explorer.
//
// Diagnostic Explorer is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Diagnostic Explorer is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Diagnostic Explorer. If not, see <http://www.gnu.org/licenses/>.
//
// http://diagexplorer.sourceforge.net/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Diagnostics;
using System.Windows.Data;
using System.Text.RegularExpressions;
using DiagnosticExplorer.Silverlight.WebServices;
namespace DiagnosticExplorer.Silverlight.Controls
{
public partial class SinkControl : UserControl
{
public event EventHandler<EventSelectedEventArgs> EventSelected;
private bool _mouseDown = false;
public SinkControl()
{
InitializeComponent();
grid.SelectionMode = DataGridSelectionMode.Single;
grid.LoadingRow += HandleLoadingRow;
Loaded += HandleLoaded;
}
private void HandleLoaded(object sender, RoutedEventArgs e)
{
CollectionViewSource view = (CollectionViewSource)Resources["EventView"];
DiagSink sink = (DiagSink) DataContext;
if (sink != null)
view.Source = sink.Events;
}
private void HandleLoadingRow(object sender, DataGridRowEventArgs e)
{
SystemEvent evt = (SystemEvent)e.Row.DataContext;
if (evt.Severity == EventSeverity.Low)
e.Row.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0xAA, 0xFF, 0xAA));
else if (evt.Severity == EventSeverity.Medium)
e.Row.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xAA));
else if (evt.Severity == EventSeverity.High)
e.Row.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0xAA, 0xAA));
}
private void HandleFilterChanged(object sender, EventArgs e)
{
CollectionViewSource view = (CollectionViewSource)Resources["EventView"];
view.View.Filter = eventFilter.GetFilter();
}
private void HandleGridMouseDown(object sender, MouseEventArgs e)
{
_mouseDown = true;
}
private void HandleGridMouseUp(object sender, MouseEventArgs e)
{
_mouseDown = false;
}
private void HandleMouseRowMove(object sender, MouseEventArgs e)
{
try
{
if (_mouseDown)
{
FrameworkElement row = (FrameworkElement)sender;
if (grid.SelectedItem != row.DataContext)
{
grid.SelectedItem = row.DataContext;
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
private void HandleSelectionChanged(object sender, SelectionChangedEventArgs e)
{
SystemEvent evt = (SystemEvent)grid.SelectedItem;
if (EventSelected != null)
EventSelected(this, new EventSelectedEventArgs(evt));
}
}
}