void AddCodeFeatureState(IUpdateContextCodeFeature update, CodeFeatureId codeFeatureId, ICachedContextFeatureState existingContext) { var featureState = new CachedCodeFeatureState(codeFeatureId, update.Enabled); bool updated = existingContext.TryAdd(codeFeatureId, featureState); if (updated) { NotifyUpdated(update, featureState); } }
void AddContextFeatureState(IUpdateContextCodeFeature update, CodeFeatureId codeFeatureId) { var featureState = new CachedCodeFeatureState(codeFeatureId, update.Enabled); var contextFeatureState = new CachedContextFeatureState(Enumerable.Repeat(featureState, 1), update.ContextKey); bool updated = _cache.TryAdd(update.ContextKey, contextFeatureState); if (updated) { NotifyUpdated(update, featureState); } }
public void UpdateCache(IUpdateCodeFeature update) { CodeFeatureId codeFeatureId = update.CodeFeatureId; ICachedCodeFeatureState existingFeatureState; if (_cache.TryGetState(codeFeatureId, out existingFeatureState)) { if (existingFeatureState.Enabled == update.Enabled) { return; } var updatedFeatureState = new CachedCodeFeatureState(codeFeatureId, update.Enabled); DateTime startTime = DateTime.UtcNow; bool updated = _cache.TryUpdate(codeFeatureId, updatedFeatureState, existingFeatureState); DateTime endTime = DateTime.UtcNow; if (updated) { var updatedEvent = new CodeFeatureStateCacheUpdated(startTime, endTime - startTime, updatedFeatureState.Id, updatedFeatureState.Enabled, update.CommandId); _cacheUpdated.ForEach(x => x.OnNext(updatedEvent)); } } else { var featureState = new CachedCodeFeatureState(codeFeatureId, update.Enabled); DateTime startTime = DateTime.UtcNow; bool updated = _cache.TryAdd(codeFeatureId, featureState); DateTime endTime = DateTime.UtcNow; if (updated) { var updatedEvent = new CodeFeatureStateCacheUpdated(startTime, endTime - startTime, featureState.Id, featureState.Enabled, update.CommandId); _cacheUpdated.ForEach(x => x.OnNext(updatedEvent)); } } }