Esempio n. 1
0
        /// <summary>
        /// Sets up a tenant.
        /// </summary>
        /// <param name="setupService">The setup service.</param>
        /// <param name="setupOptions">The tenant setup options.</param>
        /// <param name="shellSettings">The tenant shell settings.</param>
        /// <returns>
        /// Returns <c>true</c> if successfully setup.
        /// </returns>
        public async Task <bool> SetupTenantAsync(ISetupService setupService, TenantSetupOptions setupOptions, ShellSettings shellSettings)
        {
            var setupContext = await GetSetupContextAsync(setupOptions, setupService, shellSettings);

            _logger.LogInformation("AutoSetup is initializing the site");

            await setupService.SetupAsync(setupContext);

            if (setupContext.Errors.Count == 0)
            {
                _logger.LogInformation($"AutoSetup successfully provisioned the site {setupOptions.SiteName}");

                return(true);
            }

            var stringBuilder = new StringBuilder();

            foreach (var error in setupContext.Errors)
            {
                stringBuilder.AppendLine($"{error.Key} : '{error.Value}'");
            }

            _logger.LogError("AutoSetup failed installing the site '{SiteName}' with errors: {Errors}", setupOptions.SiteName, stringBuilder);

            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a tenant shell settings.
        /// </summary>
        /// <param name="setupOptions">The setup options.</param>
        /// <returns>The <see cref="ShellSettings"/>.</returns>
        public async Task <ShellSettings> CreateTenantSettingsAsync(TenantSetupOptions setupOptions)
        {
            var shellSettings = _shellSettingsManager.CreateDefaultSettings();

            shellSettings.Name             = setupOptions.ShellName;
            shellSettings.RequestUrlHost   = setupOptions.RequestUrlHost;
            shellSettings.RequestUrlPrefix = setupOptions.RequestUrlPrefix;
            shellSettings.State            = TenantState.Uninitialized;

            shellSettings["ConnectionString"] = setupOptions.DatabaseConnectionString;
            shellSettings["TablePrefix"]      = setupOptions.DatabaseTablePrefix;
            shellSettings["DatabaseProvider"] = setupOptions.DatabaseProvider;
            shellSettings["Secret"]           = Guid.NewGuid().ToString();
            shellSettings["RecipeName"]       = setupOptions.RecipeName;

            await _shellHost.UpdateShellSettingsAsync(shellSettings);

            return(shellSettings);
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AutoSetupMiddleware"/> class.
        /// </summary>
        /// <param name="next">The next middleware in the execution pipeline.</param>
        /// <param name="shellHost">The shell host.</param>
        /// <param name="shellSettings">The shell settings.</param>
        /// <param name="shellSettingsManager">The shell settings manager.</param>
        /// <param name="distributedLock">The distributed lock.</param>
        /// <param name="options">The auto setup options.</param>
        /// <param name="logger">The logger.</param>
        public AutoSetupMiddleware(
            RequestDelegate next,
            IShellHost shellHost,
            ShellSettings shellSettings,
            IShellSettingsManager shellSettingsManager,
            IDistributedLock distributedLock,
            IOptions <AutoSetupOptions> options,
            ILogger <AutoSetupMiddleware> logger)
        {
            _next                 = next;
            _shellHost            = shellHost;
            _shellSettings        = shellSettings;
            _shellSettingsManager = shellSettingsManager;
            _distributedLock      = distributedLock;
            _options              = options.Value;
            _logger               = logger;

            _lockOptions  = _options.LockOptions;
            _setupOptions = _options.Tenants.FirstOrDefault(options => _shellSettings.Name == options.ShellName);
        }
Esempio n. 4
0
        /// <summary>
        /// Gets a setup context from the configuration.
        /// </summary>
        /// <param name="options">The tenant setup options.</param>
        /// <param name="setupService">The setup service.</param>
        /// <param name="shellSettings">The tenant shell settings.</param>
        /// <returns> The <see cref="SetupContext"/> used to setup the site.</returns>
        private static async Task <SetupContext> GetSetupContextAsync(TenantSetupOptions options, ISetupService setupService, ShellSettings shellSettings)
        {
            var recipes = await setupService.GetSetupRecipesAsync();

            var recipe = recipes.SingleOrDefault(r => r.Name == options.RecipeName);

            var setupContext = new SetupContext
            {
                Recipe        = recipe,
                ShellSettings = shellSettings,
                Errors        = new Dictionary <string, string>()
            };

            setupContext.Properties[SetupConstants.AdminEmail]               = options.AdminEmail;
            setupContext.Properties[SetupConstants.AdminPassword]            = options.AdminPassword;
            setupContext.Properties[SetupConstants.AdminUsername]            = options.AdminUsername;
            setupContext.Properties[SetupConstants.DatabaseConnectionString] = options.DatabaseConnectionString;
            setupContext.Properties[SetupConstants.DatabaseProvider]         = options.DatabaseProvider;
            setupContext.Properties[SetupConstants.DatabaseTablePrefix]      = options.DatabaseTablePrefix;
            setupContext.Properties[SetupConstants.SiteName]     = options.SiteName;
            setupContext.Properties[SetupConstants.SiteTimeZone] = options.SiteTimeZone;

            return(setupContext);
        }