public async Task Test_StartupException()
        {
            bool isDisposed = false;

            AssemblyUtils.SetEntryAssembly(GetType().Assembly);

            var applicationConfig = ApplicationConfigBuilder
                                    .Create()
                                    .WithApplicationName(ApplicationName)
                                    .WithScanDirectories(
                TestAssemblyDirectories
                )
                                    // Add all file starting with Dapplo and ending on .dll
                                    .WithAssemblyPatterns("Dapplo*")
                                    .BuildApplicationConfig();

            using (var bootstrapper = new ApplicationBootstrapper(applicationConfig))
            {
                bootstrapper.Configure();

                // Makes the startup break
                bootstrapper.Builder.Register(context => true);

                bootstrapper.RegisterForDisposal(SimpleDisposable.Create(() => isDisposed = true));

                // Initialize, so we can export
                Assert.True(await bootstrapper.InitializeAsync().ConfigureAwait(false), "Not initialized");

                // Start the composition, and IStartupActions
                await Assert.ThrowsAsync <NotSupportedException>(async() => await bootstrapper.StartupAsync().ConfigureAwait(false));
            }
            // Dispose automatically calls IShutdownActions
            Assert.True(isDisposed);
        }
Пример #2
0
        /// <summary>
        ///     Make sure we startup everything after WPF instantiated
        /// </summary>
        /// <param name="e">StartupEventArgs</param>
        protected override async void OnStartup(StartupEventArgs e)
        {
            Log.Debug().WriteLine("Starting application startup");

            _bootstrapper.Configure();

            // Register the UI SynchronizationContext, this can be retrieved by specifying the name "ui" for the argument
            _bootstrapper.Builder.RegisterInstance(SynchronizationContext.Current).Named <SynchronizationContext>("ui");
            _bootstrapper.Builder.RegisterInstance(TaskScheduler.FromCurrentSynchronizationContext()).Named <TaskScheduler>("ui");
            // The following makes sure that Caliburn.Micro is correctly initialized on the right thread and Execute.OnUIThread works
            // Very important to do this, after all assemblies are loaded!
            _caliburnMicroBootstrapper = new CaliburnMicroBootstrapper(_bootstrapper);
            _bootstrapper.Builder.RegisterInstance(_caliburnMicroBootstrapper).As <IService>().SingleInstance();

            // Prepare the bootstrapper
            await _bootstrapper.InitializeAsync().ConfigureAwait(true);

            _caliburnMicroBootstrapper.Initialize();

            // Now check if there is a lock, if so we invoke OnAlreadyRunning and return
            if (_bootstrapper.IsAlreadyRunning)
            {
                var exitCode = OnAlreadyRunning?.Invoke() ?? -1;
                Shutdown(exitCode);
                return;
            }

            // Start Dapplo, services which need a UI context need to configure this
            await _bootstrapper.StartupAsync().ConfigureAwait(true);

            Log.Debug().WriteLine("Finished application startup");
            // This also triggers the Caliburn.Micro.BootstrapperBase.OnStartup
            base.OnStartup(e);
        }
        public async Task TestStartupShutdown()
        {
            AssemblyUtils.SetEntryAssembly(GetType().Assembly);

            var applicationConfig = ApplicationConfigBuilder
                                    .Create()
                                    .WithApplicationName(ApplicationName)
                                    .WithScanDirectories(TestAssemblyDirectories)
                                    // Add all assemblies starting with Dapplo
                                    .WithAssemblyPatterns("Dapplo*")
                                    .BuildApplicationConfig();

            using (var bootstrapper = new ApplicationBootstrapper(applicationConfig))
            {
                bootstrapper.Configure();
#if DEBUG
                bootstrapper.EnableActivationLogging = true;
#endif
                // Start the composition, and IStartupActions
                Assert.True(await bootstrapper.InitializeAsync().ConfigureAwait(false), "Couldn't run");

                Assert.Contains(bootstrapper.LoadedAssemblies, addon => addon.GetName().Name.EndsWith("TestAddon"));
            }
            // Dispose automatically calls IShutdownActions
        }
Пример #4
0
        /// <summary>
        ///     Make sure we startup everything after WPF instanciated
        /// </summary>
        /// <param name="e">StartupEventArgs</param>
        protected override async void OnStartup(StartupEventArgs e)
        {
            // Enable UI access for different Dapplo packages, especially the UiContext.RunOn
            // This only works here, not before the Application is started and not later
            UiContext.Initialize();

            _bootstrapper.Configure();

            // Register the UI SynchronizationContext, this can be retrieved by specifying the name "ui" for the argument
            _bootstrapper.Builder.RegisterInstance(SynchronizationContext.Current).Named <SynchronizationContext>("ui");
            _bootstrapper.Builder.RegisterInstance(TaskScheduler.FromCurrentSynchronizationContext()).Named <TaskScheduler>("ui");

            // Prepare the bootstrapper
            await _bootstrapper.InitializeAsync().ConfigureAwait(true);

            // The following makes sure that Caliburn.Micro is correctly initialized on the right thread and Execute.OnUIThread works
            // Very important to do this, after all assemblies are loaded!
            _caliburnMicroBootstrapper = new CaliburnMicroBootstrapper(_bootstrapper);
            _caliburnMicroBootstrapper.Initialize();

            // Now check if there is a lock, if so we invoke OnAlreadyRunning and return
            if (_bootstrapper.IsAlreadyRunning)
            {
                var exitCode = OnAlreadyRunning?.Invoke() ?? -1;
                Shutdown(exitCode);
                return;
            }

            // Start Dapplo, do not use configure-await false here, so the OnStartup doesn't have any issues
            await _bootstrapper.StartupAsync().ConfigureAwait(true);

            // This also triggers the Caliburn.Micro.BootstrapperBase.OnStartup
            base.OnStartup(e);
        }
Пример #5
0
        public static async Task <int> Main(string[] args)
        {
            LogSettings.RegisterDefaultLogger <DebugLogger>(LogLevels.Verbose);

            var applicationConfig = ApplicationConfigBuilder.Create()
                                    .WithApplicationName("DemoConsoleApp")
                                    .WithScanDirectories(
#if DEBUG
                @"..\..\..\..\Dapplo.Addons.TestAddonWithCostura\bin\Debug\netstandard2.0",
#else
                @"..\..\..\..\Dapplo.Addons.TestAddonWithCostura\bin\Release\netstandard2.0",
#endif
                FileLocations.StartupDirectory,
                @"MyOtherLibs"
                )
                                    .WithAssemblyNames("Dapplo.HttpExtensions", "Dapplo.Addons.TestAddonWithCostura").BuildApplicationConfig();

            using (var bootstrapper = new ApplicationBootstrapper(applicationConfig))
            {
#if DEBUG
                bootstrapper.EnableActivationLogging = true;
#endif
                bootstrapper.Configure();

                await bootstrapper.InitializeAsync().ConfigureAwait(false);

                bootstrapper.Container.Resolve <ServiceStartupShutdown>();
                // Find all, currently, available assemblies
                if (Log.IsDebugEnabled())
                {
                    foreach (var resource in bootstrapper.Resolver.EmbeddedAssemblyNames())
                    {
                        Log.Debug().WriteLine("Available embedded assembly {0}", resource);
                    }
                }
                Assembly.Load("Dapplo.HttpExtensions");
            }
            return(0);
        }