コード例 #1
0
        public override void OnFrameworkInitializationCompleted()
        {
            if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
            {
                _suspendHelper.OnFrameworkInitializationCompleted();
                var mainWindow = new MainWindow();

                var viewModel = new MainWindowViewModel(mainWindow.NotificationArea,
                                                        RxApp.SuspensionHost.GetAppState <ConfigViewModel>());

                mainWindow.DataContext = viewModel;
                desktop.MainWindow     = mainWindow;

                Window.WindowClosedEvent.AddClassHandler(typeof(MainWindow), (sender, args) =>
                {
                    if (sender is MainWindow window)
                    {
                        var mainWindowViewModel = window.DataContext as MainWindowViewModel;
                        mainWindowViewModel?.OnClosing();
                    }
                });
            }

            base.OnFrameworkInitializationCompleted();
        }
コード例 #2
0
ファイル: App.xaml.cs プロジェクト: Spaceslug/FogOfWarChess
        public override void OnFrameworkInitializationCompleted()
        {
            AssetBank.LoadAssets();
            _lifetime = (IClassicDesktopStyleApplicationLifetime)ApplicationLifetime;
            // Initialize suspension hooks.
            var suspension = new AutoSuspendHelper(ApplicationLifetime);

            RxApp.SuspensionHost.CreateNewAppState = () => new MainWindowViewModel();
            //RxApp.SuspensionHost.SetupDefaultSuspendResume(new NewtonsoftJsonSuspensionDriver("appstate.json"));
            RxApp.SuspensionHost.SetupDefaultSuspendResume(new NewtonsoftJsonSuspensionDriver(Program.Settings.ConfigDir + "/appstate.json"));
            suspension.OnFrameworkInitializationCompleted();

            // Read main view model state from disk.
            var state = RxApp.SuspensionHost.GetAppState <MainWindowViewModel>();

            Locator.CurrentMutable.RegisterConstant <IScreen>(state);
            // Register views.
            Locator.CurrentMutable.Register <IViewFor <ChessboardViewModel> >(() => new Chessboard());
            Locator.CurrentMutable.Register <IViewFor <PlayViewModel> >(() => new PlayView());
            Locator.CurrentMutable.Register <IViewFor <LoginViewModel> >(() => new LoginView());
            Locator.CurrentMutable.Register <IViewFor <StartMenuViewModel> >(() => new StartMenuView());
            Locator.CurrentMutable.Register <IViewFor <CreateGameViewModel> >(() => new CreateGameView());
            Locator.CurrentMutable.Register <IViewFor <GameBrowserViewModel> >(() => new GameBrowserView());
            Locator.CurrentMutable.Register <IViewFor <ChessClockViewModel> >(() => new ChessClock());
            Locator.CurrentMutable.Register <IViewFor <CapturedPicesViewModel> >(() => new CapturedPices());
            Locator.CurrentMutable.Register <IViewFor <ChatboxViewModel> >(() => new Chatbox());
            Locator.CurrentMutable.Register <IViewFor <RegisterUserViewModel> >(() => new RegisterUserView());


            // Show the main window.
            new MainWindow {
                DataContext = Locator.Current.GetService <IScreen>()
            }.Show();
            base.OnFrameworkInitializationCompleted();
        }
コード例 #3
0
        public override void OnFrameworkInitializationCompleted()
        {
            // Register services.
            // TODO: Move to project with models?
            var sp = BuildDependencies();

            // Reregistering things in Splat.
            Locator.CurrentMutable.RegisterConstant(sp.GetService <IParameterVMsHolder>());

            // Registering ViewModels in Splat locator.
            Locator.CurrentMutable.Register(() => sp.GetService <IDeviceConnectionViewModel>());
            Locator.CurrentMutable.Register(() => sp.GetService <IAinsCountSelectionViewModel>());

            var suspension = new AutoSuspendHelper(ApplicationLifetime);

            RxApp.SuspensionHost.CreateNewAppState = () => new MainWindowViewModel();
            RxApp.SuspensionHost.SetupDefaultSuspendResume(new NewtonsoftJsonSuspensionDriver("appstate.json"));
            suspension.OnFrameworkInitializationCompleted();

            Locator.CurrentMutable.RegisterConstant <IScreen>(RxApp.SuspensionHost.GetAppState <MainWindowViewModel>());

            // Used for Router.Navigate?
            Locator.CurrentMutable.Register <IViewFor <ITelemetry100ViewModel> >(() => new Telemetry100View());
            Locator.CurrentMutable.Register <IViewFor <ISettingsViewModel> >(() => new SettingsView());
            //Locator.CurrentMutable.Register<IViewFor<HelpViewModel>>(() => new HelpView());

            new MainWindow {
                DataContext = Locator.Current.GetService <IScreen>()
            }.Show();

            //ViewModels.ParameterPresentation.ParametersPresenterXmlSerializer.Serialize("params.xml", new PsnProtocolConfigurationLoaderFromXml("psn.Буровая.АИН1.xml").LoadConfiguration(), false);

            base.OnFrameworkInitializationCompleted();
        }
