基本信息
源码名称:wpf Chronos 例子源码下载
源码大小:2.05M
文件格式:.zip
开发语言:C#
更新时间:2015-03-05
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍


using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Threading;
using Chronos.Authentication;
using Chronos.Extensions.Windows;
using Chronos.Presentation.Core.Navigation;
using NLog;
using nRoute.Components.Messaging;
using nRoute.Services;
using System.Windows.Media;

namespace Chronos
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App 
        : nRoute.ApplicationServices.Application
    {
        #region · Logger ·

        private static Logger Logger = LogManager.GetCurrentClassLogger();

        #endregion

        #region · Static Members ·

        /// <summary>
        /// Determines if the application is running on Windows 7
        /// </summary>
        public static bool RunningOnWin7
        {
            get
            {
                return (Environment.OSVersion.Version.Major > 6) ||
                    (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor >= 1);
            }
        }

        #endregion

        #region · Fields ·

        private ChannelObserver<AuthenticationInfo> authenticationObserver;
        private List<string>                        pendingNavigations;
        private string[]                            args;
        private bool                                isLoggedIn;

        #endregion

        #region · Methods ·

        public void Run(string[] arguments)
        {
            this.args = arguments;

            this.Run();
        }

        #endregion

        #region · Overriden Methods ·

        protected override void OnStartup(StartupEventArgs e)
        {
            //RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.SoftwareOnly;

            this.DispatcherUnhandledException        = new DispatcherUnhandledExceptionEventHandler(OnDispatcherUnhandledException);
            SingleInstance.SingleInstanceActivated   = new EventHandler<SingleInstanceEventArgs>(OnSingleInstanceActivated);

            // Pending Navigations
            this.pendingNavigations = new List<string>();

            // Authentication Observer
            this.authenticationObserver = new ChannelObserver<AuthenticationInfo>((l) => OnAuthenticationAction(l));

            // Subscribe on background thread
            this.authenticationObserver.Subscribe(ThreadOption.BackgroundThread);
            
            base.OnStartup(e);

            if (this.args != null && this.args.Length > 0)
            {
                if (this.isLoggedIn)
                {
                    ServiceLocator.GetService<INavigationService>().Navigate(e.Args[0]);
                }
                else
                {
                    this.pendingNavigations.Add(e.Args[0]);
                }
            }

            RenderTier renderTier = this.GetRenderTier();
        }

        #endregion

        #region · Observer Actions ·

        private void OnAuthenticationAction(AuthenticationInfo info)
        {
            switch (info.Action)
            {
                case AuthenticationAction.LogOn:
                    this.isLoggedIn = false;
                    break;

                case AuthenticationAction.LoggedIn:
                    this.isLoggedIn = true;

                    if (this.pendingNavigations != null &&
                        this.pendingNavigations.Count > 0)
                    {
                        this.ProcessPendingNavigations();
                    }
                    break;

                case AuthenticationAction.LogOut:
                    this.isLoggedIn = false;
                    break;
            }
        }

        #endregion

        #region · Private Methods ·

        private void ProcessPendingNavigations()
        {
            foreach (string url in this.pendingNavigations)
            {
                ServiceLocator.GetService<INavigationService>().Navigate(url);
            }
        }

        #endregion

        #region · Event Handlers ·

        private void OnDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            Logger.ErrorException("Excepción no manejada", e.Exception);

            e.Handled = true;
        }

        private void OnSingleInstanceActivated(object sender, SingleInstanceEventArgs e)
        {
            if (e != null && e.Args != null && e.Args.Count > 1)
            {
                ServiceLocator.GetService<INavigationService>().Navigate(e.Args[1]);
            }
        }

        #endregion
    }
}