using HandyControl.Controls;
using HKCardIN.ViewModels;
using Stylet;
using StyletIoC;
using System;
using System.Configuration;
using System.Windows.Controls;
using System.Windows.Threading;
using System.Windows;
using Microsoft.Extensions.Configuration;
using HKCardIN.Helper;

namespace HKCardIN
{
    public class Bootstrapper : Bootstrapper<RootViewModel>
    {
        /// <summary>
        /// 程序启动
        /// </summary>
        protected override void OnStart()
        {
            HKLog.HKLogImport.Init("HKCardIN");
        }

        protected override void ConfigureIoC(IStyletIoCBuilder builder)
        {
        }

        /// <summary>
        /// 初始化系统相关参数配置
        /// </summary>
        protected override void Configure()
        {
            var configer = (new ConfigurationBuilder()).AddJsonFile("options.json").Build();
            DataBus.SaasRoute = configer["SaasRoute"];
            DataBus.LockCode = configer["LockCode"];
            base.Configure();
        }

        /// <summary>
        /// 初始化VM
        /// </summary>
        protected override void Launch()
        {
            base.Launch();
        }

        /// <summary>
        /// 加载首页VM
        /// </summary>
        /// <param name="rootViewModel"></param>
        protected override void DisplayRootView(object rootViewModel)
        {
            base.DisplayRootView(rootViewModel);
        }

        /// <summary>
        ///VM加载完毕
        /// </summary>
        protected override void OnLaunch()
        {
            base.OnLaunch();
        }

        /// <summary>
        /// 退出
        /// </summary>
        /// <param name="e"></param>
        protected override void OnExit(ExitEventArgs e)
        {
            base.OnExit(e);
        }

        /// <summary>
        /// 全局异常捕获
        /// </summary>
        /// <param name="e"></param>
        protected override void OnUnhandledException(DispatcherUnhandledExceptionEventArgs e)
        {
            HKLog.HKLogImport.WriteError(e.Exception.InnerException != null ? e.Exception.InnerException : e.Exception);
            GC.Collect();
        }
    }
}