コード例 #4
0
        public void AutoSuspendHelper_Should_Immediately_Fire_IsLaunchingNew()
        {
            using (UnitTestApplication.Start(TestServices.MockWindowingPlatform))
                using (var lifetime = new ClassicDesktopStyleApplicationLifetime(Application.Current))
                {
                    var isLaunchingReceived = false;
                    var application         = AvaloniaLocator.Current.GetService <Application>();
                    application.ApplicationLifetime = lifetime;

                    // Initialize ReactiveUI Suspension as in real-world scenario.
                    var suspension = new AutoSuspendHelper(application.ApplicationLifetime);
                    RxApp.SuspensionHost.IsLaunchingNew.Subscribe(_ => isLaunchingReceived = true);
                    suspension.OnFrameworkInitializationCompleted();

                    Assert.True(isLaunchingReceived);
                }
        }
コード例 #5
0
        public override void OnFrameworkInitializationCompleted()
        {
            var suspension = new AutoSuspendHelper(ApplicationLifetime);

            RxApp.SuspensionHost.CreateNewAppState = () => new MainViewModel();
            RxApp.SuspensionHost.SetupDefaultSuspendResume(new NewtonsoftJsonSuspensionDriver("appstate.json"));
            suspension.OnFrameworkInitializationCompleted();

            Locator.CurrentMutable.RegisterConstant <IScreen>(RxApp.SuspensionHost.GetAppState <MainViewModel>());
            Locator.CurrentMutable.Register <IViewFor <SearchViewModel> >(() => new SearchView());
            Locator.CurrentMutable.Register <IViewFor <LoginViewModel> >(() => new LoginView());

            new MainView {
                DataContext = Locator.Current.GetService <IScreen>()
            }.Show();
            base.OnFrameworkInitializationCompleted();
        }
コード例 #6
0
        public override void OnFrameworkInitializationCompleted()
        {
            ServicePropvider = ConfigureServices(new ServiceCollection());

            var suspension = new AutoSuspendHelper(ApplicationLifetime);

            RxApp.DefaultExceptionHandler = ServicePropvider.GetService <AppExceptionHandler>();
            RxApp.SuspensionHost.SetupDefaultSuspendResume(ServicePropvider.GetService <AppSuspendDriver>());
            suspension.OnFrameworkInitializationCompleted();

            var mainWindow = ServicePropvider.GetService <MainWindow>();

            mainWindow.DataContext = ServicePropvider.GetService <MainWindowViewModel>();
            mainWindow.Show();

            base.OnFrameworkInitializationCompleted();
        }
コード例 #7
0
ファイル: App.xaml.cs プロジェクト: vfofanov/Camelotia
        public override void OnFrameworkInitializationCompleted()
        {
            Akavache.BlobCache.ApplicationName = "CamelotiaV2";
            var suspension = new AutoSuspendHelper(ApplicationLifetime);

            RxApp.SuspensionHost.CreateNewAppState = () => new MainState();
            RxApp.SuspensionHost.SetupDefaultSuspendResume(new NewtonsoftJsonSuspensionDriver("appstate.json"));
            suspension.OnFrameworkInitializationCompleted();

            if (Debugger.IsAttached || IsRelease())
            {
                var window = new Window
                {
                    Height    = 590,
                    Width     = 850,
                    MinHeight = 590,
                    MinWidth  = 850,
                };

                AttachDevTools(window);
                window.Content = CreateView(window);
                window.Show();
            }
            else
            {
                var window = new LiveViewHost(this, Console.WriteLine)
                {
                    Height    = 590,
                    Width     = 850,
                    MinHeight = 590,
                    MinWidth  = 850,
                    Content   = "Please wait for the app to rebuild from sources...",
                    HorizontalContentAlignment = HorizontalAlignment.Center,
                    VerticalContentAlignment   = VerticalAlignment.Center,
                };

                AttachDevTools(window);
                window.StartWatchingSourceFilesForHotReloading();
                window.Show();
            }

            RxApp.DefaultExceptionHandler = Observer.Create <Exception>(Console.WriteLine);
            base.OnFrameworkInitializationCompleted();
        }
