public static long getNewId(DbManagerProxy manager) { Exception lastEx = null; int iDeadlockAttemptsCount = BaseSettings.DeadlockAttemptsCount; for (int iAttemptNumber = 0; iAttemptNumber < iDeadlockAttemptsCount; iAttemptNumber++) { try { return(manager.SetSpCommand("dbo.spsysGetNewID", DBNull.Value).ExecuteScalar <long>(ScalarSourceType.OutputParameter)); } catch (Exception e) { lastEx = e; if (!manager.IsTransactionStarted) { if (DbModelException.IsDeadlockException(e)) { Thread.Sleep(BaseSettings.DeadlockDelay); continue; } } throw; } } throw lastEx; }
public int LogIn(string ticketId, bool repeatAfterDeadlock = true) { using (DbManagerProxy manager = DbManagerFactory.Factory.Create(ModelUserContext.Instance)) { try { DataTable dt = manager.SetSpCommand("dbo.spLoginByTicket", manager.Parameter("@strTicket", ticketId), manager.Parameter("@intExpirationInterval", BaseSettings.TicketExpiration), manager.Parameter(ParameterDirection.Output, "@Result", 0) ).ExecuteDataTable(); int res = Convert.ToInt32(manager.Parameter("@Result").Value); if (res == 0) { PerformLogin(dt); } m_LoginTry = 0; return(res); } catch (Exception e) { Dbg.Debug("login by ticket failed, error: {0}", e); Dbg.Trace(); m_LoginTry++; if (DbModelException.IsDeadlockException(e) && m_LoginTry < DedalockRepeatCount) { Debug.WriteLine("user login deadlock found"); return(LogIn(ticketId, m_LoginTry < DedalockRepeatCount - 1)); } var dataException = e as DataException; if (dataException != null) { m_LoginTry = 0; throw DbModelException.Create(null, dataException); } m_LoginTry = 0; throw; } } }