Mercurial > silverbladetech
comparison Chronosv2/source/Authentication/AuthenticationObserver.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 /* | |
2 The MIT License | |
3 | |
4 Copyright (c) 2009-2010. Carlos Guzmán Álvarez. http://chronoswpf.codeplex.com/ | |
5 | |
6 Permission is hereby granted, free of charge, to any person obtaining a copy | |
7 of this software and associated documentation files (the "Software"), to deal | |
8 in the Software without restriction, including without limitation the rights | |
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 copies of the Software, and to permit persons to whom the Software is | |
11 furnished to do so, subject to the following conditions: | |
12 | |
13 The above copyright notice and this permission notice shall be included in | |
14 all copies or substantial portions of the Software. | |
15 | |
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
22 THE SOFTWARE. | |
23 */ | |
24 | |
25 using System; | |
26 using System.Threading.Tasks; | |
27 using Chronos.Authentication; | |
28 using Chronos.Modules.Navigation; | |
29 using Chronos.Presentation.Core.Navigation; | |
30 using Chronos.Presentation.Core.VirtualDesktops; | |
31 using NLog; | |
32 using nRoute.Components.Composition; | |
33 using nRoute.Components.Messaging; | |
34 using nRoute.Navigation; | |
35 using nRoute.Services; | |
36 | |
37 namespace Chronos | |
38 { | |
39 /// <summary> | |
40 /// Dedicated observer for authentication | |
41 /// </summary> | |
42 [MapChannelObserver(typeof(AuthenticationInfo), | |
43 InitializationMode = InitializationMode.WhenAvailable, | |
44 Lifetime = InstanceLifetime.Singleton)] | |
45 public sealed class AuthenticationObserver : IObserver<AuthenticationInfo> | |
46 { | |
47 #region · Logger · | |
48 | |
49 private static Logger Logger = LogManager.GetCurrentClassLogger(); | |
50 | |
51 #endregion | |
52 | |
53 #region · IObserver<AuthenticationInfo> Members · | |
54 | |
55 /// <summary> | |
56 /// Notifies the observer that the provider has finished sending push-based notifications. | |
57 /// </summary> | |
58 public void OnCompleted() | |
59 { | |
60 } | |
61 | |
62 /// <summary> | |
63 /// Notifies the observer that the provider has experienced an error condition. | |
64 /// </summary> | |
65 /// <param name="error">An object that provides additional information about the error.</param> | |
66 public void OnError(Exception error) | |
67 { | |
68 } | |
69 | |
70 /// <summary> | |
71 /// Provides the observer with new data. | |
72 /// </summary> | |
73 /// <param name="value">The current notification information.</param> | |
74 public void OnNext(AuthenticationInfo value) | |
75 { | |
76 switch (value.Action) | |
77 { | |
78 case AuthenticationAction.LogOn: | |
79 Logger.Debug("Autenticación del usuario"); | |
80 ServiceLocator.GetService<INavigationService>() | |
81 .Navigate(NavigateMode.Modal, NavigationRoutes.Login); | |
82 break; | |
83 | |
84 case AuthenticationAction.LoggedIn: | |
85 Logger.Debug("Usuario autenticado correctamente"); | |
86 ServiceLocator.GetService<IVirtualDesktopManager>() | |
87 .ActivateDefaultDesktop(); | |
88 break; | |
89 | |
90 case AuthenticationAction.LogOut: | |
91 Logger.Debug("Cerrando sesión"); | |
92 Task t = Task.Factory.StartNew | |
93 ( | |
94 () => | |
95 { | |
96 ServiceLocator.GetService<IVirtualDesktopManager>() | |
97 .CloseAll(); | |
98 | |
99 Channel<AuthenticationInfo>.Publish | |
100 ( | |
101 new AuthenticationInfo | |
102 { | |
103 Action = AuthenticationAction.LogOn | |
104 }, | |
105 true | |
106 ); | |
107 } | |
108 ); | |
109 break; | |
110 } | |
111 } | |
112 | |
113 #endregion | |
114 } | |
115 } |