private async Task WriteConfigFileToDiskAsync(FirstStartConfiguration firstStartConfiguration, CancellationToken cancellationToken = default) { string settingsFileLocation = Path.Combine(Env.ContentRootPath, "appsettings.json"); if (!System.IO.File.Exists(settingsFileLocation)) { FileStream fileStream = System.IO.File.Create(settingsFileLocation); byte[] bytes = ASCIIEncoding.ASCII.GetBytes("{}"); await fileStream.WriteAsync(bytes, 0, bytes.Length, cancellationToken); fileStream.Close(); await fileStream.DisposeAsync(); } string fileContents = await System.IO.File.ReadAllTextAsync(settingsFileLocation, cancellationToken); JObject jsonFile = JsonConvert.DeserializeObject <JObject>(fileContents); if (string.IsNullOrEmpty(firstStartConfiguration.ConnectionString)) { jsonFile["ConnectionStrings"][$"{firstStartConfiguration.Database}Connection"] = firstStartConfiguration.ConnectionString; } jsonFile[ConstStrings.IsFirstStart] = false; jsonFile[ConstStrings.InitializeFakeData] = firstStartConfiguration.InitializeFakeData; jsonFile[ConstStrings.AdminUserName] = firstStartConfiguration.AdminUserName; jsonFile[ConstStrings.AdminEmail] = firstStartConfiguration.AdminEmail; jsonFile[ConstStrings.AdminPassword] = firstStartConfiguration.AdminPassword; jsonFile[ConstStrings.DataProvider] = firstStartConfiguration.Database; await System.IO.File.WriteAllTextAsync(settingsFileLocation, JsonConvert.SerializeObject(jsonFile, Formatting.Indented), cancellationToken); }
private async Task WriteConfigFileToDiskAsync(FirstStartConfiguration firstStartConfiguration) { string settingsFileLocation = Path.Combine(Env.ContentRootPath, "appsettings.json"); if (!System.IO.File.Exists(settingsFileLocation)) { FileStream fileStream = System.IO.File.Create(settingsFileLocation); byte[] bytes = ASCIIEncoding.ASCII.GetBytes("{}"); await fileStream.WriteAsync(bytes, 0, bytes.Length); fileStream.Close(); await fileStream.DisposeAsync(); } string fileContents = await System.IO.File.ReadAllTextAsync(settingsFileLocation); JObject jsonFile = JsonConvert.DeserializeObject <JObject>(fileContents); jsonFile["IsFirstStart"] = false; jsonFile["DataProvider"] = firstStartConfiguration.Database; jsonFile["ConnectionStrings"][$"{firstStartConfiguration.Database}Connection"] = firstStartConfiguration.ConnectionString; await System.IO.File.WriteAllTextAsync(settingsFileLocation, JsonConvert.SerializeObject(jsonFile, Formatting.Indented)); }
public IndexModel(IWebHostEnvironment env, IConfiguration config) { Env = env ?? throw new System.ArgumentNullException(nameof(env)); Config = config ?? throw new System.ArgumentNullException(nameof(config)); FirstStartConfig = new FirstStartConfiguration(); }