/// <summary> /// Intercept /// </summary> /// <param name="invocation"></param> public void Intercept( IInvocation invocation) { var _sqlCommand = (System.Data.SqlClient.SqlCommand) invocation.Arguments[1]; var _formatStyle = (NHibernate.AdoNet.Util.FormatStyle)invocation.Arguments[2]; // Create prepared statement var _preparedStatement = new NHibernateProfiler.Common.Entity.PreparedStatement(); _preparedStatement.Id = Guid.NewGuid(); _preparedStatement.CreationTime = DateTime.Now; _preparedStatement.Sql = _sqlCommand.CommandText; _preparedStatement.Parameters = new List<NHibernateProfiler.Common.Entity.PreparedStatementParameter>(); foreach (System.Data.SqlClient.SqlParameter _parameter in _sqlCommand.Parameters) { _preparedStatement.Parameters.Add( new NHibernateProfiler.Common.Entity.PreparedStatementParameter() { Id = Guid.NewGuid(), Name = _parameter.ToString(), Type = _parameter.SqlDbType.ToString(), Value = _parameter.Value.ToString() }); } // Save prepared statement to db NHibernateProfiler.Common.RepositoryFactory.Get().SavePreparedStatement(_preparedStatement); invocation.Proceed(); }
/// <summary> /// Intercept /// </summary> /// <param name="invocation"></param> public void Intercept( IInvocation invocation) { var _sqlCommand = (System.Data.SqlClient.SqlCommand)invocation.Arguments[1]; var _formatStyle = (NHibernate.AdoNet.Util.FormatStyle)invocation.Arguments[2]; // Create prepared statement var _preparedStatement = new NHibernateProfiler.Common.Entity.PreparedStatement(); _preparedStatement.Id = Guid.NewGuid(); _preparedStatement.CreationTime = DateTime.Now; _preparedStatement.Sql = _sqlCommand.CommandText; _preparedStatement.Parameters = new List <NHibernateProfiler.Common.Entity.PreparedStatementParameter>(); foreach (System.Data.SqlClient.SqlParameter _parameter in _sqlCommand.Parameters) { _preparedStatement.Parameters.Add( new NHibernateProfiler.Common.Entity.PreparedStatementParameter() { Id = Guid.NewGuid(), Name = _parameter.ToString(), Type = _parameter.SqlDbType.ToString(), Value = _parameter.Value.ToString() }); } // Save prepared statement to db NHibernateProfiler.Common.RepositoryFactory.Get().SavePreparedStatement(_preparedStatement); invocation.Proceed(); }
/// <summary> /// Save prepared statement /// </summary> /// <param name="subject">Sql string</param> public void SavePreparedStatement( NHibernateProfiler.Common.Entity.PreparedStatement subject) { using (var _session = this.c_sessionFactory.OpenSession()) { using (var _transaction = _session.BeginTransaction()) { _session.Save(subject); _transaction.Commit(); } } }