Ejemplo n.º 1
0
        /// <inheritdoc/>
        public async Task <bool> IsActiveAsync(string featureName, string productName = null, CancellationToken cancellationToken = default)
        {
            var feature = await _featureStore
                          .FindFeatureAsync(featureName, productName, cancellationToken);

            var toggle = feature.GetToggle(this.GetType().FullName);
            var data   = toggle.GetData();

            if (Double.TryParse(data.Percentage.ToString(), out double percentage))
            {
                if (percentage > 0)
                {
                    var currentUserName = await _userNameProviderService
                                          .GetCurrentUserNameAsync();

                    if (currentUserName != null)
                    {
                        // this only apply for authenticted users, we apply some entropy to currentUserName.
                        // adding this entropy ensure that not all features with gradual rollout for username are enabled/disable at the same time for the same user.

                        var assignedPartition = _partitioner.ResolvePartition(featureName + currentUserName, partitions: 100);

                        return(assignedPartition <= percentage);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        ///<inheritdoc/>
        public async Task <bool> IsActiveAsync(string featureName, string productName = null, CancellationToken cancellationToken = default)
        {
            var currentUserName = await _userNameProviderService
                                  .GetCurrentUserNameAsync();

            if (currentUserName != null)
            {
                var feature = await _featureStore.FindFeatureAsync(featureName, productName, cancellationToken);

                var toggle = feature.GetToggle(this.GetType().FullName);
                var data   = toggle.GetData();

                string activeUserNames = data.Users?.ToString();

                if (activeUserNames != null)
                {
                    var tokenizer = new StringTokenizer(activeUserNames, EsquioConstants.DEFAULT_SPLIT_SEPARATOR);

                    return(tokenizer.Contains(
                               currentUserName, StringSegmentComparer.OrdinalIgnoreCase));
                }
            }

            return(false);
        }
Ejemplo n.º 3
0
        public async Task <bool> IsActiveAsync(string featureName, string productName = null, CancellationToken cancellationToken = default)
        {
            var feature = await _featureStore.FindFeatureAsync(featureName, productName, cancellationToken);

            var toggle = feature.GetToggle(this.GetType().FullName);
            var data   = toggle.GetData();

            if (Double.TryParse(data.Percentage.ToString(), out double percentage))
            {
                if (percentage > 0)
                {
                    var currentUserName = await _userNameProviderService
                                          .GetCurrentUserNameAsync() ?? AnonymousUser;

                    var assignedPartition = Partitioner.ResolveToLogicalPartition(currentUserName, Partitions);

                    return(assignedPartition <= percentage);
                }
            }

            return(false);
        }