protected override void OnStartup(StartupEventArgs e)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            base.OnStartup(e);
            _io      = new IOTest();
            _logger  = new LoggerTest();
            _options = new DynamicOptionsTest();
            try
            {
                var s = _io.ReadFile(GetOptionsPath());
                _options.Deserialize(s);
            }
            catch (Exception ex)
            {
                _logger.LogException(ex);
            }

            try
            {
                if (System.IO.File.Exists("error.txt"))
                {
                    string errorContent;
                    using (var sr = new System.IO.StreamReader("error.txt"))
                    {
                        errorContent = sr.ReadToEnd();
                    }
                    SendErrorReport(errorContent);
                    System.IO.File.Delete("error.txt");
                }
            }
            catch { }

            _siteContext = new YouTubeLiveSiteContext(_options, new YouTubeLiveServer(), _logger);
            _siteContext.Init();
            var browserLoader = new BrowserLoader(_logger);
            var vm            = new ViewModel.MainViewModel(_siteContext, _options, _io, _logger, browserLoader);
            var resource      = Application.Current.Resources;
            var locator       = resource["Locator"] as ViewModel.ViewModelLocator;

            locator.Main = vm;
        }
        public async Task StartAsync()
        {
            var io = new Test.IOTest();
            //settingsディレクトリの有無を確認し、無ければ作成する
            const string SettingsDirName = "settings";

            if (!Directory.Exists(SettingsDirName))
            {
                Directory.CreateDirectory(SettingsDirName);
            }
            //OptionsはMainViewModelのContentRendered()で読み込みたい。しかし、その前にConnectionNameWidth等が参照されるため現状ではコンストラクタ以前に読み込む必要がある。
            //実行される順番は
            //ctor->ConnectionNameWidth->Activated->Loaded->ContentRendered
            //理想は、とりあえずViewを表示して、そこに"読み込み中です"みたいな表示を出している間に必要なものを読み込むこと。
            //しかし、それをやるにはViewの位置はデフォルト値になってしまう。それでも良いか。
            //これ↓が一番いいかも
            //ここでOptionsのインスタンスを作成し、MainViewModelに渡す。とりあえずデフォルト値で初期化させ、ContentRenderedで保存されたOptionsを読み込み差し替える。
            var options = new DynamicOptionsTest();

            try
            {
                var s = io.ReadFile(GetOptionsPath());
                options.Deserialize(s);
            }
            catch (Exception ex)
            {
                _logger.LogException(ex);
            }
            try
            {
                SendErrorFile();
            }
            catch { }
            ISitePluginLoader sitePluginLoader = new Test.SitePluginLoaderTest();
            IBrowserLoader    browserLoader    = new BrowserLoader(_logger);
            //var model = new Model(new SitePluginLoaderTest(), options, _logger, io);
            //(IIo io, ILogger logger, IOptions options, ISitePluginLoader sitePluginLoader, IBrowserLoader browserLoader)
            //var viewModel = new MainViewModel(model);
            var viewModel = new MainViewModel(io, _logger, options, sitePluginLoader, browserLoader);

            viewModel.CloseRequested += ViewModel_CloseRequested;

            void windowClosed(object sender, EventArgs e)
            {
                viewModel.RequestClose();

                try
                {
                    var s = options.Serialize();
                    io.WriteFile(GetOptionsPath(), s);
                }
                catch (Exception ex)
                {
                    _logger.LogException(ex);
                }
                try
                {
                    var s = _logger.GetExceptions();
                    SendErrorReport(s, GetTitle(), GetVersion());
                }
                catch (Exception ex)
                {
                    //ここで例外が起きても送れない・・・。
                    Debug.WriteLine(ex.Message);
                }
            }

            //SplashScreen splashScreen = new SplashScreen();  //not disposable, but I'm keeping the same structure
            //{
            //    splashScreen.Closed += windowClosed; //if user closes splash screen, let's quit
            //    splashScreen.Show();

            await viewModel.InitializeAsync();

            var mainForm = new MainWindow();

            mainForm.Closed     += windowClosed;
            mainForm.DataContext = viewModel;
            mainForm.Show();

            //    splashScreen.Owner = mainForm;
            //    splashScreen.Closed -= windowClosed;
            //    splashScreen.Close();
            //}
        }