Exemple #1
0
        private static void CreateSettingsBox(Ui ui, DashboardModel model)
        {
            var completed = model.HasSettings;
            var id        = ui.NextId("settings").ToString();
            var message   = completed
                ? "You have successfully initialized your configuration settings."
                : "Create a configuration to manage your cluster's features and security.";
            var icon        = completed ? FontAwesomeIcons.CheckCircle : FontAwesomeIcons.PlusCircle;
            var color       = completed ? NamedColors.Grey : NamedColors.Green;
            var buttonState = completed ? " disabled" : "";

            ui.BeginDiv("card");
            {
                ui.BeginDiv("content");
                {
                    ui.Div("Configure Cluster Settings", new { @class = "header" });
                    ui.Div(message, new { @class = "description" });
                }
                ui.EndDiv();

                ui.BeginDiv($"ui bottom attached button{buttonState}", id: id)
                .Icon(icon, color).Literal("Create Settings")
                .EndDiv();
            }
            ui.EndDiv();

            if (ui.OnClick())
            {
                if (!SqliteConfigurationHelper.IsEmptyConfiguration("settings.db"))
                {
                    return;
                }

                var configSeed = ConfigurationLoader.FromEmbeddedJsonFile("seed.json");
                if (configSeed == null)
                {
                    return;
                }

                SqliteConfigurationHelper.MigrateToLatest("settings.db", SaveConfigurationOptions.Default, configSeed);
                var configRoot = ui.Context.UiServices.GetRequiredService <IConfigurationRoot>();
                configRoot.Reload();

                var options = ui.Context.UiServices.GetRequiredService <ISaveOptions <SecurityOptions> >();
                if (AuthenticationExtensions.MaybeSelfCreateMissingKeys(options.Value.Tokens))
                {
                    options.TrySave("HQ:Security", () => { });
                }

                ui.Invalidate();
            }
        }
Exemple #2
0
        private static void AddCloudConfiguration(this IConfigurationBuilder config, bool seedOnLoad)
        {
            config.AddJsonFile("seed.json", true, true);

            var root        = config.Build();
            var backend     = root.GetSection("Backend");
            var backendType = backend["Type"];

            if (string.IsNullOrWhiteSpace(backendType))
            {
                Trace.TraceWarning("No backend type found!");
                return;
            }

            Trace.TraceInformation($"Installing {backendType} back-end configuration.", backendType);

            var connectionString = backend.GetConnectionString(Constants.Options.DefaultCollection);
            var seed             = seedOnLoad ? ConfigurationLoader.FromEmbeddedJsonFile("seed.json") : null;