using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace FLY.Thick.FilmCasting.UI.Server
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        FLY.AppHelper.AppJustOne appjustone;
        NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();

        Launcher launcher;
        public App()
        {
            appjustone = new AppHelper.AppJustOne(this);

            AppDomain.CurrentDomain.UnhandledException += (s, e) =>
            {
                log.Error((Exception)e.ExceptionObject, "AppDomain.CurrentDomain.UnhandledException");
                string err = e.ExceptionObject.ToString();

                MessageBox.Show("程序出现异常，请把下面信息拍照发给厂家" + Environment.NewLine + err,
                    "异常，联系厂家",
                    MessageBoxButton.OK, MessageBoxImage.Error);

            };
            this.Startup += App_Startup;
        }
        private void App_Startup(object sender, StartupEventArgs e)
        {


            //这一段，必须放在 Startup 执行。
            //因为下面会加载页面，会调用 App.Resources 里面的 资源。 
            //当创建 App() , 在 注入 App.Resources 之前发生
            //Culture culture = new Culture();
            //if (!culture.Load())
            //    culture.Save();

            //culture.LoadCulture(typeof(App));

            var v = new Misc.Ver() { SrcType = typeof(App) };

            launcher = new Launcher();
            var mainWindow = new MainWindow();
            mainWindow.Init(launcher.container, launcher.Init);


            string title = (string)Application.Current.FindResource("str.MainWindow.Title");
            title = $"{title} {v.V}";
            mainWindow.Title = title;
            this.MainWindow = mainWindow;
            this.MainWindow.Show();
        }
    }
}
