public static void LogCommandStart(this GlimpseDbCommand command, Guid commandId, TimeSpan timerTimeSpan, bool isAsync) { if (command.MessageBroker != null) { IList <CommandExecutedParamater> parameters = null; if (command.Parameters.Count > 0) { parameters = new List <CommandExecutedParamater>(); foreach (IDbDataParameter parameter in command.Parameters) { var parameterName = parameter.ParameterName; if (!parameterName.StartsWith("@")) { parameterName = "@" + parameterName; } parameters.Add(new CommandExecutedParamater { Name = parameterName, Value = GetParameterValue(parameter), Type = parameter.DbType.ToString(), Size = parameter.Size }); } } command.MessageBroker.Publish( new CommandExecutedMessage(command.InnerConnection.ConnectionId, commandId, command.InnerCommand.CommandText, parameters, command.InnerCommand.Transaction != null, isAsync) .AsTimedMessage(timerTimeSpan)); } }
public static void LogCommandError(this GlimpseDbCommand command, Guid commandId, TimeSpan timer, Exception exception, string type, bool isAsync) { if (command.MessageBroker != null && command.TimerStrategy != null) { command.MessageBroker.Publish( new CommandErrorMessage(command.InnerConnection.ConnectionId, commandId, exception) .AsTimedMessage(command.TimerStrategy.Stop(timer)) .AsTimelineMessage("Command: Error", AdoTimelineCategory.Command, type)); } }
public static void LogCommandEnd(this GlimpseDbCommand command, Guid commandId, TimeSpan timer, int?recordsAffected, string type, bool isAsync) { if (command.MessageBroker != null && command.TimerStrategy != null) { command.MessageBroker.Publish( new CommandDurationAndRowCountMessage(command.InnerConnection.ConnectionId, commandId, recordsAffected) .AsTimedMessage(command.TimerStrategy.Stop(timer)) .AsTimelineMessage("Command: Executed", AdoTimelineCategory.Command, type)); } }
public static void LogCommandStart(this GlimpseDbCommand command, Guid commandId, TimeSpan timerTimeSpan, bool isAsync) { if (command.MessageBroker != null) { IList <CommandExecutedParamater> parameters = Support.ExtractParameters(command, null); command.MessageBroker.Publish( new CommandExecutedMessage(command.InnerConnection.ConnectionId, commandId, command.InnerCommand.CommandText, parameters, command.InnerCommand.Transaction != null, isAsync) .AsTimedMessage(timerTimeSpan)); } }
public static void LogCommandStart(this GlimpseDbCommand command, Guid commandId, TimeSpan timerTimeSpan) { command.LogCommandStart(commandId, timerTimeSpan, false); }
public static TimeSpan LogCommandSeed(this GlimpseDbCommand command) { return(command.TimerStrategy != null?command.TimerStrategy.Start() : TimeSpan.Zero); }
public static void LogCommandError(this GlimpseDbCommand command, Guid commandId, TimeSpan timer, Exception exception, string type) { command.LogCommandError(commandId, timer, exception, type, false); }
public static void LogCommandEnd(this GlimpseDbCommand command, Guid commandId, TimeSpan timer, int?recordsAffected, string type) { command.LogCommandEnd(commandId, timer, recordsAffected, type, false); }
protected override int Update(DataRow[] dataRows, DataTableMapping tableMapping) { GlimpseDbCommand accountCommand = null; if (UpdateCommand != null) { InnerDataAdapter.UpdateCommand = RetrieveBaseType(UpdateCommand); accountCommand = accountCommand ?? UpdateCommand as GlimpseDbCommand; } if (InsertCommand != null) { InnerDataAdapter.InsertCommand = RetrieveBaseType(InsertCommand); accountCommand = accountCommand ?? InsertCommand as GlimpseDbCommand; } if (DeleteCommand != null) { InnerDataAdapter.DeleteCommand = RetrieveBaseType(DeleteCommand); accountCommand = accountCommand ?? DeleteCommand as GlimpseDbCommand; } if (accountCommand != null && accountCommand.MessageBroker != null) { var commandId = Guid.NewGuid(); var timer = accountCommand.LogCommandSeed(); IList <CommandExecutedParamater> parameters = null; IList <CommandExecutedBatchParameter> batchParameters = null; if (accountCommand.Parameters.Count > 0) { if (dataRows.Length > 0) { batchParameters = new List <CommandExecutedBatchParameter>(dataRows.Length); var templates = new Dictionary <string, CommandExecutedParamater>(); var paramDefs = Support.ExtractParameters(accountCommand, templates); var names = new List <string>(templates.Keys); for (int i = 0; i < dataRows.Length; i++) { var paramsOfARow = new List <CommandExecutedParamater>(names.Count); var row = dataRows[i]; var deleted = row.RowState == DataRowState.Deleted; foreach (var name in names) { var val = deleted ? row[name, DataRowVersion.Original] : row[name]; var template = templates[name]; paramsOfARow.Add(new CommandExecutedParamater { Name = template.Name, Value = Support.TranslateValue(val), Size = template.Size, Type = template.Type }); } batchParameters.Add(new CommandExecutedBatchParameter() { Index = i, Value = paramsOfARow }); } } else { parameters = Support.ExtractParameters(accountCommand, null); } } if (batchParameters != null) { accountCommand.MessageBroker.Publish( new CommandExecutedMessage(accountCommand.InnerConnection.ConnectionId, commandId, accountCommand.CommandText, batchParameters, accountCommand.InnerCommand.Transaction != null, false) .AsTimedMessage(timer)); } else { accountCommand.MessageBroker.Publish( new CommandExecutedMessage(accountCommand.InnerConnection.ConnectionId, commandId, accountCommand.CommandText, parameters, accountCommand.InnerCommand.Transaction != null, false) .AsTimedMessage(timer)); } int result = 0; try { result = InnerDataAdapter.Update(dataRows); } catch (Exception exception) { accountCommand.LogCommandError(commandId, timer, exception, "DbDataAdapter:Update"); throw; } accountCommand.LogCommandEnd(commandId, timer, result, "DbDataAdapter:Update"); return(result); } return(InnerDataAdapter.Update(dataRows)); }
/// <summary> /// Gets the one. /// </summary> /// <param name="id">The id.</param> /// <returns></returns> public Category GetOne(int id) { string sqlStatement = "select * from Categories where CategoryID = @CategoryID"; var item = new Category(); using (var conn = this.CreateGlimpseDbConnection()) using (var command = new GlimpseDbCommand(new SqlCommand())) { command.Connection = conn; command.CommandType = CommandType.Text; command.CommandTimeout = 180; command.CommandText = sqlStatement; command.Parameters.Add(new SqlParameter("CategoryID", id)); if (conn.State != ConnectionState.Open) conn.Open(); using (IDataReader reader = command.ExecuteReader()) { if (reader.Read()) { item.CategoryID = int.Parse(reader["CategoryID"].ToString()); item.CategoryName = reader["CategoryName"].ToString(); item.Description = reader["Description"].ToString(); } } } return item; }
/// <summary> /// Gets the categories. /// </summary> /// <returns></returns> public List<Category> GetCategories() { var categories = new List<Category>(); string sqlStatement = "select * from Categories order by CategoryID desc"; using (var conn = this.CreateGlimpseDbConnection()) using (var command = new GlimpseDbCommand(new SqlCommand())) { command.Connection = conn; command.CommandType = CommandType.Text; command.CommandTimeout = 180; command.CommandText = sqlStatement; if (conn.State != ConnectionState.Open) conn.Open(); using (IDataReader reader = command.ExecuteReader()) { while (reader.Read()) { var item = new Category { CategoryID = int.Parse(reader["CategoryID"].ToString()), CategoryName = reader["CategoryName"].ToString(), Description = reader["Description"].ToString() }; categories.Add(item); } } } return categories; }