protected override void ConfigureContainer() { base.ConfigureContainer(); UIDispatcherScheduler.Initialize(); Container.RegisterType <IConfigurationService, ConfigurationService>(new ContainerControlledLifetimeManager()); }
void OnStartup(object sender, StartupEventArgs e) { // ObserveOnUIDispatcher でUIスレッドを使うために初期化 UIDispatcherScheduler.Initialize(); // TLS 1.1/1.2 対応設定 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; this.SetupTraceListener(); this.SetupUpdateChecker(); this.SetupVoiceroidProcess(); // 設定ロード開始 var loadTask = this.ConfigManager.Load().AddTo(this.CompositeDisposable); // ロード済みかつ非ロード中なら設定使用可能 var canUseConfig = new[] { this.ConfigManager.IsLoaded, this.ConfigManager.IsLoading.Inverse(), } .CombineLatestValuesAreAllTrue() .ToReadOnlyReactiveProperty() .AddTo(this.CompositeDisposable); // メインウィンドウ作成 var mainWindow = new MainWindow(); // ViewModel 設定 mainWindow.DataContext = new MainWindowViewModel( this.ProcessFactory.Processes, canUseConfig, this.ConfigManager.TalkTextReplaceConfig, this.ConfigManager.ExoConfig, this.ConfigManager.AppConfig, this.ConfigManager.UIConfig, this.LastStatus, new OpenFileDialogService(mainWindow), new WindowActivateService(mainWindow), new VoiceroidActionService(mainWindow), new AviUtlFileDropService(mainWindow)) .AddTo(this.CompositeDisposable); #if WAIT_ON_CONFIG_LOADED // ロード完了まで待つ await loadTask; #endif // WAIT_ON_CONFIG_LOADED // 表示 mainWindow.Show(); }
/// <summary> /// 初期処理 /// </summary> /// <param name="e"></param> protected override void OnStartup(StartupEventArgs e) { DispatcherHelper.UIDispatcher = this.Dispatcher; UIDispatcherScheduler.Initialize(); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; this._logger = new Logger(); var settings = new Settings(this._logger, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "MealRecipes.settings")); settings.Load(); // 各サイト読み込み Creator.PluginDirectory = settings.GeneralSettings.PluginsDirectoryPath; if (!Directory.Exists(Creator.PluginDirectory)) { var message = $"プラグインディレクトリが見つかりません。[{Creator.PluginDirectory}]"; MessageBox.Show( message, "エラー", MessageBoxButton.OK, MessageBoxImage.Error); this._logger.Log(LogLevel.Fatal, message); Environment.Exit(1); } Creator.Load(); using (var dataContext = settings.GeneralSettings.GetMealRecipeDbContext()) { // dataContext.Database.EnsureDeleted(); if (dataContext.Database.EnsureCreated()) { // マスタデータ登録 とりあえずな dataContext.MealTypes.AddRange( new MealType { MealTypeId = 1, Name = "あさごはん" }, new MealType { MealTypeId = 2, Name = "ひるごはん" }, new MealType { MealTypeId = 3, Name = "ばんごはん" }); dataContext.SaveChanges(); } } settings.MasterLoad(); settings.CachesLoad(); this.MainWindow = new Views.MainWindow() { DataContext = new MainWindowViewModel(settings, this._logger) }; this.MainWindow.ShowDialog(); }
public MainWindow() { Mapper.Initialize(cfg => { //cfg.AddProfiles(Assembly.GetExecutingAssembly()); cfg.CreateMap <TestEntity, TestViewModel>() .ForMember(dest => dest.CompositeDisposable, opt => opt.Ignore()) .ForMember(dest => dest.Messenger, opt => opt.Ignore()) .ReverseMap() .ForMember(dest => dest.SheetId, opt => opt.Ignore()) ; cfg.CreateMap <Test2Entity, Test2ViewModel>() .ForPath(dest => dest.Name.Value, source => source.MapFrom(s => s.Name)) .ForPath(dest => dest.IsOk.Value, source => source.MapFrom(s => s.IsOk)) .ForPath(dest => dest.SendEnabled.Value, source => source.MapFrom(s => s.SendEnabled)) .ForMember(dest => dest.CompositeDisposable, opt => opt.Ignore()) .ForMember(dest => dest.Messenger, opt => opt.Ignore()) .ReverseMap() .ForPath(dest => dest.Name, source => source.MapFrom(s => s.Name.Value)) .ForPath(dest => dest.IsOk, source => source.MapFrom(s => s.IsOk.Value)) .ForPath(dest => dest.SendEnabled, source => source.MapFrom(s => s.SendEnabled.Value)) ; cfg.CreateMap <Test3Entity, Test3ViewModel>() .ForPath(dest => dest.Name.Value, source => source.MapFrom(s => s.Name)) .ForPath(dest => dest.SendEnabled.Value, source => source.MapFrom(s => s.SendEnabled)) .ForMember(dest => dest.CompositeDisposable, opt => opt.Ignore()) .ForMember(dest => dest.Messenger, opt => opt.Ignore()) .ReverseMap() .ForPath(dest => dest.Name, source => source.MapFrom(s => s.Name.Value)) .ForPath(dest => dest.SendEnabled, source => source.MapFrom(s => s.SendEnabled.Value)) ; }); Mapper.AssertConfigurationIsValid(); DispatcherHelper.UIDispatcher = Dispatcher; UIDispatcherScheduler.Initialize(); InitializeComponent(); }
protected override async Task OnInitializeAsync(IActivatedEventArgs args) { UIDispatcherScheduler.Initialize(); var pixivClient = new PixivApiClient(); var accountService = new AccountService(pixivClient); Container.RegisterInstance <IPixivClient>(pixivClient, new LifetimeManager()); Container.RegisterInstance <IAccountService>(accountService, new LifetimeManager()); Container.RegisterType <IBrowsingHistoryService, BrowsingHistoryService>(new LifetimeManager()); Container.RegisterType <IImageStoreService, ImageStoreService>(new LifetimeManager()); Container.RegisterType <IDialogService, DialogService>(new LifetimeManager()); Container.RegisterType <ICategoryService, CategoryService>(new LifetimeManager()); Container.RegisterType <IQueryCacheService, QueryCacheService>(new LifetimeManager()); #if DEBUG Container.RegisterType <ILicenseService, LocalLicenseService>(new LifetimeManager()); #else Container.RegisterType <ILicenseService, LicenseService>(new LifetimeManager()); #endif // Container.RegisterInstance<IPixivClient>(new PixivWebClient(), new ContainerControlledLifetimeManager()); #if !OFFLINE await accountService.Login(); #endif await base.OnInitializeAsync(args); }
public FormEditor() { UIDispatcherScheduler.Initialize(); disposable = new CompositeDisposable(); CompositeDisposable messageDisposable = new CompositeDisposable().AddTo(disposable); CompositeDisposable openFileDialogDisposable = new CompositeDisposable().AddTo(disposable); CompositeDisposable saveFileDialogDisposable = new CompositeDisposable().AddTo(disposable); CompositeDisposable trainDisposable = new CompositeDisposable().AddTo(disposable); CompositeDisposable panelDisposable = new CompositeDisposable().AddTo(disposable); CompositeDisposable soundDisposable = new CompositeDisposable().AddTo(disposable); app = new AppViewModel(); InitializeComponent(); app.SaveLocation .BindTo( this, x => x.Text, x => string.IsNullOrEmpty(x) ? $@"NewFile - {Application.ProductName}" : $@"{Path.GetFileName(x)} - {Application.ProductName}" ) .AddTo(disposable); app.MessageBox .Subscribe(x => { messageDisposable.Dispose(); messageDisposable = new CompositeDisposable().AddTo(disposable); BindToMessageBox(x).AddTo(messageDisposable); }) .AddTo(disposable); app.OpenFileDialog .Subscribe(x => { openFileDialogDisposable.Dispose(); openFileDialogDisposable = new CompositeDisposable().AddTo(disposable); BindToOpenFileDialog(x).AddTo(openFileDialogDisposable); }) .AddTo(disposable); app.SaveFileDialog .Subscribe(x => { saveFileDialogDisposable.Dispose(); saveFileDialogDisposable = new CompositeDisposable().AddTo(disposable); BindToSaveFileDialog(x).AddTo(saveFileDialogDisposable); }) .AddTo(disposable); app.Train .Subscribe(x => { trainDisposable.Dispose(); trainDisposable = new CompositeDisposable().AddTo(disposable); BindToTrain(x).AddTo(trainDisposable); }) .AddTo(disposable); app.Panel .Subscribe(x => { panelDisposable.Dispose(); panelDisposable = new CompositeDisposable().AddTo(disposable); BindToPanel(x).AddTo(panelDisposable); }) .AddTo(disposable); app.Sound .Subscribe(x => { soundDisposable.Dispose(); soundDisposable = new CompositeDisposable().AddTo(disposable); BindToSound(x).AddTo(soundDisposable); }) .AddTo(disposable); app.Item .BindTo( this, x => x.TreeViewCarsTopNode, BindingMode.OneWay, TreeViewItemViewModelToTreeNode ) .AddTo(disposable); app.SelectedItem .BindTo( treeViewCars, x => x.SelectedNode, BindingMode.TwoWay, x => treeViewCars.Nodes.OfType <TreeNode>().Select(y => SearchTreeNode(x, y)).FirstOrDefault(y => y != null), x => (TreeViewItemViewModel)x.Tag, Observable.FromEvent <TreeViewEventHandler, TreeViewEventArgs>( h => (s, e) => h(e), h => treeViewCars.AfterSelect += h, h => treeViewCars.AfterSelect -= h ) .ToUnit() ) .AddTo(disposable); app.SelectedItem .BindTo( tabPageTrain, x => x.Enabled, BindingMode.OneWay, x => x == app.Item.Value.Children[0] ) .AddTo(disposable); app.SelectedItem .BindTo( tabPageCar, x => x.Enabled, BindingMode.OneWay, x => app.Item.Value.Children[1].Children.Contains(x) ) .AddTo(disposable); app.SelectedItem .BindTo( tabPageAccel, x => x.Enabled, BindingMode.OneWay, x => x?.Tag.Value is MotorCar && app.Item.Value.Children[1].Children.Contains(x) ) .AddTo(disposable); app.SelectedItem .BindTo( tabPageMotor, x => x.Enabled, BindingMode.OneWay, x => x?.Tag.Value is MotorCar && app.Item.Value.Children[1].Children.Contains(x) ) .AddTo(disposable); app.SelectedItem .BindTo( tabPageCoupler, x => x.Enabled, BindingMode.OneWay, x => app.Item.Value.Children[2].Children.Contains(x) ) .AddTo(disposable); app.SelectedItem .BindTo( tabPagePanel, x => x.Enabled, BindingMode.OneWay, x => x == app.Item.Value.Children[0] ) .AddTo(disposable); app.SelectedItem .BindTo( tabPageSound, x => x.Enabled, BindingMode.OneWay, x => x == app.Item.Value.Children[0] ) .AddTo(disposable); app.SelectedItem .BindTo( tabControlEditor, x => x.SelectedTab, BindingMode.OneWay, _ => { TabPage tabPage; if (tabControlEditor.SelectedTab.Enabled) { tabPage = tabControlEditor.SelectedTab; } else { tabPage = tabControlEditor.TabPages.OfType <TabPage>().FirstOrDefault(x => x.Enabled); } return(tabPage); } ) .AddTo(disposable); app.IsVisibleInfo .ToReadOnlyReactivePropertySlim() .BindTo( toolStripMenuItemInfo, x => x.Checked ) .AddTo(disposable); app.IsVisibleInfo .ToReadOnlyReactivePropertySlim() .BindTo( toolStripMenuItemInfo, x => x.BackColor, x => x ? SystemColors.GradientActiveCaption : SystemColors.Control ) .AddTo(disposable); app.IsVisibleWarning .ToReadOnlyReactivePropertySlim() .BindTo( toolStripMenuItemWarning, x => x.Checked ) .AddTo(disposable); app.IsVisibleWarning .ToReadOnlyReactivePropertySlim() .BindTo( toolStripMenuItemWarning, x => x.BackColor, x => x ? SystemColors.GradientActiveCaption : SystemColors.Control ) .AddTo(disposable); app.IsVisibleError .ToReadOnlyReactivePropertySlim() .BindTo( toolStripMenuItemError, x => x.Checked ) .AddTo(disposable); app.IsVisibleError .ToReadOnlyReactivePropertySlim() .BindTo( toolStripMenuItemError, x => x.BackColor, x => x ? SystemColors.GradientActiveCaption : SystemColors.Control ) .AddTo(disposable); Interface.LogMessages .CollectionChangedAsObservable() .Subscribe(_ => { tabPageStatus.Text = $@"{Utilities.GetInterfaceString("status", "name")} ({Interface.LogMessages.Count})"; toolStripMenuItemError.Text = $@"{Interface.LogMessages.Count(m => m.Type == MessageType.Error || m.Type == MessageType.Critical)} {Utilities.GetInterfaceString("status", "menu", "error")}"; toolStripMenuItemWarning.Text = $@"{Interface.LogMessages.Count(m => m.Type == MessageType.Warning)} {Utilities.GetInterfaceString("status", "menu", "warning")}"; toolStripMenuItemInfo.Text = $@"{Interface.LogMessages.Count(m => m.Type == MessageType.Information)} {Utilities.GetInterfaceString("status", "menu", "info")}"; }) .AddTo(disposable); app.VisibleLogMessages .ObserveAddChanged() .Subscribe(y => { listViewStatus.Items.Add(ListViewItemViewModelToListViewItem(y)); listViewStatus.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); }) .AddTo(disposable); app.VisibleLogMessages .ObserveRemoveChanged() .Subscribe(y => { foreach (ListViewItem item in listViewStatus.Items.OfType <ListViewItem>().Where(z => z.Tag == y).ToArray()) { listViewStatus.Items.Remove(item); } listViewStatus.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); }) .AddTo(disposable); app.CreateNewFile.BindToButton(toolStripMenuItemNew).AddTo(disposable); app.OpenFile.BindToButton(toolStripMenuItemOpen).AddTo(disposable); app.SaveFile.BindToButton(toolStripMenuItemSave).AddTo(disposable); app.SaveAsFile.BindToButton(toolStripMenuItemSaveAs).AddTo(disposable); new[] { app.UpCar, app.UpCoupler }.BindToButton(buttonCarsUp).AddTo(disposable); new[] { app.DownCar, app.DownCoupler }.BindToButton(buttonCarsDown).AddTo(disposable); app.AddCar.BindToButton(buttonCarsAdd).AddTo(disposable); app.CopyCar.BindToButton(buttonCarsCopy).AddTo(disposable); app.RemoveCar.BindToButton(buttonCarsRemove).AddTo(disposable); app.ChangeCarClass.BindToCheckBox(checkBoxIsMotorCar).AddTo(disposable); app.ChangeVisibleLogMessages.BindToButton(MessageType.Information, toolStripMenuItemInfo).AddTo(disposable); app.ChangeVisibleLogMessages.BindToButton(MessageType.Warning, toolStripMenuItemWarning).AddTo(disposable); app.ChangeVisibleLogMessages.BindToButton(MessageType.Error, toolStripMenuItemError).AddTo(disposable); app.ChangeVisibleLogMessages.BindToButton(MessageType.Critical, toolStripMenuItemError).AddTo(disposable); app.ClearLogMessages.BindToButton(toolStripMenuItemClear).AddTo(disposable); app.OutputLogs.BindToButton(buttonOutputLogs).AddTo(disposable); }
protected override async void OnInitialized() { UIDispatcherScheduler.Initialize(); await this.NavigationService.NavigateAsync("MainPage"); }
private void Application_Startup(object sender, StartupEventArgs e) { DispatcherHelper.UIDispatcher = Dispatcher; UIDispatcherScheduler.Initialize(); }