/// <summary> /// Creates a new Alexa request state instance. /// </summary> /// <param name="callback">The callback method.</param> /// <param name="country">The country.</param> /// <param name="pages">The number of pages to return.</param> /// <param name="ranking">The Alexa ranking list.</param> /// <param name="state">The user state.</param> public AlexaRankingRequestState(AsyncCallback callback, AlexaCountry country, int pages, AlexaRanking ranking, object state) : base(callback, state) { // Set the country. this.Country = country; // Set the number of pages. this.Pages = pages; // Set the ranking list. this.ranking = ranking != null ? ranking : new AlexaRanking(); // Clear the ranking list. this.ranking.Clear(); }
/// <summary> /// Begins an asynchronous request for the country-specific Alexa ranking. /// </summary> /// <param name="callback">The callback method.</param> /// <param name="country">The country.</param> /// <param name="pages">The number of pages to return.</param> /// <param name="ranking">The ranking list.</param> /// <param name="userState">The user state.</param> public IAsyncResult BeginGetCountryRanking(AsyncCallback callback, AlexaCountry country, int pages, AlexaRanking ranking = null, object userState = null) { // Create the request state. AlexaRankingRequestState asyncState = new AlexaRankingRequestState(callback, country, pages, ranking, userState); // Call the internal request method. this.BeginGetRankingInternal(asyncState, this.GetUriCountryRanking); // Return the request state. return asyncState; }
/// <summary> /// Computes the request URI for the Alexa global ranking. /// </summary> /// <param name="asyncState">The request state</param> /// <param name="uri">The request URI.</param> /// <param name="country">The request country.</param> private void GetUriGlobalRanking(AlexaRankingRequestState asyncState, out Uri uri, out AlexaCountry country) { // Set the URI. uri = new Uri(AlexaRequest.urlRankingGlobal.FormatWith(asyncState.Page++)); // Set the country. country = AlexaCountry.Global; }
/// <summary> /// Computes the request URI for the Alexa country ranking. /// </summary> /// <param name="asyncState">The request state</param> /// <param name="uri">The request URI.</param> /// <param name="country">The request country.</param> private void GetUriCountryRanking(AlexaRankingRequestState asyncState, out Uri uri, out AlexaCountry country) { // Set the URI. uri = new Uri(AlexaRequest.urlRankingCountry.FormatWith(asyncState.Page++, asyncState.Country.Code)); // Set the country. country = asyncState.Country; }