public void UpdateCache(IUpdateContextCodeFeature update)
        {
            // ignore updates that aren't for this cache instance
            if (update.ContextId != ContextMetadata <TContext> .Id)
            {
                return;
            }

            CodeFeatureId codeFeatureId = update.CodeFeatureId;

            ICachedContextFeatureState existingContext;

            if (_cache.TryGetContextFeatureState(update.ContextKey, out existingContext))
            {
                ICachedCodeFeatureState existingCode;
                if (existingContext.TryGetCodeFeatureState(codeFeatureId, out existingCode))
                {
                    if (existingCode.Enabled == update.Enabled)
                    {
                        return;
                    }

                    UpdateExistingCodeFeature(update, codeFeatureId, existingContext, existingCode);
                }
                else
                {
                    AddCodeFeatureState(update, codeFeatureId, existingContext);
                }
            }
            else
            {
                AddContextFeatureState(update, codeFeatureId);
            }
        }
Пример #2
0
        public async Task <IEnumerable <Tuple <string, ICachedCodeFeatureState> > > Load()
        {
            var results = new List <Tuple <string, ICachedCodeFeatureState> >();

            var configuration = ConfigurationManager.GetSection("fooidity") as FooidityConfiguration;

            if (configuration != null)
            {
                if (configuration.Contexts != null)
                {
                    for (int i = 0; i < configuration.Contexts.Count; i++)
                    {
                        ContextElement context = configuration.Contexts[i];

                        var contextId = new ContextId(context.Id);

                        Type contextType = contextId.GetType(false);
                        if (contextType == null)
                        {
                            throw new ConfigurationErrorsException("The context type is not valid: " + context.Id);
                        }

                        if (contextType != typeof(TContext))
                        {
                            continue;
                        }

                        if (context.Instances != null)
                        {
                            for (int instanceIndex = 0; instanceIndex < context.Instances.Count; instanceIndex++)
                            {
                                ContextInstanceElement instance = context.Instances[instanceIndex];

                                if (instance.Features != null)
                                {
                                    for (int j = 0; j < instance.Features.Count; j++)
                                    {
                                        FeatureStateElement feature = instance.Features[j];

                                        var featureId = new CodeFeatureId(feature.Id);

                                        Type codeFeatureType = featureId.GetType(false);
                                        if (codeFeatureType == null)
                                        {
                                            throw new ConfigurationErrorsException("The feature type is not valid: " + feature.Id);
                                        }

                                        ICachedCodeFeatureState codeState = new CachedCodeFeatureState(featureId, feature.Enabled);

                                        results.Add(Tuple.Create(instance.Key, codeState));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(results);
        }
Пример #3
0
        public async Task <IEnumerable <ICachedCodeFeatureState> > Load()
        {
            var codeFeatureStates = new List <ICachedCodeFeatureState>();

            var configuration = ConfigurationManager.GetSection("fooidity") as FooidityConfiguration;

            if (configuration != null)
            {
                if (configuration.Features != null)
                {
                    for (int i = 0; i < configuration.Features.Count; i++)
                    {
                        FeatureStateElement feature = configuration.Features[i];

                        var featureId = new CodeFeatureId(feature.Id);

                        Type codeFeatureType = featureId.GetType(false);
                        if (codeFeatureType == null)
                        {
                            throw new ConfigurationErrorsException("The feature type is not valid: " + feature.Id);
                        }

                        var state = new FeatureState(featureId, feature.Enabled);

                        codeFeatureStates.Add(state);
                    }
                }
            }

            return(codeFeatureStates);
        }
Пример #4
0
 public UpdateCodeFeature(CodeFeatureId codeFeatureId, bool enabled, DateTime timestamp, Guid commandId)
 {
     CodeFeatureId = codeFeatureId;
     CommandId = commandId;
     Enabled = enabled;
     Timestamp = timestamp;
 }
        public async Task<IEnumerable<ICachedCodeFeatureState>> Load()
        {
            var codeFeatureStates = new List<ICachedCodeFeatureState>();

            var configuration = ConfigurationManager.GetSection("fooidity") as FooidityConfiguration;
            if (configuration != null)
            {
                if (configuration.Features != null)
                {
                    for (int i = 0; i < configuration.Features.Count; i++)
                    {
                        FeatureStateElement feature = configuration.Features[i];

                        var featureId = new CodeFeatureId(feature.Id);

                        Type codeFeatureType = featureId.GetType(false);
                        if (codeFeatureType == null)
                            throw new ConfigurationErrorsException("The feature type is not valid: " + feature.Id);

                        var state = new FeatureState(featureId, feature.Enabled);

                        codeFeatureStates.Add(state);
                    }
                }
            }

            return codeFeatureStates;
        }
Пример #6
0
 public UpdateCodeFeature(CodeFeatureId codeFeatureId, bool enabled, DateTime timestamp, Guid commandId)
 {
     CodeFeatureId = codeFeatureId;
     CommandId     = commandId;
     Enabled       = enabled;
     Timestamp     = timestamp;
 }
Пример #7
0
            public UpdateCommand(string codeFeatureId, bool enabled)
            {
                _codeFeatureId = new CodeFeatureId(codeFeatureId);
                _enabled = enabled;

                _commandId = Guid.NewGuid();
                _timestamp = DateTime.UtcNow;
            }
Пример #8
0
            public void Should_be_parsed_into_a_type_without_the_namespace()
            {
                var id = new CodeFeatureId("urn:feature:TopLevelCodeFeature:Fooidity.Tests");

                Type type = id.GetType();

                type.ShouldBe(typeof(TopLevelCodeFeature));
            }
Пример #9
0
            public void Should_be_parsed_into_a_type()
            {
                var id = new CodeFeatureId("urn:feature:SampleCodeFeature:Fooidity.Tests.CodeFeatureName:Fooidity.Tests");

                Type type = id.GetType();

                type.ShouldBe(typeof(SampleCodeFeature));
            }
Пример #10
0
            public UpdateCommand(string codeFeatureId, bool enabled)
            {
                _codeFeatureId = new CodeFeatureId(codeFeatureId);
                _enabled       = enabled;

                _commandId = Guid.NewGuid();
                _timestamp = DateTime.UtcNow;
            }
Пример #11
0
        public async Task<ActionResult> Disable(string codeFeatureId, CancellationToken cancellationToken = default(CancellationToken))
        {
            var id = new CodeFeatureId(codeFeatureId);

            await _updateHandler.Execute(new UpdateCommand(id, false), cancellationToken);

            return Redirect("Index");
        }
Пример #12
0
            public UpdateCommand(CodeFeatureId codeFeatureId, bool enabled)
            {
                _commandId = Guid.NewGuid();
                _timestamp = DateTime.UtcNow;

                _codeFeatureId = codeFeatureId;
                _enabled = enabled;
            }
Пример #13
0
            public UpdateCommand(CodeFeatureId codeFeatureId, bool enabled)
            {
                _commandId = Guid.NewGuid();
                _timestamp = DateTime.UtcNow;

                _codeFeatureId = codeFeatureId;
                _enabled       = enabled;
            }
Пример #14
0
            public void Should_be_parsed_into_a_type()
            {
                var id = new CodeFeatureId("urn:feature:SampleCodeFeature:Fooidity.Tests.CodeFeatureName:Fooidity.Tests");

                Type type = id.GetType();

                type.ShouldBe(typeof(SampleCodeFeature));
            }
Пример #15
0
        public async Task <ActionResult> Disable(string codeFeatureId, CancellationToken cancellationToken = default(CancellationToken))
        {
            var id = new CodeFeatureId(codeFeatureId);

            await _updateHandler.Execute(new UpdateCommand(id, false), cancellationToken);

            return(Redirect("Index"));
        }
Пример #16
0
            public void Should_be_parsed_into_a_type_without_the_namespace()
            {
                var id = new CodeFeatureId("urn:feature:TopLevelCodeFeature:Fooidity.Tests");

                Type type = id.GetType();

                type.ShouldBe(typeof(TopLevelCodeFeature));
            }
 public UpdateContextCodeFeature(Uri contextId, string contextKey, CodeFeatureId codeFeatureId, bool enabled, DateTime timestamp,
     Guid commandId)
 {
     CodeFeatureId = codeFeatureId;
     CommandId = commandId;
     ContextId = contextId;
     Enabled = enabled;
     ContextKey = contextKey;
     Timestamp = timestamp;
 }
 public UpdateContextCodeFeature(Uri contextId, string contextKey, CodeFeatureId codeFeatureId, bool enabled, DateTime timestamp,
                                 Guid commandId)
 {
     CodeFeatureId = codeFeatureId;
     CommandId     = commandId;
     ContextId     = contextId;
     Enabled       = enabled;
     ContextKey    = contextKey;
     Timestamp     = timestamp;
 }
Пример #19
0
 public Update(CodeFeatureId codeFeatureId, DateTime timestamp, bool enabled, Uri organizationId = null, Uri environmentId = null,
               Guid?commandId = null)
 {
     _codeFeatureId  = codeFeatureId;
     _commandId      = commandId ?? Guid.NewGuid();
     _enabled        = enabled;
     _organizationId = organizationId;
     _environmentId  = environmentId;
     _timestamp      = timestamp;
 }
        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);
            }
        }
Пример #22
0
        public bool Equals(CodeFeatureState other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(CodeFeatureId.Equals(other.CodeFeatureId));
        }
        public void Consume(ICodeFeatureStateUpdated message)
        {
            Uri id = message.CodeFeatureId;

            try
            {
                var codeFeatureId = new CodeFeatureId(id);

                var update = new UpdateCodeFeature(codeFeatureId, message.Enabled, message.Timestamp, message.CommandId ?? message.EventId);
                _updateCache.UpdateCache(update);
            }
            catch (FormatException ex)
            {
                _log.Error(string.Format("The CodeFeatureId was not valid: {0}", id), ex);
            }
        }
Пример #24
0
        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));
                }
            }
        }
 public bool TryUpdate(CodeFeatureId id, ICachedCodeFeatureState featureState, ICachedCodeFeatureState previousFeatureState)
 {
     return _cache.TryUpdate(id, featureState, previousFeatureState);
 }
 public bool TryAdd(CodeFeatureId codeFeatureId, ICachedCodeFeatureState featureState)
 {
     return _cache.TryAdd(codeFeatureId, featureState);
 }
 public bool TryUpdate(CodeFeatureId codeFeatureId, ICachedCodeFeatureState updated, ICachedCodeFeatureState existing)
 {
     return _cache.TryUpdate(codeFeatureId, updated, existing);
 }
 public bool TryGetCodeFeatureState(CodeFeatureId codeFeatureId, out ICachedCodeFeatureState featureState)
 {
     return _cache.TryGet(codeFeatureId, out featureState);
 }
 public bool TryUpdate(CodeFeatureId id, ICachedCodeFeatureState featureState, ICachedCodeFeatureState previousFeatureState)
 {
     return(_cache.TryUpdate(id, featureState, previousFeatureState));
 }
