Beispiel #1
0
 public virtual async Task <Response> RewardAsync(string eventId, PersonalizerRewardOptions reward, CancellationToken cancellationToken = default)
 {
     using var scope = _clientDiagnostics.CreateScope("EventsClient.Reward");
     scope.Start();
     try
     {
         return(await RestClient.RewardAsync(eventId, reward, cancellationToken).ConfigureAwait(false));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
Beispiel #2
0
 public virtual Response Reward(string eventId, PersonalizerRewardOptions reward, CancellationToken cancellationToken = default)
 {
     using var scope = _clientDiagnostics.CreateScope("EventsClient.Reward");
     scope.Start();
     try
     {
         return(RestClient.Reward(eventId, reward, cancellationToken));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
Beispiel #3
0
        public Response Reward(string eventId, PersonalizerRewardOptions reward, CancellationToken cancellationToken = default)
        {
            if (eventId == null)
            {
                throw new ArgumentNullException(nameof(eventId));
            }
            if (reward == null)
            {
                throw new ArgumentNullException(nameof(reward));
            }

            using var message = CreateRewardRequest(eventId, reward);
            _pipeline.Send(message, cancellationToken);
            switch (message.Response.Status)
            {
            case 204:
                return(message.Response);

            default:
                throw _clientDiagnostics.CreateRequestFailedException(message.Response);
            }
        }
Beispiel #4
0
        internal HttpMessage CreateRewardRequest(string eventId, PersonalizerRewardOptions reward)
        {
            var message = _pipeline.CreateMessage();
            var request = message.Request;

            request.Method = RequestMethod.Post;
            var uri = new RawRequestUriBuilder();

            uri.AppendRaw(endpoint, false);
            uri.AppendRaw("/personalizer/v1.1-preview.3", false);
            uri.AppendPath("/events/", false);
            uri.AppendPath(eventId, true);
            uri.AppendPath("/reward", false);
            request.Uri = uri;
            request.Headers.Add("Accept", "application/json");
            request.Headers.Add("Content-Type", "application/json");
            var content = new Utf8JsonRequestContent();

            content.JsonWriter.WriteObjectValue(reward);
            request.Content = content;
            return(message);
        }
 /// <summary> Report reward between 0 and 1 that resulted from using the action specified in rewardActionId, for the specified event. </summary>
 /// <param name="eventId"> The event id this reward applies to. </param>
 /// <param name="reward"> The reward should be a floating point number, typically between 0 and 1. </param>
 /// <param name="cancellationToken"> The cancellation token to use. </param>
 public virtual Response Reward(string eventId, float reward, CancellationToken cancellationToken = default)
 {
     using var scope = clientDiagnostics.CreateScope("PersonalizerClient.Reward");
     scope.Start();
     try
     {
         if (useLocalInference)
         {
             validateAndUpdateLiveModelConfig();
             return(rlNetProcessor.Value.Reward(eventId, reward));
         }
         else
         {
             PersonalizerRewardOptions rewardOptions = new PersonalizerRewardOptions(reward);
             return(EventsRestClient.Reward(eventId, rewardOptions, cancellationToken));
         }
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
Beispiel #6
0
        public async Task <Response> RewardAsync(string eventId, PersonalizerRewardOptions reward, CancellationToken cancellationToken = default)
        {
            if (eventId == null)
            {
                throw new ArgumentNullException(nameof(eventId));
            }
            if (reward == null)
            {
                throw new ArgumentNullException(nameof(reward));
            }

            using var message = CreateRewardRequest(eventId, reward);
            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);

            switch (message.Response.Status)
            {
            case 204:
                return(message.Response);

            default:
                throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false);
            }
        }