Click here to Skip to main content
15,892,199 members
Articles / Desktop Programming / WPF

Calcium: A modular application toolset leveraging PRISM – Part 1

Rate me:
Please Sign up or sign in to vote.
4.93/5 (70 votes)
1 Jun 2009BSD17 min read 251.5K   208  
Calcium provides much of what one needs to rapidly build a multifaceted and sophisticated modular application. Includes a host of modules and services, and an infrastructure that is ready to use in your next application.
#region File and License Information
/*
<File>
	<Copyright>Copyright © 2007, Daniel Vaughan. All rights reserved.</Copyright>
	<License see="prj:///Documentation/License.txt"/>
	<Owner Name="Daniel Vaughan" Email="dbvaughan@gmail.com"/>
	<CreationDate>2008-05-04 19:49:23Z</CreationDate>
	<LastSubmissionDate>$Date: $</LastSubmissionDate>
	<Version>$Revision: $</Version>
</File>
*/
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
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 DanielVaughan.Logging.ClientLogging;

namespace DanielVaughan.Logging.Silverlight.UI
{
    public partial class LogViewer
    {
		/// <summary>
		/// Gets or sets a value indicating whether to display all
		/// logging messages, whether they are sent to the server or not.
		/// </summary>
		/// <value><c>true</c> if in offline mode; otherwise, <c>false</c>.</value>
		public bool OfflineMode { get; set; }

        public LogViewer()
        {
            InitializeComponent();
			Loaded += LogViewer_Loaded;
        }

		void LogViewer_Loaded(object sender, RoutedEventArgs e)
		{
			//TextBlock_Version.Text = "1.1.4";//Assembly.GetExecutingAssembly().GetName().Version.ToString();
			ListBox_Entries.Items.Clear();
			ListBox_Entries.SelectionChanged += ListBox_Entries_SelectionChanged;

			LogManager.WriteRequested += LogManager_LogEntrySendAttempt;
			LogManager.LogEntrySent += LogManager_LogEntrySent;
			LogManager.Error += LogManager_Error;
		}

		void LogManager_Error(object sender, InternalMessageEventArgs e)
		{
			string errorMessage = e.Exception != null ? 
				e.Exception.Message + "  " + e.Exception.StackTrace 
				: string.Empty;
			Dispatcher.BeginInvoke(() => TextBlock_Messages.Text += e.Message + "   " + errorMessage + "\n");
		}

		void ListBox_Entries_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			var entryData = ListBox_Entries.SelectedItem as LogEntryData;
			if (entryData != null)
			{
				TextBlock_Entry.Text = entryData.Message;
			}
		}

		void LogManager_LogEntrySendAttempt(object sender, LogEventArgs e)
		{
			if (OfflineMode && e.LogEntryData != null)
			{
				DisplayLogEntry(e.LogEntryData);
			}
		}

		void LogManager_LogEntrySent(object sender, LogEventArgs e)
		{
			if (!OfflineMode && e.LogEntryData != null)
			{
				DisplayLogEntry(e.LogEntryData);
			}
		}

		void DisplayLogEntry(LogEntryData logEntryData)
		{
			if (Dispatcher.CheckAccess())
			{
				ListBox_Entries.Items.Insert(0, logEntryData);
			}
			else
			{
				Dispatcher.BeginInvoke(() => ListBox_Entries.Items.Insert(0, logEntryData));
			}
		}


    }
}

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 BSD License


Written By
Engineer
Switzerland Switzerland
Daniel is a former senior engineer in Technology and Research at the Office of the CTO at Microsoft, working on next generation systems.

Previously Daniel was a nine-time Microsoft MVP and co-founder of Outcoder, a Swiss software and consulting company.

Daniel is the author of Windows Phone 8 Unleashed and Windows Phone 7.5 Unleashed, both published by SAMS.

Daniel is the developer behind several acclaimed mobile apps including Surfy Browser for Android and Windows Phone. Daniel is the creator of a number of popular open-source projects, most notably Codon.

Would you like Daniel to bring value to your organisation? Please contact

Blog | Twitter


Xamarin Experts
Windows 10 Experts

Comments and Discussions