WindowsDevCenter.com
oreilly.comSafari Books Online.Conferences.

advertisement


AddThis Social Bookmark Button

Creating an Application from Scratch, Part 3
Pages: 1, 2, 3, 4, 5

When we are ready to make a call to find information about a particular customer, we must provide information through the CustomerContentLookup object to the CustomerContentLookupRequest object.

customerLookup.AssociateTag = this.associateTag;
customerLookup.SubscriptionId = this.subscriptionID;
customerLookupRequest.CustomerId = reviewerID;
//...
   customerLookupRequest.ReviewPage = pageNumber.ToString();
   customerLookupRequest.ResponseGroup = 
      new string[] { "CustomerFull" };
   customerLookup.Request =
      new CustomerContentLookupRequest[] { customerLookupRequest };
   try
   {
      OneSecond();
      customerLookupResponse =
         amazonService.CustomerContentLookup( customerLookup );
   }

We set the authorization we need (AssociateTag and SubscriptionTag) and the CustomerID we want information about (we get this from our dictionary of reviewers). We then set the ResponseGroup to include the "CustomerFull" response, which the Amazon documentation indicates will return all the user's reviews. We call the amazonService object's CustomerContentLookup method, passing in the CustomerLookup object which itself contains the CustomerLookupRequest object. What we get back is a CustomerLookupResponse object.

Note also that before calling Amazon, I call my own OneSecond method, whose job is to make sure that at least one second has elapsed since the last time I called an Amazon web service.

    
private void OneSecond()
{
   bool bWaiting = true;
   while ( bWaiting )
   {
      this.lblGating.Text = numMillisecondsGated.ToString( "N" ) + 
       " Seconds gated";
      Application.DoEvents();
      TimeSpan elapsed = DateTime.Now - this.lastAmazonCall;
      if ( elapsed.Seconds >= 1 )
      {
         this.lastAmazonCall = DateTime.Now;
         bWaiting = false;
      }
      else
      {
         System.Threading.Thread.Sleep( WaitTime );
         numMillisecondsGated += WaitTime / 1000f;
      }
   }
}

To get the reviews for that customer, I drill down through the CustomerLookupResponse returned by the Amazon web service.

Customers[] customersFound = customerLookupResponse.Customers;
if ( customersFound.Length > 0 )
{
   CustomerReviews custReviews;
   CustomerReviews[] customerReviews;
   Customer[] customerCollection;
   try
   {
      customerCollection = customersFound[0].Customer;
      customerReviews = customerCollection[0].CustomerReviews;
      custReviews = customerReviews[0];
   }
//..
 Review[] reviews = custReviews.Review;
 foreach ( Review review in reviews )
 {
    InsertReview(
       review.ASIN,
       customerLookupRequest.CustomerId,
       review.Rating,
       review.Summary,
       review.Content );

In the elided code (just before setting the Review[] array), I clear out all the reviews for this customer so as to start clean, and I also set the number of pages of reviews returned (there can be up to ten pages, each with up to ten reviews).

Pages: 1, 2, 3, 4, 5

Next Pagearrow