Click here to Skip to main content
15,886,799 members
Articles / Desktop Programming / WPF

Reflection Studio - Part 1 - Introduction: Architecture and Design

Rate me:
Please Sign up or sign in to vote.
4.83/5 (23 votes)
22 Sep 2010GPL36 min read 59.9K   6.9K   111  
Reflection Studio is a "developer" application for assembly, database, performance, and code generation, written in C# under WPF 4.0.
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using ReflectionStudio.Classes;
using ReflectionStudio.Classes.Workspace;
using ReflectionStudio.Core.Events;
using AvalonDock;

namespace ReflectionStudio.Components.UserControls
{
	/// <summary>
	/// Interaction logic for EventLogExplorer.xaml
	/// </summary>
	public partial class EventLogExplorer : DockableContent
	{
		public EventLogExplorer()
		{
			InitializeComponent();
		}

		/// <summary>
		/// User control load - init the data
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void UserControl_Loaded(object sender, RoutedEventArgs e)
		{
			//take care that avalon is loading controls each time a panel show
			if (this.dataGridLogEvent.ItemsSource == null)
			{
				ListCollectionView view = new ListCollectionView(BindingView.Instance.LogEvents);
				view.Filter = FilterPredicate;
				this.dataGridLogEvent.ItemsSource = view;

				this.cbLogLevel.SelectionChanged += new SelectionChangedEventHandler(cbLogLevel_SelectionChanged);
			}
		}
		
		/// <summary>
		/// Event handler that process every messages
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		internal void OnMessage(object sender, MessageEventArgs e)
		{
			//add event in the message stack
			BindingView.Instance.AddLogEvent(e.Info);

			RefreshGrid();

			//be sure the datagrid scroll to the last event
			this.dataGridLogEvent.ScrollIntoView(e.Info);
		}

		/// <summary>
		/// Clear the collection and the datagrid display
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void BtnClear_Click(object sender, RoutedEventArgs e)
		{
			BindingView.Instance.LogEvents.Clear();

			RefreshGrid();
		}

		/// <summary>
		/// When the selection level change, update the workspace setting
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void cbLogLevel_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			//Save the level in the settings to share it with the tracer and event dispatcher
			if (this.cbLogLevel.SelectedItem != null)
				WorkspaceService.Instance.Entity.LogLevel = (MessageEventType)this.cbLogLevel.SelectedItem;

			RefreshGrid();
		}

		private void RefreshGrid()
		{
			if (this.dataGridLogEvent != null && this.dataGridLogEvent.ItemsSource != null)
				((ListCollectionView)this.dataGridLogEvent.ItemsSource).Refresh();
		}

		/// <summary>
		/// Predicate filter to log level
		/// </summary>
		/// <param name="item"></param>
		/// <returns></returns>
		private bool FilterPredicate(object item)
		{
			MessageInfo info = (MessageInfo)item;
			if (info.Type <= WorkspaceService.Instance.Entity.LogLevel)
				return true;
			else
				return false;
		}
	}
}

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 General Public License (GPLv3)


Written By
Architect
France France
WPF and MVVM fan, I practice C # in all its forms from the beginning of the NET Framework without mentioning C ++ / MFC and other software packages such as databases, ASP, WCF, Web & Windows services, Application, and now Core and UWP.
In my wasted hours, I am guilty of having fathered C.B.R. and its cousins C.B.R. for WinRT and UWP on the Windows store.
But apart from that, I am a great handyman ... the house, a rocket stove to heat the jacuzzi and the last one: a wood oven for pizza, bread, and everything that goes inside

https://guillaumewaser.wordpress.com/
https://fouretcompagnie.wordpress.com/

Comments and Discussions