Guest User

Untitled

a guest
Jul 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. public class AzureNHibernateRepository : NHibernateRepository
  2. {
  3. private const int maxRetries = 5;
  4.  
  5. public AzureNHibernateRepository ( INHibernateUnitOfWork uow ) : base ( uow )
  6. {}
  7.  
  8. public void EnsureCleanup ( Action block )
  9. {
  10. ensureCleanup(block);
  11. }
  12.  
  13. protected override void ensureCleanup(Action block)
  14. {
  15. var retries = 0;
  16.  
  17. while ( retries < maxRetries )
  18. {
  19. retries ++;
  20.  
  21. try
  22. {
  23. block.Invoke();
  24. return;
  25. }
  26. catch (DbException dbException )
  27. {
  28. this.unitOfWork.CleanUp ();
  29. if (!dbException.Message.Contains("transport-level error")) throw;
  30. if ( retries == maxRetries ) throw dbException;
  31. }
  32. catch (Exception)
  33. {
  34. this.unitOfWork.CleanUp();
  35. throw;
  36. }
  37. }
  38. }
  39. }
Add Comment
Please, Sign In to add comment