|
using System;
using System.Diagnostics;
using System.IO;
using System.Windows;
using ReflectionStudio.Classes.Workspace;
using ReflectionStudio.Controls.Helpers;
using ReflectionStudio.Core;
using ReflectionStudio.Core.Events;
using ReflectionStudio.Core.Project;
namespace ReflectionStudio
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
/// <summary>
/// Load the workspace values
/// </summary>
/// <param name="e"></param>
protected override void OnStartup(StartupEventArgs e)
{
PresentationTraceSources.ResourceDictionarySource.Listeners.Add(new ConsoleTraceListener());
PresentationTraceSources.ResourceDictionarySource.Switch.Level = SourceLevels.All;
PresentationTraceSources.DataBindingSource.Listeners.Add(new ConsoleTraceListener());
PresentationTraceSources.DataBindingSource.Switch.Level = SourceLevels.Error;
PresentationTraceSources.DependencyPropertySource.Listeners.Add(new ConsoleTraceListener());
PresentationTraceSources.DependencyPropertySource.Switch.Level = SourceLevels.All;
PresentationTraceSources.DocumentsSource.Listeners.Add(new ConsoleTraceListener());
PresentationTraceSources.DocumentsSource.Switch.Level = SourceLevels.All;
PresentationTraceSources.MarkupSource.Listeners.Add(new ConsoleTraceListener());
PresentationTraceSources.MarkupSource.Switch.Level = SourceLevels.All;
PresentationTraceSources.NameScopeSource.Listeners.Add(new ConsoleTraceListener());
PresentationTraceSources.NameScopeSource.Switch.Level = SourceLevels.All;
base.OnStartup(e);
TraceConfiguration();
//install unhandled exception handler
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionHandler);
//load workspace values
WorkspaceService.Instance.Themes = ThemeHelper.DiscoverThemes();
WorkspaceService.Instance.Load();
if (WorkspaceService.Instance.Entity.CurrentTheme != string.Empty)
ThemeHelper.LoadTheme(WorkspaceService.Instance.Entity.CurrentTheme);
else
{
if (WorkspaceService.Instance.Themes.Count > 0)
ThemeHelper.LoadTheme(WorkspaceService.Instance.Themes[0]);
}
//if we have a file as starting, tell it to the startup dialog to not show up
if (e.Args.GetLength(0) != 0)
{
string arg = e.Args[0];
if (File.Exists(arg) && arg.Contains(ProjectService.ProjectExtension))
WorkspaceService.Instance.Entity.StartupProject = arg;
}
}
/// <summary>
/// Save the workspace values
/// </summary>
/// <param name="e"></param>
protected override void OnExit(ExitEventArgs e)
{
WorkspaceService.Instance.Save();
base.OnExit(e);
}
/// <summary>
/// Manage unhandled exception application wide
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs e)
{
Exception exceptionObject = e.ExceptionObject as Exception;
Tracer.Error("Reflection Studio : Unhandled Exception", exceptionObject);
}
private void TraceConfiguration()
{
try
{
//delete the old log file
string logPath = Path.Combine(PathHelper.ApplicationPath, "ReflectionStudio.exe.log");
if (File.Exists(logPath))
File.Delete(logPath);
if (ReflectionStudio.Properties.Settings.Default.UseTraceListener)
{
//configure the trace
System.Diagnostics.Trace.AutoFlush = true;
System.Diagnostics.Trace.IndentSize = 2;
//configure the text listenner
System.Diagnostics.TraceListenerCollection listeners = System.Diagnostics.Trace.Listeners;
listeners.Add(new System.Diagnostics.TextWriterTraceListener(logPath, "LOG"));
}
}
catch (Exception error)
{
Tracer.Error("Reflection Studio.TraceConfiguration", error);
}
}
}
}
|
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.
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/