@namespace Oqtane.Installer.Controls @implements Oqtane.Interfaces.IDatabaseConfigControl @inject IStringLocalizer Localizer @{ foreach (var field in _connectionStringFields) { var fieldId = field.Name.ToLowerInvariant(); if (field.Name != "IntegratedSecurity") { var isVisible = ""; var fieldType = (field.Name == "Pwd") ? "password" : "text"; if ((field.Name == "Uid" || field.Name == "Pwd") ) { var intSecurityField = _connectionStringFields.Single(f => f.Name == "IntegratedSecurity"); if (intSecurityField != null) { isVisible = (Convert.ToBoolean(intSecurityField.Value)) ? "display: none;" : ""; } } field.Value = field.Value.Replace("{{Date}}", DateTime.UtcNow.ToString("yyyyMMddHHmm")); if (IsInstaller) { } else { } } else { if (IsInstaller) { } else { } } } } @code { [Parameter] public bool IsInstaller { get; set; } private readonly List _connectionStringFields = new() { new() {Name = "Server", FriendlyName = "Server", Value = "127.0.0.1", HelpText="Enter the database server"}, new() {Name = "Port", FriendlyName = "Port", Value = "5432", HelpText="Enter the port used to connect to the server"}, new() {Name = "Database", FriendlyName = "Database", Value = "Oqtane-{{Date}}", HelpText="Enter the name of the database"}, new() {Name = "IntegratedSecurity", FriendlyName = "Integrated Security", Value = "true", HelpText="Select if you want integrated security or not"}, new() {Name = "Uid", FriendlyName = "User Id", Value = "", HelpText="Enter the username to use for the database"}, new() {Name = "Pwd", FriendlyName = "Password", Value = "", HelpText="Enter the password to use for the database"} }; public string GetConnectionString() { var connectionString = String.Empty; var server = _connectionStringFields[0].Value; var port = _connectionStringFields[1].Value; var database = _connectionStringFields[2].Value; var integratedSecurity = Boolean.Parse(_connectionStringFields[3].Value); var userId = _connectionStringFields[4].Value; var password = _connectionStringFields[5].Value; if (!String.IsNullOrEmpty(server) && !String.IsNullOrEmpty(database) && !String.IsNullOrEmpty(port)) { connectionString = $"Server={server};Port={port};Database={database};"; } if (integratedSecurity) { connectionString += "Integrated Security=true;"; } else { if (!String.IsNullOrEmpty(userId) && !String.IsNullOrEmpty(password)) { connectionString += $"User ID={userId};Password={password};"; } else { connectionString = String.Empty; } } return connectionString; } }