Mercurial > silverbladetech
view Chronosv2/source/Authentication/AuthenticationObserver.cs @ 28:4c0dea4760c5
RabbitMq working
author | adminsh@apollo |
---|---|
date | Wed, 21 Mar 2012 20:29:04 +0000 |
parents | 741981715d94 |
children |
line wrap: on
line source
using System; using System.Threading.Tasks; using Chronos.Authentication; using Chronos.Modules.Navigation; using Chronos.Presentation.Core.Navigation; using Chronos.Presentation.Core.VirtualDesktops; using NLog; using nRoute.Components.Composition; using nRoute.Components.Messaging; using nRoute.Navigation; using nRoute.Services; namespace Chronos { /// <summary> /// Dedicated observer for authentication /// </summary> [MapChannelObserver(typeof(AuthenticationInfo), InitializationMode = InitializationMode.WhenAvailable, Lifetime = InstanceLifetime.Singleton)] public sealed class AuthenticationObserver : IObserver<AuthenticationInfo> { #region · Logger · private static Logger Logger = LogManager.GetCurrentClassLogger(); #endregion #region · IObserver<AuthenticationInfo> Members · /// <summary> /// Notifies the observer that the provider has finished sending push-based notifications. /// </summary> public void OnCompleted() { } /// <summary> /// Notifies the observer that the provider has experienced an error condition. /// </summary> /// <param name="error">An object that provides additional information about the error.</param> public void OnError(Exception error) { } /// <summary> /// Provides the observer with new data. /// </summary> /// <param name="value">The current notification information.</param> public void OnNext(AuthenticationInfo value) { switch (value.Action) { case AuthenticationAction.LogOn: Logger.Debug("User Authentication"); ServiceLocator.GetService<INavigationService>() .Navigate(NavigateMode.Modal, NavigationRoutes.Login); break; case AuthenticationAction.LoggedIn: Logger.Debug("Properly authenticated user"); ServiceLocator.GetService<IVirtualDesktopManager>() .ActivateDefaultDesktop(); break; case AuthenticationAction.LogOut: Logger.Debug("Logging out"); Task t = Task.Factory.StartNew ( () => { ServiceLocator.GetService<IVirtualDesktopManager>() .CloseAll(); Channel<AuthenticationInfo>.Publish ( new AuthenticationInfo { Action = AuthenticationAction.LogOn }, true ); } ); break; } } #endregion } }