Ejemplo n.º 1
0
        /// <summary>
        /// Invokes a method in a retriable fashion.
        /// </summary>
        /// <param name="throttledWaitTime">The amount of time to wait if the request is throttled.</param>
        /// <param name="method">The method to invoke.</param>
        public static void InvokeRetriable(int throttledWaitTime, RetriableMethodCall method)
        {
            bool retryRequest = false;

            do
            {
                retryRequest = false;
                try
                {
                    // Perform some action
                    method.Invoke();
                }
                catch (MarketplaceWebServiceOrdersException ordersErr)
                {
                    // If the request is throttled, wait and try again.
                    if (ordersErr.ErrorCode == "RequestThrottled")
                    {
                        Console.WriteLine("Request is throttled; waiting...");
                        retryRequest = true;
                        System.Threading.Thread.Sleep(throttledWaitTime);
                    }
                    else
                    {
                        // On any other error, re-throw the exception to be handled by the caller
                        throw;
                    }
                }
            } while (retryRequest);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Invokes a method in a retriable fashion.
 /// </summary>
 /// <param name="throttledWaitTime">The amount of time to wait if the request is throttled.</param>
 /// <param name="method">The method to invoke.</param>
 public static void InvokeRetriable(RetriableMethodCall method)
 {
     InvokeRetriable(DEFAULT_THROTTLED_WAIT_TIMEOUT, method);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Invokes a method in a retriable fashion.
 /// </summary>
 /// <param name="throttledWaitTime">The amount of time to wait if the request is throttled.</param>
 /// <param name="method">The method to invoke.</param>
 public static void InvokeRetriable(RetriableMethodCall method)
 {
     InvokeRetriable(DEFAULT_THROTTLED_WAIT_TIMEOUT, method);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Invokes a method in a retriable fashion.
        /// </summary>
        /// <param name="throttledWaitTime">The amount of time to wait if the request is throttled.</param>
        /// <param name="method">The method to invoke.</param>
        public static void InvokeRetriable(int throttledWaitTime, RetriableMethodCall method)
        {
            bool retryRequest = false;

            do
            {
                try
                {
                    retryRequest = false;
                    // Perform some action
                    method.Invoke();
                }
                catch (MarketplaceWebServiceOrdersException ordersErr)
                {
                    // If the request is throttled, wait and try again.
                    if (ordersErr.ErrorCode == "RequestThrottled")
                    {
                        NLog.LogManager.GetCurrentClassLogger().Warn("Request is throttled; waiting for {0}", throttledWaitTime / 1000);
                        retryRequest = true;
                        System.Threading.Thread.Sleep(throttledWaitTime);
                    }
                    else
                    {
                        // On any other error, re-throw the exception to be handled by the caller
                        throw;
                    }
                }
            } while (retryRequest);
        }
 /// <summary>
 /// Invokes a method in a retriable fashion.
 /// </summary>
 /// <param name="throttledWaitTime">The amount of time to wait if the request is throttled.</param>
 /// <param name="method">The method to invoke.</param>
 public static void InvokeRetriable(int throttledWaitTime, RetriableMethodCall method)
 {
     bool retryRequest = false;
     do
     {
         retryRequest = false;
         try
         {
             // Perform some action
             method.Invoke();
         }
         catch (MarketplaceWebServiceOrdersException ordersErr)
         {
             // If the request is throttled, wait and try again.
             if (ordersErr.ErrorCode == "RequestThrottled")
             {
                 Console.WriteLine("Request is throttled; waiting...");
                 retryRequest = true;
                 System.Threading.Thread.Sleep(throttledWaitTime);
             }
             else
             {
                 // On any other error, re-throw the exception to be handled by the caller
                 throw;
             }
         }
     } while (retryRequest);
 }