public async Task <ClientConfiguration> GetConfigurationAsync() { // IIS web site names should be predefined correctly string host = HostingEnvironment.ApplicationHost.GetSiteName(); Guid clientId = CompanyHelper.GetCompanyIdByHost(host); ClientConfigurationDto configurationDto = _cacheConfigurationRepository.GetByClientId(clientId); if (configurationDto != null) { return(MapClientConfigurationDtoToClientConfiguration(configurationDto)); } configurationDto = await _dbConfigurationRepository.GetByClientIdAsync(clientId); List <string> activeModules = await _dbConfigurationRepository.GetActiveModulesByClientIdAsync(clientId); if (configurationDto == null || activeModules == null || activeModules.Count == 0) { throw new ConfigurationErrorsException($"Configuration for the {host} was not found"); } configurationDto.ActiveModules = string.Join(",", activeModules); _cacheConfigurationRepository.CreateConfiguration(configurationDto); return(MapClientConfigurationDtoToClientConfiguration(configurationDto)); }
public Task <bool> CreateConfiguration(ClientConfigurationDto configuration) { MemoryCache memoryCache = MemoryCache.Default; string config = JsonConvert.SerializeObject(configuration); return(Task.FromResult(memoryCache.Add(configuration.ClientId.ToString(), config, DateTimeOffset.UtcNow.AddMilliseconds(FiveMunutesInMiliseconds)))); }
public ClientConfigurationDto GetByClientId(Guid clientId) { MemoryCache memoryCache = MemoryCache.Default; object valueFromCache = memoryCache.Get(clientId.ToString()); if (valueFromCache == null) { return(null); } string value = valueFromCache.ToString(); ClientConfigurationDto configurationDto = JsonConvert.DeserializeObject <ClientConfigurationDto>(value); return(configurationDto); }
private static ClientConfiguration MapClientConfigurationDtoToClientConfiguration(ClientConfigurationDto configurationDto) { return(new ClientConfiguration { ClientId = configurationDto.ClientId, ConnectionString = configurationDto.ConnectionString, ActiveModules = configurationDto.ActiveModules?.Split(',').ToList() ?? new List <string>() }); }