public async Task <TFieldValue> GetDictionaryFieldValueAsync <TFieldValue>(string entityId, Expression <Func <T, object> > propertyExpression, object dictionaryKey) { if (!FlattenDictionaries) { return(default(TFieldValue)); } var redisKey = PrimaryCacheKeyFormatter(entityId); var hashPropertyName = GetPropertyName(propertyExpression); var key = JsonConvert.SerializeObject(dictionaryKey); var hashName = DictionaryHashFieldNameFormatter(hashPropertyName, key); var hashVal = await RedisDatabase.HashGetAsync(redisKey, hashName).ConfigureAwait(false); var val = JsonConvert.DeserializeObject <TFieldValue>(hashVal); return(val); }
public async Task <TFieldValue> GetFieldVaueAsync <TFieldValue>(string entityId, string hashName) { var redisKey = PrimaryCacheKeyFormatter(entityId); var fieldType = typeof(TFieldValue); var isIDictionary = fieldType.GetInterfaces().Any(pi => pi.IsGenericType && pi.GetGenericTypeDefinition() == typeof(IDictionary <,>)); if (isIDictionary && FlattenDictionaries) { var fullHash = await RedisDatabase.HashGetAllAsync(redisKey).ConfigureAwait(false); var dictionaryHashes = fullHash.Where(h => h.Name.ToString().Contains(hashName)).ToList(); var constructedDictionary = GetConstructedDictionaryPropertyInstance(fieldType, dictionaryHashes, hashName); return((TFieldValue)constructedDictionary); } var hashVal = await RedisDatabase.HashGetAsync(redisKey, hashName).ConfigureAwait(false); var val = JsonConvert.DeserializeObject <TFieldValue>(hashVal); return(val); }
public async Task <HttpActionResult <AgentInfo, DeploymentCommand> > Poll([FromBody] AgentInfo agentInfo) => await this.WithResponseContainer( agentInfo, async info => { var command = new DeploymentCommand { Execute = true }; string sourceIp = Request?.HttpContext?.Connection?.RemoteIpAddress?.ToString(); long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); var newInfo = new AgentInfo { DeploymentPackage = info.DeploymentPackage, ActiveDeploymentId = info.ActiveDeploymentId, ReportedIpAddresses = info.ReportedIpAddresses, Status = info.Status, IpAddress = sourceIp, LastUpdate = now }; await RedisDatabase.HashSetAsync(CacheKeys.AgentInfo, info.Id, newInfo); Deployment activeDeployment = await RedisDatabase.HashGetAsync <Deployment>(CacheKeys.ActiveDeployments, info.Id); command.Deployment = activeDeployment; List <DeploymentResult> deploymentResults = await RedisDatabase.GetAsync <List <DeploymentResult> >(CacheKeys.DeploymentResults); List <string> successful = (deploymentResults ?? new List <DeploymentResult>()) .Where(i => i != null) .Where(i => i.CommandResults.All(j => j.Success)) .Select(i => i.AgentInfo.ActiveDeploymentId) .ToList(); if (activeDeployment == null || successful.Contains(activeDeployment.Id) || agentInfo.ActiveDeploymentId == activeDeployment.Id) { command.Execute = false; } return(command); });