comparison Chronosv2/source/App.xaml.cs @ 10:443821e55f06

Initial cleaned up add from Codeplex files
author stevenh7776 stevenhollidge@hotmail.com
date Tue, 21 Feb 2012 17:25:44 +0700
parents
children 741981715d94
comparison
equal deleted inserted replaced
9:904a9faadf8b 10:443821e55f06
1 using System;
2 using System.Collections.Generic;
3 using System.Windows;
4 using System.Windows.Threading;
5 using Chronos.Authentication;
6 using Chronos.Extensions.Windows;
7 using Chronos.Presentation.Core.Navigation;
8 using NLog;
9 using nRoute.Components.Messaging;
10 using nRoute.Services;
11 using System.Windows.Media;
12
13 namespace Chronos
14 {
15 /// <summary>
16 /// Interaction logic for App.xaml
17 /// </summary>
18 public partial class App
19 : nRoute.ApplicationServices.Application
20 {
21 #region · Logger ·
22
23 private static Logger Logger = LogManager.GetCurrentClassLogger();
24
25 #endregion
26
27 #region · Static Members ·
28
29 /// <summary>
30 /// Determines if the application is running on Windows 7
31 /// </summary>
32 public static bool RunningOnWin7
33 {
34 get
35 {
36 return (Environment.OSVersion.Version.Major > 6) ||
37 (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor >= 1);
38 }
39 }
40
41 #endregion
42
43 #region · Fields ·
44
45 private ChannelObserver<AuthenticationInfo> authenticationObserver;
46 private List<string> pendingNavigations;
47 private string[] args;
48 private bool isLoggedIn;
49
50 #endregion
51
52 #region · Methods ·
53
54 public void Run(string[] arguments)
55 {
56 this.args = arguments;
57
58 this.Run();
59 }
60
61 #endregion
62
63 #region · Overriden Methods ·
64
65 protected override void OnStartup(StartupEventArgs e)
66 {
67 //RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.SoftwareOnly;
68
69 this.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(OnDispatcherUnhandledException);
70 SingleInstance.SingleInstanceActivated += new EventHandler<SingleInstanceEventArgs>(OnSingleInstanceActivated);
71
72 // Pending Navigations
73 this.pendingNavigations = new List<string>();
74
75 // Authentication Observer
76 this.authenticationObserver = new ChannelObserver<AuthenticationInfo>((l) => OnAuthenticationAction(l));
77
78 // Subscribe on background thread
79 this.authenticationObserver.Subscribe(ThreadOption.BackgroundThread);
80
81 base.OnStartup(e);
82
83 if (this.args != null && this.args.Length > 0)
84 {
85 if (this.isLoggedIn)
86 {
87 ServiceLocator.GetService<INavigationService>().Navigate(e.Args[0]);
88 }
89 else
90 {
91 this.pendingNavigations.Add(e.Args[0]);
92 }
93 }
94
95 RenderTier renderTier = this.GetRenderTier();
96 }
97
98 #endregion
99
100 #region · Observer Actions ·
101
102 private void OnAuthenticationAction(AuthenticationInfo info)
103 {
104 switch (info.Action)
105 {
106 case AuthenticationAction.LogOn:
107 this.isLoggedIn = false;
108 break;
109
110 case AuthenticationAction.LoggedIn:
111 this.isLoggedIn = true;
112
113 if (this.pendingNavigations != null &&
114 this.pendingNavigations.Count > 0)
115 {
116 this.ProcessPendingNavigations();
117 }
118 break;
119
120 case AuthenticationAction.LogOut:
121 this.isLoggedIn = false;
122 break;
123 }
124 }
125
126 #endregion
127
128 #region · Private Methods ·
129
130 private void ProcessPendingNavigations()
131 {
132 foreach (string url in this.pendingNavigations)
133 {
134 ServiceLocator.GetService<INavigationService>().Navigate(url);
135 }
136 }
137
138 #endregion
139
140 #region · Event Handlers ·
141
142 private void OnDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
143 {
144 Logger.ErrorException("Excepción no manejada", e.Exception);
145
146 e.Handled = true;
147 }
148
149 private void OnSingleInstanceActivated(object sender, SingleInstanceEventArgs e)
150 {
151 if (e != null && e.Args != null && e.Args.Count > 1)
152 {
153 ServiceLocator.GetService<INavigationService>().Navigate(e.Args[1]);
154 }
155 }
156
157 #endregion
158 }
159 }