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(); }
private void Build(string projectRootPath) { var rhetosProjectContent = new RhetosProjectContentProvider(projectRootPath, _logProvider).Load(); if (FilesUtility.IsInsideDirectory(AppDomain.CurrentDomain.BaseDirectory, Path.Combine(projectRootPath, "bin"))) { throw new FrameworkException($"Rhetos build command cannot be run from the generated application folder." + $" Visual Studio integration runs it automatically from Rhetos NuGet package tools folder." + $" You can run it manually from Package Manager Console, since the tools folder it is included in PATH."); } var configuration = new ConfigurationBuilder(_logProvider) .AddOptions(rhetosProjectContent.RhetosBuildEnvironment) .AddOptions(rhetosProjectContent.RhetosTargetEnvironment) .AddKeyValue(ConfigurationProvider.GetKey((ConfigurationProviderOptions o) => o.LegacyKeysWarning), true) .AddKeyValue(ConfigurationProvider.GetKey((LoggingOptions o) => o.DelayedLogTimout), 60.0) .AddJsonFile(Path.Combine(projectRootPath, RhetosBuildEnvironment.ConfigurationFileName), optional: true) .Build(); var projectAssets = rhetosProjectContent.RhetosProjectAssets; AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolver.GetResolveEventHandler(projectAssets.Assemblies, _logProvider, true); var build = new ApplicationBuild(configuration, _logProvider, projectAssets.Assemblies, projectAssets.InstalledPackages); build.ReportLegacyPluginsFolders(); build.GenerateApplication(); }
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); }
/// <summary> /// Configures RhetosAppEnvironment and loads configuration from Rhetos run-time configuration files. /// </summary> public static IConfigurationBuilder AddRhetosAppEnvironment(this IConfigurationBuilder builder, string configurationFolder) { // Normalize path for better error handling and more robust configuration. configurationFolder = Path.GetFullPath(Path.Combine(configurationFolder, ".")); builder.AddKeyValue(ConfigurationProvider.GetKey((RhetosAppEnvironment o) => o.ApplicationRootFolder), configurationFolder); // Main run-time configuration file. builder.AddJsonFile(Path.Combine(configurationFolder, RhetosAppEnvironment.ConfigurationFileName), optional: true); // User-specific run-time configuration file. builder.AddJsonFile(Path.Combine(configurationFolder, RhetosAppEnvironment.LocalConfigurationFileName), optional: true); return(builder); }
/// <summary> /// Provides services from the referenced host application. /// Use the <see cref="CreateFrom"/> method instead, it you only need Rhetos context and components. /// </summary> public static IServiceProvider GetHostServices( string rhetosHostAssemblyPath, Action <IRhetosHostBuilder> configureRhetosHost = null, Action <HostBuilderContext, IServiceCollection> configureServices = null) { // Using the full path for better error reporting. rhetosHostAssemblyPath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, rhetosHostAssemblyPath)); if (!File.Exists(rhetosHostAssemblyPath)) { throw new ArgumentException($"Please specify the host application assembly file. File '{rhetosHostAssemblyPath}' does not exist."); } var hostBuilder = HostResolver.FindBuilder(rhetosHostAssemblyPath); hostBuilder.UseContentRoot(Path.GetDirectoryName(rhetosHostAssemblyPath)); hostBuilder.ConfigureServices((hostContext, services) => { services.AddRhetosHost((serviceProvider, rhetosHostBuilder) => { // Overriding Rhetos host application's location settings, because the default values might be incorrect when the host assembly is executed // from another process with FindBuilder. For example, it could have different AppDomain.BaseDirectory, or the assembly copied in shadow directory. rhetosHostBuilder.UseRootFolder(Path.GetDirectoryName(rhetosHostAssemblyPath)); // Use host assembly directory as root for all RhetosHostBuilder operations. rhetosHostBuilder.ConfigureConfiguration(configurationBuilder => configurationBuilder.AddKeyValue( ConfigurationProvider.GetKey((RhetosAppOptions o) => o.RhetosHostFolder), Path.GetDirectoryName(rhetosHostAssemblyPath))); // Override the RhetosHostFolder to make sure it is set to the original host folder location, not a shadow copy (for applications such as LINQPad). configureRhetosHost?.Invoke(rhetosHostBuilder); }); }); if (configureServices != null) { hostBuilder.ConfigureServices(configureServices); } return(hostBuilder.Build().Services); }