/// <summary> /// Gets Configuration /// </summary> /// <param name="type">Type of configuration to be retrieved</param> /// <param name="id">Identity of Configuration requested i.e which client requested the configuration</param> /// <returns>ConfigInstance of the type requested</returns> public async Task <ConfigInstance> GetAsync(Type type, ConfigurationIdentity id) { var configId = type.Name; var result = ConfigFactory.CreateGenericInstance(type, id); var json = await storageConnector.GetConfigFileAsync(type.Name, id.Client.ClientId); if (!string.IsNullOrWhiteSpace(json)) { result.SetConfiguration(ConfigStorageObjectHelper.ParseConfigurationStoredObject(json, type)); } return(result); }
/// <summary> /// Gets Collection Configuration /// </summary> /// <param name="type">Type of configuration to be retrieved</param> /// <param name="id">Identity of Configuration requested i.e which client requested the configuration</param> /// <returns>Enumerable of the type requested</returns> public async Task <IEnumerable> GetCollectionAsync(Type type, ConfigurationIdentity id) { var configId = type.Name; var json = await storageConnector.GetConfigFileAsync(type.Name, id.Client.ClientId); var configType = BuildGenericType(typeof(List <>), type); if (!string.IsNullOrWhiteSpace(json)) { return((IEnumerable)ConfigStorageObjectHelper.ParseConfigurationStoredObject(json, configType)); } return((IEnumerable)Activator.CreateInstance(configType)); }
private static ConfigInstance BuildInstance(ConfigurationIdentity targetConfigurationIdentity, SnapshotTextEntry entry, ConfigurationRegistration configInfo) { if (configInfo.IsCollection) { var collectionType = typeof(IEnumerable <>).MakeGenericType(configInfo.ConfigType); var newCollectionInstance = ConfigFactory.CreateGenericCollectionInstance(configInfo.ConfigType, targetConfigurationIdentity); newCollectionInstance.SetConfiguration(ConfigStorageObjectHelper.ParseConfigurationStoredObject(entry.ConfigurationJson, collectionType)); return(newCollectionInstance); } var newInstance = ConfigFactory.CreateGenericInstance(configInfo.ConfigType, targetConfigurationIdentity); newInstance.SetConfiguration(ConfigStorageObjectHelper.ParseConfigurationStoredObject(entry.ConfigurationJson, configInfo.ConfigType)); return(newInstance); }