Exemplo n.º 1
0
        public Task <HttpResponseMessage> Claim(ClaimDealPayload claimDealPayload)
        {
            Stopwatch callTimer = Stopwatch.StartNew();

            Task <HttpResponseMessage> result;

            // Build a context object to pass down the pipeline.
            CommerceContext context = CommerceContext.BuildAsynchronousRestContext("Claim deal in partners and data store",
                                                                                   Request, new ClaimDealResponse(), callTimer);

            try
            {
                context.Log.Information("Processing {0} call.", context.ApiCallDescription);
                CustomIdentity clientIdentity = (CustomIdentity)Thread.CurrentPrincipal.Identity;
                context.Log.Verbose("Presented credentials are for role \"{0}\" and include token \"{1}\".",
                                    clientIdentity.Name, clientIdentity.PresentedClientToken);
                context.Log.Verbose("{0} request:\r\n{1}", context.ApiCallDescription, General.SerializeJson(claimDealPayload));

                // Add payload information to the context.
                context[Key.ClaimDealPayload] = claimDealPayload;

                // Create an executor object to execute the API invocation.
                ClaimDealExecutor claimDealExecutor = new ClaimDealExecutor(context);
                Task.Factory.StartNew(async() => await claimDealExecutor.Execute());

                result = ((TaskCompletionSource <HttpResponseMessage>)context[Key.TaskCompletionSource]).Task;
            }
            catch (Exception ex)
            {
                result = RestResponder.CreateExceptionTask(context, ex);
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Extracts required elements from the ClaimDealPayload.
        /// </summary>
        /// <returns>
        /// The result of the operation.
        /// </returns>
        private ResultCode ExtractClaimDealPayload()
        {
            ResultCode result = ResultCode.Success;

            Context.Log.Verbose("Extracting ClaimDealPayload.");
            ClaimDealPayload claimDealPayload = Context[Key.ClaimDealPayload] as ClaimDealPayload;

            if (claimDealPayload != null)
            {
                if (claimDealPayload.UserId != Guid.Empty)
                {
                    Context[Key.GlobalUserId] = claimDealPayload.UserId;

                    if (claimDealPayload.ClaimDealInfo != null)
                    {
                        Context[Key.GlobalDealId] = claimDealPayload.ClaimDealInfo.DealId;
                        Context[Key.CardId]       = claimDealPayload.ClaimDealInfo.CardId;
                    }
                    else
                    {
                        Context.Log.Verbose("ClaimDealInfo is null.");
                        result = ResultCode.ParameterCannotBeNull;
                    }
                }
                else
                {
                    Context.Log.Verbose("UserId is Guid.Empty.");
                    result = ResultCode.InvalidParameter;
                }
            }
            else
            {
                Context.Log.Verbose("ClaimDealPayload object is null.");
                result = ResultCode.ParameterCannotBeNull;
            }

            return(result);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the ClaimDealTask class.
 /// </summary>
 /// <param name="claimDealPayload">
 /// The claimDealPayload to send to the ClaimDeal API.
 /// </param>
 /// <param name="log">
 /// The CommerceLog object through which log entries can be made.
 /// </param>
 public ClaimDealTask(ClaimDealPayload claimDealPayload,
                      CommerceLog log)
 {
     ClaimDealPayload = claimDealPayload;
     Log = log;
 }