コード例 #8
0
        public override void OnFrameworkInitializationCompleted()
        {
            // Configure ReactiveUI suspension management.
            var suspension = new AutoSuspendHelper(ApplicationLifetime);

            // RxApp.SuspensionHost.CreateNewAppState = () => new MainState();
            // RxApp.SuspensionHost.SetupDefaultSuspendResume(new NewtonsoftJsonSuspensionDriver("appstate.json"));
            suspension.OnFrameworkInitializationCompleted();
            base.OnFrameworkInitializationCompleted();

            // Configure app dependencies.
            var window = new MainView();

            // var styles = new AvaloniaStyleManager(window);

            Akavache.BlobCache.ApplicationName = "SocialQ";
            // window.SwitchThemeButton.Click += (sender, args) => styles.UseNextTheme();
            window.DataContext = new MainViewModel();
            // window.DataContext = new MainViewModel(
            //     RxApp.SuspensionHost.GetAppState<MainState>(),
            //     new ProviderFactory(
            //         new AvaloniaYandexAuthenticator(),
            //         Akavache.BlobCache.UserAccount
            //     ),
            //     (state, provider) => new ProviderViewModel(state,
            //         owner => new CreateFolderViewModel(state.CreateFolderState, owner, provider),
            //         owner => new RenameFileViewModel(state.RenameFileState, owner, provider),
            //         (file, owner) => new FileViewModel(owner, file),
            //         (folder, owner) => new FolderViewModel(owner, folder),
            //         new AuthViewModel(
            //             new DirectAuthViewModel(state.AuthState.DirectAuthState, provider),
            //             new HostAuthViewModel(state.AuthState.HostAuthState, provider),
            //             new OAuthViewModel(provider),
            //             provider
            //         ),
            //         new AvaloniaFileManager(window),
            //         provider
            //     )
            // );

            window.Show();
        }
コード例 #9
0
        public override void OnFrameworkInitializationCompleted()
        {
            Locator.CurrentMutable.Register(() => new ServiceBusHelper(), typeof(IServiceBusHelper));
            Locator.CurrentMutable.RegisterLazySingleton(() => new LoggingService(), typeof(ILoggingService));

            var suspension = new AutoSuspendHelper(ApplicationLifetime);

            RxApp.SuspensionHost.CreateNewAppState = () => new AppState();
            RxApp.SuspensionHost.SetupDefaultSuspendResume(new NewtonsoftJsonSuspensionDriver("appstate.json"));
            suspension.OnFrameworkInitializationCompleted();
            var state = RxApp.SuspensionHost.GetAppState <AppState>();

            Locator.CurrentMutable.RegisterLazySingleton(() => state, typeof(IAppState));

            new MainWindow {
                DataContext = new MainWindowViewModel()
            }.Show();

            base.OnFrameworkInitializationCompleted();
        }
コード例 #10
0
        public void ShouldPersistState_Should_Fire_On_App_Exit_When_SuspensionDriver_Is_Initialized()
        {
            using (UnitTestApplication.Start(TestServices.MockWindowingPlatform))
                using (var lifetime = new ClassicDesktopStyleApplicationLifetime(Application.Current))
                {
                    var shouldPersistReceived = false;
                    var application           = AvaloniaLocator.Current.GetService <Application>();
                    application.ApplicationLifetime = lifetime;

                    // Initialize ReactiveUI Suspension as in real-world scenario.
                    var suspension = new AutoSuspendHelper(application.ApplicationLifetime);
                    RxApp.SuspensionHost.CreateNewAppState = () => new AppState {
                        Example = "Foo"
                    };
                    RxApp.SuspensionHost.ShouldPersistState.Subscribe(_ => shouldPersistReceived = true);
                    RxApp.SuspensionHost.SetupDefaultSuspendResume(new DummySuspensionDriver());
                    suspension.OnFrameworkInitializationCompleted();

                    lifetime.Shutdown();
                    Assert.True(shouldPersistReceived);
                    Assert.Equal("Foo", RxApp.SuspensionHost.GetAppState <AppState>().Example);
                }
        }
コード例 #11
0
        public override void OnFrameworkInitializationCompleted()
        {
            // Create the AutoSuspendHelper.
            var suspension = new AutoSuspendHelper(ApplicationLifetime);

            RxApp.SuspensionHost.CreateNewAppState = () => new MainWindowViewModel();
            RxApp.SuspensionHost.SetupDefaultSuspendResume(new JsonSuspensionDriver(new JsonSuspensionSettings {
                Filename = "appstate.json",
                JsonSerializerSettings = new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.All,
                    Formatting       = Formatting.Indented
                }
            }, Locator.Current.GetService <IList <JsonConverter> >()));
            suspension.OnFrameworkInitializationCompleted();

            // Load the saved view model state.
            var state = RxApp.SuspensionHost.GetAppState <MainWindowViewModel>();

            new MainWindow {
                DataContext = state
            }.Show();
            base.OnFrameworkInitializationCompleted();
        }
コード例 #12
0
ファイル: App.xaml.cs プロジェクト: MarkusKgit/Camelotia
    public override void OnFrameworkInitializationCompleted()
    {
        Akavache.BlobCache.ApplicationName = "CamelotiaV2";
        var suspension = new AutoSuspendHelper(ApplicationLifetime);

        RxApp.SuspensionHost.CreateNewAppState = () => new MainState();
        RxApp.SuspensionHost.SetupDefaultSuspendResume(new NewtonsoftJsonSuspensionDriver("appstate.json"));
        suspension.OnFrameworkInitializationCompleted();

        var window = new Window
        {
            Height    = 590,
            Width     = 850,
            MinHeight = 590,
            MinWidth  = 850,
        };

        AttachDevTools(window);
        window.Content = CreateView(window);
        window.Show();

        RxApp.DefaultExceptionHandler = Observer.Create <Exception>(Console.WriteLine);
        base.OnFrameworkInitializationCompleted();
    }