예제 #1
0
        public async Task <IActionResult> Post(GroupRollout groupRollout)
        {
            if (groupRollout == null)
            {
                return(BadRequest(CreateProblemDetailsResponse("GroupRollout is required")));
            }

            GroupRollout existingGroupRolloutWithName = await _groupRolloutService
                                                        .GetByName(groupRollout.Name)
                                                        .ConfigureAwait(false);

            if (existingGroupRolloutWithName != null)
            {
                return(BadRequest(CreateProblemDetailsResponse("GroupRollout with the same name already exists")));
            }

            groupRollout.CreatedOn = DateTimeOffset.Now;
            GroupRollout newGroupRollout = await _groupRolloutService
                                           .AddAsync(groupRollout)
                                           .ConfigureAwait(false);

            return(newGroupRollout == null
                ? (IActionResult)StatusCode(StatusCodes.Status500InternalServerError)
                : Ok(newGroupRollout));
        }
예제 #2
0
        public async Task <IActionResult> Put(Guid id, GroupRollout groupRollout)
        {
            if (id == Guid.Empty)
            {
                return(BadRequest(CreateProblemDetailsResponse("Invalid Id")));
            }

            if (groupRollout == null)
            {
                return(BadRequest(CreateProblemDetailsResponse("GroupRollout is required")));
            }

            GroupRollout existingGroupRollout = await _groupRolloutService
                                                .GetByIdAsync(id)
                                                .ConfigureAwait(false);

            if (existingGroupRollout == null)
            {
                return(NotFound());
            }

            if (existingGroupRollout.Id != groupRollout.Id)
            {
                return(BadRequest(CreateProblemDetailsResponse("GroupRollout Id mismatch")));
            }

            groupRollout.ModifiedOn = DateTimeOffset.Now;
            GroupRollout updatedGroupRollout = _groupRolloutService.Update(groupRollout);

            return(updatedGroupRollout == null
                ? (IActionResult)StatusCode(StatusCodes.Status500InternalServerError)
                : Ok(updatedGroupRollout));
        }
예제 #3
0
        /// <summary>
        /// Performs a targeting evaluation using the provided <see cref="TargetingContext"/> to determine if a feature should be enabled.
        /// </summary>
        /// <param name="context">The feature evaluation context.</param>
        /// <param name="targetingContext">The targeting context to use during targeting evaluation.</param>
        /// <exception cref="ArgumentNullException">Thrown if either <paramref name="context"/> or <paramref name="targetingContext"/> is null.</exception>
        /// <returns>True if the feature is enabled, false otherwise.</returns>
        public Task <bool> EvaluateAsync(FeatureFilterEvaluationContext context, ITargetingContext targetingContext)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (targetingContext == null)
            {
                throw new ArgumentNullException(nameof(targetingContext));
            }

            var settings = (TargetingFilterSettings)context.Parameters;

            if (!TryValidateSettings(settings, out string paramName, out string message))
            {
                throw new ArgumentException(message, paramName);
            }

            //
            // Check if the user is being targeted directly
            if (targetingContext.UserId != null &&
                settings.Audience.Users != null &&
                settings.Audience.Users.Any(user => targetingContext.UserId.Equals(user, ComparisonType)))
            {
                return(Task.FromResult(true));
            }

            //
            // Check if the user is in a group that is being targeted
            if (targetingContext.Groups != null &&
                settings.Audience.Groups != null)
            {
                foreach (string group in targetingContext.Groups)
                {
                    GroupRollout groupRollout = settings.Audience.Groups.FirstOrDefault(g => g.Name.Equals(group, ComparisonType));

                    if (groupRollout != null)
                    {
                        string audienceContextId = $"{targetingContext.UserId}\n{context.FeatureName}\n{group}";

                        if (IsTargeted(audienceContextId, groupRollout.RolloutPercentage))
                        {
                            return(Task.FromResult(true));
                        }
                    }
                }
            }

            //
            // Check if the user is being targeted by a default rollout percentage
            string defaultContextId = $"{targetingContext.UserId}\n{context.FeatureName}";

            return(Task.FromResult(IsTargeted(defaultContextId, settings.Audience.DefaultRolloutPercentage)));
        }
예제 #4
0
        public async Task <IActionResult> Get(string groupRolloutName, CancellationToken cancellationToken = default)
        {
            if (string.IsNullOrEmpty(groupRolloutName))
            {
                return(BadRequest("Invalid GroupRolloutName provided"));
            }

            GroupRollout groupRollout = await _groupRolloutService
                                        .GetByName(groupRolloutName, cancellationToken)
                                        .ConfigureAwait(false);

            return(groupRollout == null ? (IActionResult)NotFound() : Ok(groupRollout));
        }
예제 #5
0
        public async Task <IActionResult> Post(GroupRollout groupRollout)
        {
            if (groupRollout == null)
            {
                return(BadRequest("GroupRollout is required"));
            }

            using (IFeatureManagementAppTierAPI api = CreateFeatureManagementApi())
            {
                HttpOperationResponse <object> result = await api.PostGroupRolloutWithHttpMessagesAsync(groupRollout);

                return(CreateResponse <GroupRollout>(result));
            }
        }
예제 #6
0
        public async Task <IActionResult> Delete(Guid id)
        {
            if (id == Guid.Empty)
            {
                return(BadRequest(CreateProblemDetailsResponse("Invalid Id")));
            }

            _groupRolloutService.DeleteById(id);
            GroupRollout groupRollout = await _groupRolloutService.GetByIdAsync(id);

            return(groupRollout == null
                ? StatusCode(StatusCodes.Status500InternalServerError)
                : Ok());
        }
예제 #7
0
        public async Task <IActionResult> Get(Guid id)
        {
            if (id == Guid.Empty)
            {
                return(BadRequest(CreateProblemDetailsResponse("Invalid Id")));
            }

            GroupRollout groupRollout = await _groupRolloutService
                                        .GetByIdAsync(id)
                                        .ConfigureAwait(false);

            return(groupRollout == null
                ? (IActionResult)NotFound()
                : Ok(groupRollout));
        }
예제 #8
0
 /// <summary>
 /// Update a Group Rollout
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='id'>
 /// </param>
 /// <param name='body'>
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <object> PutGroupRolloutAsync(this IFeatureManagementAppTierAPI operations, System.Guid id, GroupRollout body = default(GroupRollout), CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.PutGroupRolloutWithHttpMessagesAsync(id, body, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }