/// <summary> /// This adds an ErrorHandler to the SqlHandlerDict /// The ErrorHandler will be called if the specified sql error happens. /// Note: will throw an exception if an error handler already exists for that sql error number unless /// the checkNotAlreadySet is set to false /// </summary> /// <param name="sqlErrorNumber"></param> /// <param name="errorHandler">Called when given sql error number happens with sql error and entities. /// Should return ValidationError or null if cannot handle the error</param> /// <param name="checkNotAlreadySet"></param> public static void AddToSqlHandlerDict(int sqlErrorNumber, HandleSqlException errorHandler, bool checkNotAlreadySet = true) { if (PrivateSqlHandlerDict.ContainsKey(sqlErrorNumber)) { if (checkNotAlreadySet) { throw new InvalidOperationException( string.Format("You tried to add an exception handler for sql error {0} but a handler called {1} was already there.", sqlErrorNumber, PrivateSqlHandlerDict[sqlErrorNumber].GetType().GetTypeInfo().Name)); } PrivateSqlHandlerDict[sqlErrorNumber] = errorHandler; } else { PrivateSqlHandlerDict.Add(sqlErrorNumber, errorHandler); } }
/// <summary> /// This adds an ErrorHandler to the SqlHandlerDict /// The ErrorHandler will be called if the specified sql error happens. /// Note: will throw an exception if an error handler already exists for that sql error number unless /// the checkNotAlreadySet is set to false /// </summary> /// <param name="sqlErrorNumber"></param> /// <param name="errorHandler">Called when given sql error number happens with sql error and entities. /// Should return ValidationError or null if cannot handle the error</param> /// <param name="checkNotAlreadySet"></param> public static void AddToSqlHandlerDict(int sqlErrorNumber, HandleSqlException errorHandler, bool checkNotAlreadySet = true) { if (PrivateSqlHandlerDict.ContainsKey(sqlErrorNumber)) { if (checkNotAlreadySet) throw new InvalidOperationException( string.Format("You tried to add an exception handler for sql error {0} but a handler called {1} was already there.", sqlErrorNumber, PrivateSqlHandlerDict[sqlErrorNumber].Method.Name)); PrivateSqlHandlerDict[sqlErrorNumber] = errorHandler; } else PrivateSqlHandlerDict.Add(sqlErrorNumber, errorHandler); }