Exemple #1
0
 private void UIThreadFunc()
 {
     ApplicationLifetime = new ClassicDesktopStyleApplicationLifetime();
     ApplicationLifetime.ShutdownMode = ShutdownMode.OnMainWindowClose;
     AppBuilder.Configure <App>().UsePlatformDetect().SetupWithLifetime(ApplicationLifetime);
     ApplicationLifetime.Start(Array.Empty <string>());
 }
Exemple #2
0
        public void Should_Allow_Canceling_Shutdown_Via_ShutdownRequested_Event()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
                using (var lifetime = new ClassicDesktopStyleApplicationLifetime())
                {
                    var lifetimeEvents = new Mock <IPlatformLifetimeEventsImpl>();
                    AvaloniaLocator.CurrentMutable.Bind <IPlatformLifetimeEventsImpl>().ToConstant(lifetimeEvents.Object);
                    lifetime.Start(Array.Empty <string>());

                    var window = new Window();
                    var raised = 0;

                    window.Show();

                    lifetime.ShutdownRequested += (s, e) =>
                    {
                        e.Cancel = true;
                        ++raised;
                    };

                    lifetimeEvents.Raise(x => x.ShutdownRequested += null, new ShutdownRequestedEventArgs());

                    Assert.Equal(1, raised);
                    Assert.Equal(new[] { window }, lifetime.Windows);
                }
        }
        public Task StartAsync(CancellationToken cancellationToken)
        {
            _uiThreadTask = Task.Factory.StartNew(() =>
            {
                Program.BuildAvaloniaApp().SetupWithLifetime(_classicDesktopStyleApplicationLifetime);
                _classicDesktopStyleApplicationLifetime.Start(_classicDesktopStyleApplicationLifetime.Args);
                _hostApplicationLifetime.StopApplication();
            }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default);

            return(Task.CompletedTask);
        }
Exemple #4
0
        public void Should_Set_ExitCode_After_Shutdown()
        {
            using (UnitTestApplication.Start(TestServices.MockThreadingInterface))
                using (var lifetime = new ClassicDesktopStyleApplicationLifetime())
                {
                    lifetime.Shutdown(1337);

                    var exitCode = lifetime.Start(Array.Empty <string>());

                    Assert.Equal(1337, exitCode);
                }
        }
Exemple #5
0
        public static int StartWithClassicDesktopLifetime <T>(
            this T builder, string[] args, ShutdownMode shutdownMode = ShutdownMode.OnLastWindowClose)
            where T : AppBuilderBase <T>, new()
        {
            var lifetime = new ClassicDesktopStyleApplicationLifetime()
            {
                ShutdownMode = shutdownMode
            };

            builder.SetupWithLifetime(lifetime);
            return(lifetime.Start(args));
        }
Exemple #6
0
        // Initialization code. Don't use any Avalonia, third-party APIs or any
        // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
        // yet and stuff might break.
        public static void Main(string[] args)
        {
            if (args.Length > 0 && args[0] == "--run-test")
            {
                StreamWriter testWriter = new StreamWriter("test.log");
                testWriter.WriteLine("it-works");
                testWriter.Close();
                return;
            }

            var appState = new AppState();

            Sikor.Container.IServiceProvider[] services =
            {
                new Storage(),
                new Logger(),
                new JiraWrapper(),
                appState
            };

            foreach (Sikor.Container.IServiceProvider service in services)
            {
                service.Register();
            }

            var Ui       = BuildAvaloniaApp(); //adds view models to container
            var lifetime = new ClassicDesktopStyleApplicationLifetime();

            Ui.SetupWithLifetime(lifetime);
            Sikor.Container.ServiceContainer.Init();


            //Ui.StartWithClassicDesktopLifetime(args);
            appState.PostInit();

            foreach (Sikor.Container.IServiceProvider service in services)
            {
                if (service.GetTypeString() == typeof(AppState).ToString())
                {
                    continue; //skip appsstate
                }

                service.PostInit();
            }

            lifetime.Start(args);
        }
        public void Start <TMainWindow>(Func <object>?dataContextProvider = null)
            where TMainWindow : Window, new()
        {
            AfterSetup(builder =>
            {
                var window = new TMainWindow();
                if (dataContextProvider != null)
                {
                    window.DataContext = dataContextProvider();
                }
                ((IClassicDesktopStyleApplicationLifetime)builder.Instance !.ApplicationLifetime !)
                .MainWindow = window;
            });

            // Copy-pasted because we can't call extension methods due to generic constraints
            var lifetime = new ClassicDesktopStyleApplicationLifetime()
            {
                ShutdownMode = ShutdownMode.OnMainWindowClose
            };

            SetupWithLifetime(lifetime);
            lifetime.Start(Array.Empty <string>());
        }