ColonelPanic

TryExecute

Jul 13th, 2011
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. // Usage:
  2. // salesforce.TryExecute<string, QueryResult<Deal>, System.Exception>(
  3. //     "select Id, Name from Deal__c",
  4. //     (svc, qry) => { return svc.Query<Deal>(qry); },
  5. //     (ex) => { System.Diagnostics.Trace.WriteLine(ex.Message); },
  6. //     3);
  7. public static TOut TryExecute<TIn, TOut, TException>(this ISalesforceService service, TIn arg, Func<ISalesforceService, TIn, TOut> executeHandler, Action<TException> errorHandler, int retryCount) where TException : System.Exception
  8. {
  9.     TOut result = default(TOut);
  10.  
  11.     try
  12.     {
  13.         result = executeHandler(service, arg);
  14.     }
  15.     catch (TException e)
  16.     {
  17.         if (retryCount == 0)
  18.         {
  19.             errorHandler(e);
  20.         }
  21.  
  22.         service.TryExecute<TIn, TOut, TException>(arg, executeHandler, errorHandler, --retryCount);
  23.     }
  24.  
  25.     return result;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment