///<inheritdoc/> public ValueTask <bool> IsActiveAsync(ToggleExecutionContext context, CancellationToken cancellationToken = default) { string claimType = context.Data[ClaimType]?.ToString(); string allowedValues = context.Data[ClaimValues]?.ToString(); if (claimType != null && allowedValues != null) { var user = _httpContextAccessor.HttpContext.User; if (user != null && user.Identity.IsAuthenticated) { var tokenizer = new StringTokenizer(allowedValues, EsquioConstants.DEFAULT_SPLIT_SEPARATOR); var claimValues = user.Claims .Where(claim => claim.Type == claimType) .Select(claim => claim.Value); foreach (var item in claimValues) { if (item != null) { if (tokenizer.Contains(item, StringSegmentComparer.OrdinalIgnoreCase)) { return(new ValueTask <bool>(true)); } } } } } return(new ValueTask <bool>(false)); }
/// <inheritdoc /> public ValueTask <bool> IsActiveAsync(ToggleExecutionContext context, CancellationToken cancellationToken = default) { string environments = context.Data[Environments]?.ToString(); if (environments != null) { var tokenizer = new StringTokenizer(environments, EsquioConstants.DEFAULT_SPLIT_SEPARATOR); var isActive = tokenizer.Contains(_hostEnvironment.EnvironmentName, StringSegmentComparer.OrdinalIgnoreCase); return(new ValueTask <bool>(isActive)); } return(new ValueTask <bool>(false)); }
/// <inheritdoc/> public ValueTask <bool> IsActiveAsync(ToggleExecutionContext context, CancellationToken cancellationToken = default) { string environmentVariable = context.Data[EnvironmentVariable]?.ToString(); string validValues = context.Data[Values]?.ToString(); string environmentVariableValue = Environment .GetEnvironmentVariable(environmentVariable); if (environmentVariableValue != null) { var tokenizer = new StringTokenizer(validValues, EsquioConstants.DEFAULT_SPLIT_SEPARATOR); var active = tokenizer.Contains(environmentVariableValue, StringSegmentComparer.OrdinalIgnoreCase); return(new ValueTask <bool>(active)); } return(new ValueTask <bool>(false)); }
///<inheritdoc/> public ValueTask <bool> IsActiveAsync(ToggleExecutionContext context, CancellationToken cancellationToken = default) { var currentUserName = GetCurrentUserName(); if (currentUserName != null) { string activeUserNames = context.Data[Users]?.ToString(); if (activeUserNames != null) { var tokenizer = new StringTokenizer(activeUserNames, EsquioConstants.DEFAULT_SPLIT_SEPARATOR); var isActive = tokenizer.Contains(currentUserName, StringSegmentComparer.OrdinalIgnoreCase); return(new ValueTask <bool>(isActive)); } } return(new ValueTask <bool>(false)); }
/// <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(); string environments = data.Environments?.ToString(); var currentEnvironment = await _environmentNameProviderService .GetEnvironmentNameAsync(cancellationToken); if (environments != null && currentEnvironment != null) { var tokenizer = new StringTokenizer(environments, EsquioConstants.DEFAULT_SPLIT_SEPARATOR); return(tokenizer.Contains(currentEnvironment, StringSegmentComparer.OrdinalIgnoreCase)); } return(false); }
public async Task <bool> IsActiveAsync(string featureName, string productName = null, CancellationToken cancellationToken = default) { var feature = await _featureStore.FindFeatureAsync(featureName, productName); var toggle = feature.GetToggle(this.GetType().FullName); var data = toggle.GetData(); string allowedCountries = data.Countries; var currentCountry = await _locationProviderService .GetCountryCode(GetRemoteIpAddress()); if (allowedCountries != null && currentCountry != null) { var tokenizer = new StringTokenizer(allowedCountries, EsquioConstants.DEFAULT_SPLIT_SEPARATOR); return(tokenizer.Contains(currentCountry, StringSegmentComparer.OrdinalIgnoreCase)); } return(false); }
public async Task <bool> IsActiveAsync(string featureName, string productName = null, CancellationToken cancellationToken = default) { var feature = await _featureStore.FindFeatureAsync(featureName, productName); var toggle = feature.GetToggle(this.GetType().FullName); var data = toggle.GetData(); var allowedCountries = (string)data.Countries; var location = await GetLocationFromIp(GetRemoteIpAddress(), cancellationToken); var currentCountry = location?.Country; if (allowedCountries != null && currentCountry != null) { var tokenizer = new StringTokenizer(allowedCountries, split_characters); return(tokenizer.Contains(currentCountry, StringSegmentComparer.OrdinalIgnoreCase)); } return(false); }