private IList <T> Query <T>(QueryAction <T> executeAction, Action <Exception> notifyAction) { IList <T> result = new List <T>(); if (ExceptionHandled) { try { result = executeAction.Invoke(); } catch (Exception ex) { notifyAction.Invoke(ex); } } else { result = executeAction.Invoke(); notifyAction.Invoke(null); } return(result); }
private void _Query(string queryString, QueryAction queryAction, ResultAction resultAction, Delegate postDelegate, bool query) { MySqlConnection connection = null; MySqlCommand command = null; MySqlDataReader reader = null; try { connection = GetConnection(); command = new MySqlCommand( queryString, connection ); queryAction?.Invoke(command); if (query) { reader = command.ExecuteReader(); while (reader.Read()) { resultAction?.Invoke(reader); } } else { command.ExecuteNonQuery(); } } catch (Exception e) { Console.WriteLine(e); } finally { reader?.Dispose(); command?.Dispose(); connection?.Dispose(); try { postDelegate?.DynamicInvoke(); } catch (Exception e) { Console.WriteLine(e); } } }