Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Pings the Commerce database.
        /// </summary>
        /// <returns>
        /// * True if the Commerce database could be pinged.
        /// * Else returns false.
        /// </returns>
        private static bool PingCommerce()
        {
            // Ping Commerce by attempting to retrieve cards for a user known not to exist.
            GetCardsResponse response = new GetCardsResponse();
            CommerceContext  context  = CommerceContext.BuildSynchronousRestContext(String.Empty, null, response, new Stopwatch());

            context[Key.GlobalUserId]           = Guid.Empty;
            context[Key.RewardProgramType]      = RewardPrograms.All;
            context.Log.OnlyLogIfVerbosityIsAll = true;
            V2GetCardsExecutor getCardsExecutor = new V2GetCardsExecutor(context);

            getCardsExecutor.Execute();
            return(response.ResultSummary.GetResultCode() == ResultCode.UnregisteredUser);
        }