Esempio n. 1
0
        private void DbUpdate(string startupAssembly, bool shortTransactions, bool skipRecompute)
        {
            RhetosHost CreateRhetosHost(Action <IRhetosHostBuilder> configureRhetosHost)
            {
                return(RhetosHost.CreateFrom(startupAssembly, builder =>
                {
                    builder.ConfigureConfiguration(configurationBuilder =>
                    {
                        // Default settings for dbupdate command:
                        configurationBuilder.AddKeyValue(ConfigurationProvider.GetKey((DatabaseOptions o) => o.SqlCommandTimeout), 0);
                        configurationBuilder.AddKeyValue(ConfigurationProvider.GetKey((ConfigurationProviderOptions o) => o.LegacyKeysWarning), true);
                        configurationBuilder.AddKeyValue(ConfigurationProvider.GetKey((LoggingOptions o) => o.DelayedLogTimout), 60.0);
                        // Standard configuration files can override the default settings:
                        configurationBuilder.AddJsonFile(DbUpdateOptions.ConfigurationFileName, optional: true);
                        // CLI switches can override the settings from configuration files:
                        if (shortTransactions)
                        {
                            configurationBuilder.AddKeyValue(ConfigurationProvider.GetKey((DbUpdateOptions o) => o.ShortTransactions), shortTransactions);
                        }
                        if (skipRecompute)
                        {
                            configurationBuilder.AddKeyValue(ConfigurationProvider.GetKey((DbUpdateOptions o) => o.SkipRecompute), skipRecompute);
                        }
                    });
                    configureRhetosHost.Invoke(builder);
                }));
            }

            var deployment = new ApplicationDeployment(CreateRhetosHost, _logProvider);

            deployment.UpdateDatabase();
            deployment.InitializeGeneratedApplication();
        }
Esempio n. 2
0
        private void DbUpdate(DirectoryInfo applicationFolder, bool shortTransactions, bool skipRecompute)
        {
            var host = Host.Find(applicationFolder.FullName, LogProvider);

            var configuration = host.RhetosRuntime.BuildConfiguration(LogProvider, host.ConfigurationFolder, configurationBuilder =>
            {
                configurationBuilder.AddKeyValue(ConfigurationProvider.GetKey((DatabaseOptions o) => o.SqlCommandTimeout), 0);
                configurationBuilder.AddKeyValue(ConfigurationProvider.GetKey((ConfigurationProviderOptions o) => o.LegacyKeysWarning), true);
                configurationBuilder.AddKeyValue(ConfigurationProvider.GetKey((LoggingOptions o) => o.DelayedLogTimout), 60.0);
                configurationBuilder.AddConfigurationManagerConfiguration();
                configurationBuilder.AddJsonFile(Path.Combine(host.ConfigurationFolder, DbUpdateOptions.ConfigurationFileName), optional: true);
                if (shortTransactions)
                {
                    configurationBuilder.AddKeyValue(ConfigurationProvider.GetKey((DbUpdateOptions o) => o.ShortTransactions), shortTransactions);
                }
                if (skipRecompute)
                {
                    configurationBuilder.AddKeyValue(ConfigurationProvider.GetKey((DbUpdateOptions o) => o.SkipRecompute), skipRecompute);
                }
            });

            var assemblyFiles = AssemblyResolver.GetRuntimeAssemblies(configuration);

            AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolver.GetResolveEventHandler(assemblyFiles, LogProvider, true);

            var deployment = new ApplicationDeployment(configuration, LogProvider);

            deployment.UpdateDatabase();
            deployment.InitializeGeneratedApplication(host.RhetosRuntime);
        }