Example #1
0
		public SpesaDTO GetSpesaById(int id, UserInfo userinfo)
		{
            var retryCount = 5;
            var success = false;
            var windsorRep = new WindsorConfigRepository();
            SpesaDTO item = null;
            while (retryCount >= 0 && !success)
            {
                try
                {
                    windsorRep.BeginTransaction(userinfo);
                    var repo = new SpesaRepository(userinfo, windsorRep);
                    item = repo.GetById(id);
                    windsorRep.Commit();
                    success = true;
                }
                catch (Exception ex)
                {
                    _log.ErrorFormat("Errore nella lettura della Fattura/Spesa - TENTATIVO:{0} - {1} - id:{2}", ex, (6 - retryCount), Utility.GetMethodDescription(), id);

                    windsorRep.Rollback();
                    if (!isRetryException(ex))
                        throw;

                    // Add delay here if you wish. 
                    System.Threading.Thread.Sleep(1000 * (6 - retryCount));
                    retryCount--;
                    _log.InfoFormat("Lettura delle spese - INIZIO TENTATIVO:{0} - {1} - id:{2} - azienda:{3}", ex, (6 - retryCount), Utility.GetMethodDescription(), id, userinfo.Azienda);
                }
            }

            if (!success)
                windsorRep.Rollback();

            return item;
		}