public HttpResponseMessage Get() { Stopwatch callTimer = Stopwatch.StartNew(); HttpResponseMessage result; // Build a context object to pass down the pipeline. CommerceContext context = CommerceContext.BuildSynchronousRestContext("Get users referrals", Request, new GetUsersReferralsResponse(), callTimer); try { context.Log.Information("Processing {0} call.", context.ApiCallDescription); // Add ID for the user making this call to the context. context[Key.GlobalUserId] = CommerceContext.PopulateUserId(context); // Create an executor object to execute the API invocation. GetUsersReferralsExecutor executor = new GetUsersReferralsExecutor(context); executor.Execute(); // Build the response from the result of API invocation. result = RestResponder.BuildSynchronousResponse(context); } catch (Exception ex) { result = RestResponder.BuildSynchronousResponse(context, ex); } return(result); }
public HttpResponseMessage GetEarnHistory() { Stopwatch callTimer = Stopwatch.StartNew(); HttpResponseMessage result; // Build a context object to pass down the pipeline. CommerceContext context = CommerceContext.BuildSynchronousRestContext("Get Earn/Burn history", Request, new GetEarnBurnTransactionHistoryResponse(), callTimer); try { context.Log.Information("Processing {0} call.", context.ApiCallDescription); // Add call parameters. context[Key.GlobalUserId] = CommerceContext.PopulateUserId(context); context[Key.RewardProgramType] = RewardPrograms.EarnBurn; // Create an executor object to execute the API invocation. GetRedemptionHistoryExecutor getRedemptionHistoryExecutor = new GetRedemptionHistoryExecutor(context); getRedemptionHistoryExecutor.Execute(); // Build the response from the result of API invocation. result = RestResponder.BuildSynchronousResponse(context); } catch (Exception ex) { result = RestResponder.BuildSynchronousResponse(context, ex); } return(result); }
public Task <HttpResponseMessage> Delete(Guid cardId) { Stopwatch callTimer = Stopwatch.StartNew(); Task <HttpResponseMessage> result; // Build a context object to pass down the pipeline. CommerceContext context = CommerceContext.BuildAsynchronousRestContext("Remove card", Request, new RemoveCardResponse(), callTimer); try { context[Key.CardId] = General.IntegerFromGuid(cardId); context.Log.Information("Processing {0} call.", context.ApiCallDescription); context.Log.Verbose("{0} request:\r\ncardId={1}", context.ApiCallDescription, cardId); // Add ID for the user making this call to the context. context[Key.GlobalUserId] = CommerceContext.PopulateUserId(context); context[Key.RewardProgramType] = ControllerHelper.GetRewardProgramAssociatedWithRequest(this.Request); // Create an executor object to execute the API invocation. RemoveCardExecutor removeCardExecutor = new RemoveCardExecutor(context); Task.Factory.StartNew(async() => await removeCardExecutor.Execute()); result = ((TaskCompletionSource <HttpResponseMessage>)context[Key.TaskCompletionSource]).Task; } catch (Exception ex) { result = RestResponder.CreateExceptionTask(context, ex); } return(result); }
public HttpResponseMessage Add(int rewardRecipient) { Stopwatch callTimer = Stopwatch.StartNew(); HttpResponseMessage result; // Build a context object to pass down the pipeline. CommerceContext context = CommerceContext.BuildSynchronousRestContext("Add user referral type", Request, new AddReferralTypeResponse(), callTimer); try { context.Log.Information("Processing {0} call.", context.ApiCallDescription); context[Key.RewardRecipient] = rewardRecipient; // Add user ID to the context. context[Key.GlobalUserId] = CommerceContext.PopulateUserId(context); // Create an executor object to execute the API invocation. AddReferralTypeExecutor executor = new AddReferralTypeExecutor(context); executor.Execute(); // Build the response from the result of API invocation. result = RestResponder.BuildSynchronousResponse(context); } catch (Exception ex) { result = RestResponder.BuildSynchronousResponse(context, ex); } return(result); }
public HttpResponseMessage RetrieveHistory() { Stopwatch callTimer = Stopwatch.StartNew(); HttpResponseMessage result; // Build a context object to pass down the pipeline. CommerceContext context = CommerceContext.BuildSynchronousRestContext("Get Microsoft Store voucher distribution history", Request, new GetMssVoucherDistributionHistoryResponse(), callTimer); try { // Add request information to the call context. context.Log.Information("Processing {0} call.", context.ApiCallDescription); Guid userId = CommerceContext.PopulateUserId(context); context[Key.GlobalUserId] = userId; context.Log.Verbose("{0} request for user {1}", context.ApiCallDescription, userId); // Create an executor object to execute the API invocation. MssvDistributionHistoryExecutor executor = new MssvDistributionHistoryExecutor(context); executor.Execute(); result = RestResponder.BuildSynchronousResponse(context); } catch (Exception ex) { result = RestResponder.BuildSynchronousResponse(context, ex); } return(result); }
public HttpResponseMessage Get() { Stopwatch callTimer = Stopwatch.StartNew(); HttpResponseMessage result; // Build a context object to pass down the pipeline. CommerceContext context = CommerceContext.BuildSynchronousRestContext("Get cards", Request, new V2GetCardsResponse(), callTimer); try { context.Log.Information("Processing {0} call.", context.ApiCallDescription); // Add ID for the user making this call to the context. context[Key.GlobalUserId] = CommerceContext.PopulateUserId(context); context[Key.RewardProgramType] = ControllerHelper.GetRewardProgramAssociatedWithRequest(this.Request); // Create an executor object to execute the API invocation. V2GetCardsExecutor getCardsExecutor = new V2GetCardsExecutor(context); getCardsExecutor.Execute(); // Build the response from the result of API invocation. result = RestResponder.BuildSynchronousResponse(context); } catch (Exception ex) { result = RestResponder.BuildSynchronousResponse(context, ex); } return(result); }
public HttpResponseMessage GetSecureCardOperationToken(string operation, string eventId = "", string referralCode = "", string referrer = null) { Stopwatch callTimer = Stopwatch.StartNew(); HttpResponseMessage result; // Build a context object to pass down the pipeline. CommerceContext context = CommerceContext.BuildSynchronousRestContext("Get secure card operation token", Request, new GetSecureCardOperationTokenResponse(), callTimer); try { context[Key.RequestedCrudOperation] = operation; context[Key.ReferralTypeCode] = referralCode; context[Key.ReferralEvent] = ReferralEvent.Signup; context.Log.Information("Processing {0} call.", context.ApiCallDescription); // Populate the context. context[Key.GlobalUserId] = CommerceContext.PopulateUserId(context); context[Key.ReferredUserId] = context[Key.GlobalUserId].ToString(); Guid eventIdGuid; if (Guid.TryParse(eventId, out eventIdGuid) == true) { context[Key.CorrelationId] = eventIdGuid; } context[Key.ReferrerId] = referrer; // Create an executor object to execute the API invocation. GetSecureCardOperationTokenExecutor executor = new GetSecureCardOperationTokenExecutor(context); executor.Execute(); // Build the response from the result of API invocation. result = RestResponder.BuildSynchronousResponse(context); } catch (Exception ex) { result = RestResponder.BuildSynchronousResponse(context, ex); } return(result); }
public Task <HttpResponseMessage> Add(NewCardNumber newCardNumber) { Stopwatch callTimer = Stopwatch.StartNew(); Task <HttpResponseMessage> result; // Build a context object to pass down the pipeline. CommerceContext context = CommerceContext.BuildAsynchronousRestContext("Add card and queue claiming already claimed deals", Request, new AddCardResponse(), callTimer); try { if (newCardNumber == null) { throw new ArgumentNullException("newCardNumber", "Parameter newCardNumber cannot be null."); } context.Log.Information("Processing {0} call.", context.ApiCallDescription); // Generate a legacy NewCardInfo object from the specified number. NewCardInfo newCardInfo = ControllerUtilities.GenerateLegacyCardInfo(newCardNumber); ControllerUtilities.LogObfuscatedNewCardInfo(newCardInfo, context); // Add parameters of the call to the context. context[Key.QueueJob] = true; context[Key.NewCardInfo] = newCardInfo; context[Key.GlobalUserId] = CommerceContext.PopulateUserId(context); context[Key.ReferrerId] = newCardNumber.Referrer; context[Key.RewardProgramType] = ControllerUtilities.GetRewardProgramAssociatedWithRequest(this.Request); // Create an executor object to execute the API invocation. AddCardExecutor executor = new AddCardExecutor(context); Task.Factory.StartNew(async() => await executor.Execute()); result = ((TaskCompletionSource <HttpResponseMessage>)context[Key.TaskCompletionSource]).Task; } catch (Exception ex) { result = RestResponder.CreateExceptionTask(context, ex); } return(result); }
public HttpResponseMessage Distribute(MssvDistributionDataContract request) { Stopwatch callTimer = Stopwatch.StartNew(); HttpResponseMessage result; if (request == null) { throw new ArgumentNullException("request", "Parameter request cannot be null."); } // Build a context object to pass down the pipeline. CommerceContext context = CommerceContext.BuildSynchronousRestContext("Distribute Microsoft Store vouchers", Request, new DistributeMssvResponse(), callTimer); try { // Add request information to the call context. context.Log.Information("Processing {0} call.", context.ApiCallDescription); context[Key.GlobalUserId] = CommerceContext.PopulateUserId(context); context[Key.DistributionAmount] = request.DistributionAmount; context[Key.VoucherExpirationUtc] = request.VoucherExpirationUtc; context[Key.Notes] = request.Notes; context.Log.Verbose("{0} request:\r\n{1}", context.ApiCallDescription, General.SerializeJson(request)); // Create an executor object to execute the API invocation. DistributeMssvExecutor executor = new DistributeMssvExecutor(context); executor.Execute(); result = RestResponder.BuildSynchronousResponse(context); } catch (Exception ex) { result = RestResponder.BuildSynchronousResponse(context, ex); } return(result); }