Пример #30
0
 public FeatureState(CodeFeatureId id, bool enabled)
 {
     _enabled = enabled;
     _id      = id;
 }
Пример #31
0
 public CodeFeatureStateImpl(CodeFeatureId codeFeatureId, DateTime lastUpdated, bool enabled)
 {
     _enabled       = enabled;
     _codeFeatureId = codeFeatureId;
     _lastUpdated   = lastUpdated;
 }
 public bool TryAdd(CodeFeatureId codeFeatureId, ICachedCodeFeatureState featureState)
 {
     return(_cache.TryAdd(codeFeatureId, featureState));
 }
 public bool TryUpdate(CodeFeatureId codeFeatureId, ICachedCodeFeatureState updated, ICachedCodeFeatureState existing)
 {
     return(_cache.TryUpdate(codeFeatureId, updated, existing));
 }
Пример #34
0
 public override int GetHashCode()
 {
     return(CodeFeatureId.GetHashCode());
 }
Пример #35
0
 CodeFeatureMetadata()
 {
     _id = new CodeFeatureId(typeof(TFeature));
 }
 public FeatureState(CodeFeatureId id, bool enabled)
 {
     _enabled = enabled;
     _id = id;
 }
 public bool TryGetCodeFeatureState(CodeFeatureId codeFeatureId, out ICachedCodeFeatureState featureState)
 {
     return(_cache.TryGet(codeFeatureId, out featureState));
 }