private static void BindTenantsConfiguration(this IServiceCollection services, IConfiguration configuration) { var nodeConfiguration = new List <TenantConfiguration>(); // check if tenants_config file exists; if (File.Exists(ConfigurationLocations.GetTenantsConfigurationFile()) != true) { nodeConfiguration = JsonConvert.DeserializeObject <List <TenantConfiguration> >(File.ReadAllText(ConfigurationLocations.GetTenantsInitialConfigurationFile())); TenantIOWriter.WriteTenantsConfiguration(nodeConfiguration); } nodeConfiguration = JsonConvert.DeserializeObject <List <TenantConfiguration> >(File.ReadAllText(ConfigurationLocations.GetTenantsConfigurationFile())); services.AddSingleton(nodeConfiguration); }
public static List <TenantConfiguration> ReadTenantsFromConfigFile() { while (true) { try { var tenantConfigurations = File.ReadAllText(ConfigurationLocations.GetTenantsConfigurationFile()).JsonToObject <List <TenantConfiguration> >(); return(tenantConfigurations); } catch (Exception) { Thread.Sleep(100); } } }
public static bool WriteTenantsConfiguration(List <TenantConfiguration> tenantConfigurations) { if (File.Exists(ConfigurationLocations.GetTenantsConfigurationFile())) { File.Delete(ConfigurationLocations.GetTenantsConfigurationFile()); } try { File.WriteAllText(ConfigurationLocations.GetTenantsConfigurationFile(), tenantConfigurations.ToPrettyJson()); return(true); } catch (System.Exception) { return(false); } }