Example #1
0
        /// <summary>
        /// Runs the activity asynchronously.
        /// </summary>
        /// <param name="sharedContext">The shared context.</param>
        /// <returns>
        /// Next activity to be run or <c>null</c> if last in flow.
        /// </returns>
        public async Task <IActivity> RunAsync(SharedContext sharedContext)
        {
            BargainFinderMaxRQ request = this.CreateRequest(this.data);

            sharedContext.AddSerializedResultJson(RequestJsonSharedContextKey, request);
            var httpResponse = await this.restClient.PostAsync <BargainFinderMaxRQ, BargainFinderMaxRS>(Endpoint, request);

            sharedContext.AddRestResult <BargainFinderMaxRS>(SharedContextKey, httpResponse, false, ResponseJsonSharedContextKey);
            sharedContext.AddResult(RequestUrlSharedContextKey, httpResponse.RequestUri);
            return(null);
        }
Example #2
0
 /// <summary>
 /// Adds the REST result (either deserialized model or error message) to shared context.
 /// </summary>
 /// <typeparam name="TResult">The type of the result.</typeparam>
 /// <param name="sharedContext">The shared context.</param>
 /// <param name="key">The shared context key.</param>
 /// <param name="httpResponse">The HTTP response.</param>
 /// <param name="allowedNotFound">if set to <c>true</c>, then 404 Not Found is not treated as error.</param>
 /// <param name="jsonKey">The shared context key under which the reformatted JSON response will be placed.</param>
 public static void AddRestResult <TResult>(
     this SharedContext sharedContext,
     string key,
     HttpResponse <TResult> httpResponse,
     bool allowedNotFound = false,
     string jsonKey       = null)
 {
     if (httpResponse.IsSuccess || (allowedNotFound && httpResponse.StatusCode == HttpStatusCode.NotFound))
     {
         sharedContext.AddResult(key, httpResponse.Value);
         sharedContext.AddSerializedResultJson(jsonKey, httpResponse.Value);
     }
     else
     {
         sharedContext.AddResult(key, httpResponse.Message);
         sharedContext.IsFaulty = true;
     }
 }