/// <summary> /// Esegue l'aggiornamento e l'insert nella tabella wr_materiali /// </summary> /// <param name="CollezioneControlli"></param> /// <param name="Operazione"></param> /// <returns></returns> public int ExecuteManodopera(S_ControlsCollection CollezioneControlli, ExecuteType Operazione) { int i_MaxParametri = CollezioneControlli.Count + 1; S_Controls.Collections.S_Object s_Operazione = new S_Object(); s_Operazione.ParameterName = "p_operazione"; s_Operazione.DbType = CustomDBType.VarChar; s_Operazione.Direction = ParameterDirection.Input; s_Operazione.Index = i_MaxParametri++; s_Operazione.Value = Operazione.ToString(); S_Controls.Collections.S_Object s_IdOut = new S_Object(); s_IdOut.ParameterName = "p_IdOut"; s_IdOut.DbType = CustomDBType.Integer; s_IdOut.Direction = ParameterDirection.Output; s_IdOut.Index = i_MaxParametri++; CollezioneControlli.Add(s_Operazione); CollezioneControlli.Add(s_IdOut); ApplicationDataLayer.OracleDataLayer _OraDl = new OracleDataLayer(s_ConnStr); int i_Result = _OraDl.GetRowsAffected(CollezioneControlli, "Pack_CostiOperativiGestione.ExecuteAddetti"); return(i_Result); }
private void button_GetAxisIoCoor_Click(object sender, EventArgs e) { try { _executeType = ExecuteType.GetAxisCoordinate; EnableControl(false); string json = "{\"GetAxis\":\"Coor\"}"; byte[] buffer = Encoding.ASCII.GetBytes(json); uint bufferSize = (uint)buffer.Length; int ret = CoreInterface.SetEpsonEP0Cmd(Cmd, buffer, ref bufferSize, (ushort)bufferSize, 0); if (ret == 0) { MessageBox.Show(ResString.GetResString("SendCmdFailed")); EnableControl(true); } //GetAxisCoorRoot root = new GetAxisCoorRoot() //{ // GetAxisCoor = new List<int>() // { // 1000,200,300,400,500,600 // } //}; //json = JsonConvert.SerializeObject(root); //CallBack(Encoding.ASCII.GetBytes(json)); } catch (Exception exception) { MessageBox.Show(exception.Message); EnableControl(true); } }
public ExpressionExecutive(ExpressionValue assignVar, ExecuteType func, ExpressionValue left, ExpressionValue right) { if (assignVar == null || left == null || right == null) { throw new Exception(); } if (assignVar.TypeOfReference == ExpressionValue.RefType.NotReferred || assignVar.TypeOfReference == ExpressionValue.RefType.Null) { throw new Exception(); } this.AssignResultVar = assignVar; List <ExecuteType> etchck = new List <ExecuteType>() { ExecuteType.AssignAdd, ExecuteType.AssignDiv, ExecuteType.AssignModulo, ExecuteType.AssignMul, ExecuteType.AssignSub }; FuncType = func; if (!etchck.Contains(func)) { throw new Exception(); } ExLeftPart = left; ExRightPart = right; }
//only for one button order //note: the only difference id not to collect basic info public void DirectMakeOrder(OrderDirection direction, ExecuteType iexecuteType) { OrderDirection = direction; ExecutionType = iexecuteType; PBMsgTrader.PBMsgOrderInsert pb = CreateOrder(mFutureFlag); View.SendOrder(pb); }
/// <summary> /// 获取需要执行的命令类型 /// </summary> /// <param name="m"></param> /// <param name="executeType"></param> private void GetExecuteType(MethodInfo m, ref ExecuteType executeType) { var rType = m.ReturnType; if (executeType == ExecuteType.Default) { //执行命令类型的默认设置 if (rType != null) { if (rType == typeof(int)) { executeType = ExecuteType.ExecuteNoQuery; } else if (rType.IsValueType || rType == typeof(string) || (rType.IsArray && rType.GetElementType() != null && rType.GetElementType().IsValueType)) { executeType = ExecuteType.ExecuteObject; } else { executeType = ExecuteType.ExecuteDateTable; } } else { executeType = ExecuteType.ExecuteNoQuery; } } }
/// <summary> /// profile with results. /// </summary> /// <param name="type">The type of execution.</param> /// <param name="func">a function to execute against against the profile result</param> /// <typeparam name="TResult">the type of result to return.</typeparam> /// <returns>The <see cref="TResult"/>return the profiled result.</returns> private TResult ProfileWith <TResult>(ExecuteType type, Func <TResult> func) { if (_profiler == null || !_profiler.IsActive) { return(func()); } TResult result; _profiler.ExecuteStart(this, type); try { result = func(); } catch (Exception e) { _profiler.OnError(this, type, e); throw; } finally { _profiler.ExecuteFinish(this, type, null); } return(result); }
/// <summary> /// Tracks when 'command' is started. /// </summary> public void ExecuteStartImpl(DbCommand command, ExecuteType type) { var id = Tuple.Create((object)command, type); var sqlTiming = new SqlTiming(command, type, Profiler); _inProgress[id] = sqlTiming; }
/// <summary> /// Creates a platform task. /// </summary> /// <param name="index">The index of user</param> /// <param name="client">The RUYI Net client</param> /// <param name="onExecute">The method to call when the task executes.</param> /// <param name="callback">The callback to call when the task completes.</param> public RuyiNetPlatformTask(int index, RuyiNetClient client, ExecuteType onExecute, CallbackType callback) : base(onExecute, callback) { mClient = client; mIndex = index; }
public static ExecuteType CheckExecuteType(string query) { ExecuteType executeType = ExecuteType.NONE; Func <string, bool> IsMatch = pattern => { if (!Regex.IsMatch(query, pattern, RegexOptions.IgnoreCase)) { return(false); } return(true); }; if (IsMatch(@"(?=.*insert)(?=.*into)(?=.*values)")) { executeType = ExecuteType.INSERT; } else if (IsMatch(@"(?=.*update)(?=.*set)")) { executeType = ExecuteType.UPDATE; } else if (IsMatch(@"(?=.*delete)(?=.*from)")) { executeType = ExecuteType.DELETE; } return(executeType); }
public int?Execute(string query, object sqlParam = null, CommandType cmdType = CommandType.Text) { return(_SqlTryCatch(con => { using (DbCommand cmd = con.CreateCommand()) { cmd.CommandType = cmdType; cmd.CommandText = query; if (sqlParam != null) { cmd.Parameters.AddRange(_SetParams(sqlParam, cmd)); } cmd.ExecuteNonQueryAsync(); ExecuteType executeType = MiniOrmHelpers.CheckExecuteType(query); //int lastInsertId = Convert.ToInt32(cmd.LastInsertedId); int lastInsertId = 0; OnExecuted(true, lastInsertId, executeType); return lastInsertId; } }, error => { ExecuteType executeType = MiniOrmHelpers.CheckExecuteType(query); OnExecuted(false, 0, executeType); })); }
private void button_IOOutput_Run_Click(object sender, EventArgs e) { try { _currentMoveAxis = (int)numericUpDown_IOOutput_Axis.Value; _executeType = ExecuteType.Move; EnableControl(false); MoveLenAxis moveLenAxis = new MoveLenAxis() { Axis = (int)numericUpDown_IOOutput_Axis.Value, Len = (int)numericUpDown_IOOutput_Len.Value, Speed = (int)numericUpDown_IOOutput_Speed.Value, }; IoOutput root = new IoOutput() { Io = moveLenAxis, }; string json = JsonConvert.SerializeObject(root); byte[] buffer = Encoding.ASCII.GetBytes(json); uint bufferSize = (uint)buffer.Length; int ret = CoreInterface.SetEpsonEP0Cmd(Cmd, buffer, ref bufferSize, (ushort)bufferSize, 0); if (ret == 0) { MessageBox.Show(ResString.GetResString("SendCmdFailed")); EnableControl(true); } } catch (Exception exception) { MessageBox.Show(exception.Message); EnableControl(true); } }
private Object ExecuteScalar(string spNameOrSqlString, ExecuteType type, params DbParam[] parameters) { Object obj = null; try { this.CreateConnection(); using (DbCommand command = type == ExecuteType.StoredProc ? _dataBase.GetStoredProcCommand(spNameOrSqlString) : _dataBase.GetSqlStringCommand(spNameOrSqlString)) { command.Connection = this._connection; command.CommandTimeout = 180;//默认180秒 this.AddParameterToDataBase(_dataBase, command, parameters); obj = this.ExecuteScalar(_dataBase, command); this.SetValueToParameters(command, parameters); } } catch (Exception ex) { throw new DataAccessLayerException(ex.Message, ex.InnerException); } finally { ReleaseConnection(); } return(obj); }
public T ExecuteScalarFunction <T>(string query, SQLParameters parameter, ExecuteType type) { using (_con = new SqlConnection(ConnectionString)) { _cmd = new SqlCommand { Connection = _con }; _cmd.Parameters.Clear(); _cmd.CommandType = type == ExecuteType.StoredProcedure ? CommandType.StoredProcedure : CommandType.Text; _cmd.CommandText = query; _cmd.CommandTimeout = ConnectDbTimeOut; if (parameter != null) { _cmd.Parameters.AddRange(parameter.ToArray()); } SqlParameter returnValue = _cmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Text); returnValue.Direction = ParameterDirection.ReturnValue; _con.Open(); _cmd.ExecuteNonQuery(); if (_con.State == ConnectionState.Open) { _con.Close(); } return((T)returnValue.Value); } }
public ExecuteResult CheckField(ExecuteType executeType, IUnitOfWork <MSDbContext> unitOfWork) { ExecuteResult result = new ExecuteResult(); //var repo = unitOfWork.GetRepository<Role>(); ////如果不是新增角色,操作之前都要先检查角色是否存在 //if (executeType != ExecuteType.Create && !repo.Exists(a => a.Id == Id)) //{ // return result.SetFailMessage("角色不存在"); //} ////针对不同的操作,检查逻辑不同 //switch (executeType) //{ // case ExecuteType.Delete: // case ExecuteType.Update: // //如果存在Id不同,角色名相同的实体,则返回报错 // if (repo.Exists(a => a.Name == Name && a.Id != Id)) // { // return result.SetFailMessage($"已存在相同的角色名称:{Name}"); // } // break; // case ExecuteType.Create: // default: // //如果存在相同的角色名,则返回报错 // if (repo.Exists(a => a.Name == Name)) // { // return result.SetFailMessage($"已存在相同的角色名称:{Name}"); // } // break; //} return(result);//没有错误,默认返回成功 }
public void ExecuteNonQuery(string query, SQLParameters parameter, ExecuteType type) { using (var conn = new SqlConnection(_connectionString)) { try { conn.Open(); var cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandType = type == ExecuteType.StoredProcedure ? CommandType.StoredProcedure : CommandType.Text; cmd.CommandText = query; cmd.CommandTimeout = _connectDbTimeOut; if (parameter != null) { cmd.Parameters.AddRange(parameter.ToArray()); } cmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { if (conn.State != ConnectionState.Closed) { conn.Close(); } } } }
public override IMessage Invoke(IMessage msg) { IMethodCallMessage methodMessage = new MethodCallMessageWrapper((IMethodCallMessage)msg); ExecuteType executeType = GetExecuteType(methodMessage); if (executeType != ExecuteType.None) { profiler.ExecuteStart(instance, executeType); } object returnValue = methodMessage.MethodBase.Invoke(instance, methodMessage.Args); if (executeType == ExecuteType.Reader) { returnValue = new ProfiledDbDataReader((DbDataReader)returnValue, instance.Connection, profiler); } IMessage returnMessage = new ReturnMessage(returnValue, methodMessage.Args, methodMessage.ArgCount, methodMessage.LogicalCallContext, methodMessage); if (executeType == ExecuteType.Reader) { profiler.ExecuteFinish(instance, executeType, (DbDataReader)returnValue); } else if (executeType != ExecuteType.None) { profiler.ExecuteFinish(instance, executeType, null); } return(returnMessage); }
public static string GetExecuteType(ExecuteType executeType) { string type = string.Empty; switch (executeType) { case ExecuteType.OpenPosition: { type = "开仓"; } break; case ExecuteType.ClosePosition: { type = "平仓"; } break; case ExecuteType.AdjustPosition: { type = "调仓"; } break; default: break; } return(type); }
private void LogCommandAsError(Exception exception, ExecuteType type) { var formatter = new SqlServerFormatter(); SqlTiming timing = new SqlTiming(this, type, null); exception.Data["SQL"] = formatter.FormatSql(timing); }
private void OnComboIndexChanged(ListViewItem item, ExecuteType comboValue) { if (ComboIndexChanged != null) { ComboIndexChanged(item, comboValue); } }
public void ExecuteNonQuery(string query, SQLParameters parameter, ExecuteType type) { using (_con = new SqlConnection(ConnectionString)) { _con.Open(); _cmd = new SqlCommand { Connection = _con, CommandType = type == ExecuteType.StoredProcedure ? CommandType.StoredProcedure : CommandType.Text, CommandText = query, CommandTimeout = ConnectDbTimeOut }; if (parameter != null) { _cmd.Parameters.AddRange(parameter.ToArray()); } _cmd.ExecuteNonQuery(); _con.Dispose(); if (_con.State == ConnectionState.Open) { _con.Close(); } } }
/// <summary> /// 执行数据源的查询与交互。 /// </summary> /// <typeparam name="TDbResult">返回结果的数据类型。</typeparam> /// <typeparam name="TDbValue">返回值的数据类型。</typeparam> /// <param name="type">执行的类型。</param> /// <param name="callback">执行时的回调方法。</param> /// <returns>返回一个执行结果。</returns> protected virtual TDbResult Execute <TDbResult, TDbValue>(ExecuteType type, Func <DbCommand, TDbValue> callback) where TDbResult : DbResult <TDbValue>, new() { var dbCommand = this.CreateDbCommand(); this.OnExecuting(type); TDbResult result = new TDbResult(); try { this.Open(); var value = callback(dbCommand); result.Initialization(this._Engine, dbCommand, value, null); } catch (Exception ex) { result.Initialization(this._Engine, dbCommand, default(TDbValue), this._Command.Aborted ? ExecuteAbortException.Instance : ex); } if (this._Engine == this._owner) { this.Close(); } this.OnExecuted(type, result); return(result); }
private void ExecuteNonQuery(string spNameOrSqlString, ExecuteType type, params DbParam[] parameters) { try { this.CreateConnection(); using (DbCommand command = type == ExecuteType.StoredProc ? _dataBase.GetStoredProcCommand(spNameOrSqlString) : _dataBase.GetSqlStringCommand(spNameOrSqlString)) { command.Connection = _connection; command.CommandTimeout = 300;//默认30秒 this.AddParameterToDataBase(_dataBase, command, parameters); this.ExecuteNonQuery(_dataBase, command); this.SetValueToParameters(command, parameters); } } catch (Exception ex) { throw new DataAccessLayerException(ex.Message, ex.InnerException); } finally { this.ReleaseConnection(); } }
public DataTable ExecuteToTable(string query, SQLParameters parameter, ExecuteType type) { using (_con = new SqlConnection(ConnectionString)) { _con.Open(); _cmd = new SqlCommand { Connection = _con }; _cmd.Parameters.Clear(); _cmd.CommandType = type == ExecuteType.StoredProcedure ? CommandType.StoredProcedure : CommandType.Text; _cmd.CommandText = query; _cmd.CommandTimeout = ConnectDbTimeOut; if (parameter != null) { _cmd.Parameters.AddRange(parameter.ToArray()); } _adapter = new SqlDataAdapter(_cmd); DataTable tbl = new DataTable(); _adapter.Fill(tbl); _adapter.Dispose(); if (_con.State == ConnectionState.Open) { _con.Close(); } return(tbl); } }
/// <summary> /// 执行数据源的查询与交互。 /// </summary> /// <typeparam name="TValue">返回结果的数据类型。</typeparam> /// <param name="type">执行的命令类型。</param> /// <param name="callback">执行时的回调方法。</param> /// <returns>执行结果。</returns> protected virtual TValue Execute <TValue>(ExecuteType type, Func <DbCommand, TValue> callback) { var dbCommand = this.CreateDbCommand(); TValue value = default(TValue); this.OnExecuting(type, dbCommand); this.Open(); try { value = callback(dbCommand); } catch (Exception ex) { GA.OnGlobalError(this.Engine, ex); throw; } finally { if (this._closeAfterFinally) { this.Close(); } } this.OnExecuted(type, dbCommand, value); return(value); }
/// <summary> /// 创建一个空的执行对象。 /// </summary> /// <returns></returns> public static IExecuteObject CreateEmptyExecuteObject(ExecuteType type, string connKey = null) { ServerType serverType = GetServerType(connKey); //检查缓存 if (_executeList.ContainsKey(serverType)) { var empty = _executeList[serverType].CloneEmpty(); empty.ExecuteType = type; return(empty); } //反射实例化对象 string className = GetInstanceClassName(serverType) + "ExecuteObject"; Assembly ass = Assembly.GetExecutingAssembly(); object obj = ass.CreateInstance(className); IExecuteObject instance = obj as IExecuteObject; if (instance == null) { throw new DataObjectException("未能实例化数据库 ExecuteObject 对象!"); } instance.ExecuteType = type; if (!_executeList.ContainsKey(serverType)) { _executeList[serverType] = instance; } return(instance); }
void IDbProfiler.ExecuteFinish(DbCommand profiledDbCommand, ExecuteType executeType, System.Data.Common.DbDataReader reader) { if (reader == null) { watch.Stop(); } ExecuteFinishCount++; }
internal ExecutedEventArgs GetEventArgs(ExecuteType type, System.Data.Common.DbCommand dbCommand, object result) { var e = this._EventArgs ?? (this._EventArgs = new ExecutedEventArgs(this, dbCommand)); e.ExecuteType = type; e.Result = result; return(e); }
internal ExecutedEventArgs GetEventArgs(ExecuteType type, IDbResult result) { var e = this._EventArgs ?? (this._EventArgs = new ExecutedEventArgs(this)); e.ExecuteType = type; e.Result = result; return(e); }
/// <summary> /// Tracks when 'command' is started. /// </summary> public Guid ExecuteStartImpl(string collectionName, object query, ExecuteType type) { var id = Guid.NewGuid(); var mongoTiming = new MongoTiming(collectionName, query.ToString(), type, Profiler); _inProgress[id] = mongoTiming; return id; }
public ReflectInfo(PropertyInfo propertyInfo, Type type, ExecuteType executeType, string name, Attribute[] attributes) { PropertyInfo = propertyInfo; Type = type; ExecuteType = executeType; Name = name; Attributes = attributes; }
/// <summary> /// execute stored procedure or text /// </summary> /// <param name="text"></param> /// <param name="executeType"></param> /// <param name="parameters"></param> /// <param name="commandType"></param> /// <returns></returns> private async Task <object> Execute(string commandText, ExecuteType executeType, IList <SqlDbParameter> parameters, CommandType commandType) { object returnObject = null; if (_connection != null) { if (_connection.State == ConnectionState.Open) { _command = _connection.CreateCommand(); _command.CommandText = commandText; _command.CommandType = commandType; _command.CommandTimeout = _commandTimeout; if (_transaction != null) { _command.Transaction = _transaction; } // pass parameters to command if (parameters != null) { _command.Parameters.Clear(); foreach (SqlDbParameter dbParameter in parameters) { DbParameter parameter = _command.CreateParameter(); parameter.ParameterName = "@" + dbParameter.Name; parameter.Direction = dbParameter.Direction; parameter.Value = dbParameter.Value; _command.Parameters.Add(parameter); } } switch (executeType) { case ExecuteType.ExecuteReader: returnObject = await _command.ExecuteReaderAsync(); break; case ExecuteType.ExecuteNonQuery: returnObject = await _command.ExecuteNonQueryAsync(); break; case ExecuteType.ExecuteScalar: returnObject = await _command.ExecuteScalarAsync(); break; default: break; } } } return(returnObject); }
public Guid ExecuteStartImpl(string collectionName, object query, IMongoUpdate update, ExecuteType type) { var id = Guid.NewGuid(); var q = String.Format("{0}\n{1}", query, update); var mongoTiming = new MongoTiming(collectionName, q, type, Profiler); _inProgress[id] = mongoTiming; return id; }
public void SetItem(MyGesture gesture) { m_active = gesture.Active; m_caption = gesture.Caption; m_description = gesture.Description; m_executionType = gesture.ExecutionType; m_itemPos = gesture.ItemPos; SetMainListItem(); }
public static int PriorityToIndex(ExecuteType priority) { switch (priority) { case ExecuteType.Implicit: return 0; case ExecuteType.ImplicitIfUnique: return 1; case ExecuteType.Explicit: return 2; default: return 0; } }
public static string ExecuteCommand( string ConnectionTypeName, string ConnectionString, string ConnectionStringName, string SqlCommand, ExecuteType ExecuteType ) { string connstr = GetConnectionString( ConnectionString, ConnectionStringName ); IDbConnection conn = CreateConnection( ConnectionTypeName ); conn.ConnectionString = connstr; string result = RunCommand( conn, SqlCommand, ExecuteType ); return result; }
public static ExecuteCom GetCom(ExecuteType _type) { switch (_type) { case ExecuteType.Damage: case ExecuteType.Cure: case ExecuteType.Buffer: break; } return null; }
/// <summary> /// Creates a new SqlTiming to profile 'command'. /// </summary> public ProfilerItem(DbCommand command, ExecuteType executeType) { CommandText = AddSpacesToParameters(command.CommandText); Parameters = GetCommandParameters(command); ExecuteType = executeType; if (Profiler.ConfigurationSettings.StackTraceBreadCrumbConfiguration.IsEnabled) StackTraceBreadCrumb = GetStackTraceBreadCrumbs(); StartDateTime = DateTime.Now; _totalStopWatch = Stopwatch.StartNew(); }
/// <summary> /// Finishes profiling for 'command', recording durations. /// </summary> public void ExecuteFinishImpl(DbCommand command, ExecuteType type, DbDataReader reader = null) { var id = Tuple.Create((object)command, type); var current = _inProgress[id]; current.ExecutionComplete(isReader: reader != null); SqlTiming ignore; _inProgress.TryRemove(id, out ignore); if (reader != null) { _inProgressReaders[reader] = current; } }
public static void AddMongoTiming(string commandString, long durationMilliseconds, ExecuteType executeType) { if (MiniProfiler.Current == null || MiniProfiler.Current.Head == null) return; MiniProfiler.Current.Head.AddCustomTiming(MongoMiniProfiler.CategoryName, new CustomTiming(MiniProfiler.Current, commandString) { DurationMilliseconds = durationMilliseconds, FirstFetchDurationMilliseconds = durationMilliseconds, ExecuteType = executeType.ToString().ToLower() }); }
/// <summary> /// Creates a new SqlTiming to profile 'command'. /// </summary> public SqlTiming(DbCommand command, ExecuteType type, MiniProfiler profiler) { Id = Guid.NewGuid(); RawCommandString = CommandString = AddSpacesToParameters(command.CommandText); Parameters = GetCommandParameters(command); ExecuteType = type; if (!MiniProfiler.Settings.ExcludeStackTraceSnippetFromSqlTimings) StackTraceSnippet = Helpers.StackTraceSnippet.Get(); _profiler = profiler; _profiler.AddSqlTiming(this); _startTicks = _profiler.ElapsedTicks; StartMilliseconds = MiniProfiler.GetRoundedMilliseconds(_startTicks); }
/// <summary> /// Creates a new SqlTiming to profile 'command'. /// </summary> public MongoTiming(string collectionName, string command, ExecuteType type, MiniProfiler profiler) { Id = Guid.NewGuid(); CollectionName = collectionName; CommandString = command; ExecuteType = type; if (!MiniProfiler.Settings.ExcludeStackTraceSnippetFromSqlTimings) StackTraceSnippet = Helpers.StackTraceSnippet.Get(); _profiler = profiler; if (_profiler != null) { _profiler.AddMongoTiming(this); _startTicks = _profiler.ElapsedTicks; StartMilliseconds = _profiler.GetRoundedMilliseconds(_startTicks); } }
public SqlTiming(string commandText, ExecuteType type, MiniProfiler profiler) { Id = Guid.NewGuid(); CommandString = AddSpacesToParameters(commandText); Parameters = new List<SqlTimingParameter>(); ExecuteType = type; if (!MiniProfiler.Settings.ExcludeStackTraceSnippetFromSqlTimings) StackTraceSnippet = Helpers.StackTraceSnippet.Get(); _profiler = profiler; if (_profiler != null) { _profiler.AddSqlTiming(this); _startTicks = _profiler.ElapsedTicks; StartMilliseconds = _profiler.GetRoundedMilliseconds(_startTicks); } }
public object Execute( TransactionChoice connType , CommandType commandType , string procedure , ExecuteType executeType , IList<SqlParameter> parameters , out ExecuteOutcome executeOutcome, out string executeOutcomeMessage) { object result = null; SqlCommand cmd = NewSqlCommand(connType, commandType, procedure, parameters); try { result = CommandExecute(executeType, cmd); executeOutcome = ExecuteOutcome.Success; executeOutcomeMessage = ""; } catch (Exception ex) { if (ex.GetBaseException().Message.Contains("timeout") || ex.GetBaseException().Message.Contains("deadlock")) { //return message that it timed out executeOutcome = ExecuteOutcome.Timeout; executeOutcomeMessage = "Server timed out or thread deadlock victim. " + ex.Message; } else { executeOutcome = ExecuteOutcome.Failure; throw ex; } } return result; }
void IDbProfiler.OnError(DbCommand profiledDbCommand, ExecuteType executeType, Exception exception) { // TODO: implement errors aggregation and presentation }
/// <summary> /// Returns the number of sql statements of <paramref name="type"/> that were executed in this <see cref="Timing"/>. /// </summary> internal int GetExecutedCount(ExecuteType type) { return HasSqlTimings ? SqlTimings.Count(s => s.ExecuteType == type) : 0; }
// IDbProfiler methods void IDbProfiler.ExecuteStart(DbCommand profiledDbCommand, ExecuteType executeType) { SqlProfiler.ExecuteStart(profiledDbCommand, executeType); }
void IDbProfiler.ExecuteFinish(DbCommand profiledDbCommand, ExecuteType executeType, DbDataReader reader) { if (reader != null) { SqlProfiler.ExecuteFinish(profiledDbCommand, executeType, reader); } else { SqlProfiler.ExecuteFinish(profiledDbCommand, executeType); } }
/// <summary> /// Returns the number of sql statements of <paramref name="type"/> that were executed in all <see cref="Timing"/>s. /// </summary> private int GetExecutedCount(ExecuteType type) { return HasSqlTimings ? GetTimingHierarchy().Sum(t => t.GetExecutedCount(type)) : 0; }
/// <summary> /// Tracks when 'command' is started. /// </summary> public static void ExecuteStart(this SqlProfiler sqlProfiler, DbCommand command, ExecuteType type) { if (sqlProfiler == null) return; sqlProfiler.ExecuteStartImpl(command, type); }
private int ExecutedCount(ExecuteType type) { return HasSqlTimings ? SqlTimings.Count(s => s.ExecuteType == type) : 0; }
void IDbProfiler.ExecuteFinish(System.Data.Common.DbCommand profiledDbCommand, ExecuteType executeType, System.Data.Common.DbDataReader reader) { SqlProfiler.ExecuteFinish(profiledDbCommand, executeType, reader); }
/// <summary> /// Finishes profiling for 'command', recording durations. /// </summary> public static void ExecuteFinish(this SqlProfiler sqlProfiler, DbCommand command, ExecuteType type, DbDataReader reader = null) { if (sqlProfiler == null) return; sqlProfiler.ExecuteFinishImpl(command, type, reader); }
void IDbProfiler.ExecuteStart(System.Data.Common.DbCommand profiledDbCommand, ExecuteType executeType) { SqlProfiler.ExecuteStart(profiledDbCommand, executeType); }
internal ExecutedEventArgs GetEventArgs(ExecuteType type, System.Data.Common.DbCommand dbCommand, object result) { var e = this._EventArgs ?? (this._EventArgs = new ExecutedEventArgs(this, dbCommand)); e.ExecuteType = type; e.Result = result; return e; }
private static void TestMARSSessionPooling(string caseName, string connectionString, CommandType commandType, ExecuteType executeType, ReaderTestType readerTestType, GCType gcType) { SqlCommand[] cmd = new SqlCommand[CONCURRENT_COMMANDS]; SqlDataReader[] gch = new SqlDataReader[CONCURRENT_COMMANDS]; using (SqlConnection con = new SqlConnection(connectionString)) { con.Open(); for (int i = 0; i < CONCURRENT_COMMANDS; i++) { // Prepare all commands cmd[i] = con.CreateCommand(); switch (commandType) { case CommandType.Text: cmd[i].CommandText = _COMMAND_SQL; cmd[i].CommandTimeout = 120; break; case CommandType.StoredProcedure: cmd[i].CommandText = _COMMAND_RPC; cmd[i].CommandTimeout = 120; cmd[i].CommandType = CommandType.StoredProcedure; break; } } for (int i = 0; i < CONCURRENT_COMMANDS; i++) { switch (executeType) { case ExecuteType.ExecuteScalar: cmd[i].ExecuteScalar(); break; case ExecuteType.ExecuteNonQuery: cmd[i].ExecuteNonQuery(); break; case ExecuteType.ExecuteReader: if (readerTestType != ReaderTestType.ReaderGC) gch[i] = cmd[i].ExecuteReader(); switch (readerTestType) { case ReaderTestType.ReaderClose: { gch[i].Dispose(); break; } case ReaderTestType.ReaderDispose: gch[i].Dispose(); break; case ReaderTestType.ReaderGC: gch[i] = null; WeakReference weak = OpenReaderThenNullify(cmd[i]); GC.Collect(); if (gcType == GCType.Wait) { GC.WaitForPendingFinalizers(); Assert.False(weak.IsAlive, "Error - target still alive!"); } break; case ReaderTestType.ConnectionClose: GC.SuppressFinalize(gch[i]); con.Close(); con.Open(); break; case ReaderTestType.NoCloses: GC.SuppressFinalize(gch[i]); break; } break; } if (readerTestType != ReaderTestType.NoCloses) { con.Close(); con.Open(); // Close and open, to re-assure collection! } SqlCommand verificationCmd = con.CreateCommand(); verificationCmd.CommandText = COMMAND_STATUS; using (SqlDataReader rdr = verificationCmd.ExecuteReader()) { rdr.Read(); int connections = (int)rdr.GetValue(0); rdr.NextResult(); rdr.Read(); int requests = (int)rdr.GetValue(0); switch (executeType) { case ExecuteType.ExecuteScalar: case ExecuteType.ExecuteNonQuery: // 1 for connection, 1 for command Assert.True(connections == 2, "Failure - incorrect number of connections for ExecuteScalar! #connections: " + connections); // only 1 executing Assert.True(requests == 1, "Failure - incorrect number of requests for ExecuteScalar! #requests: " + requests); break; case ExecuteType.ExecuteReader: switch (readerTestType) { case ReaderTestType.ReaderClose: case ReaderTestType.ReaderDispose: case ReaderTestType.ConnectionClose: // 1 for connection, 1 for command Assert.True(connections == 2, "Failure - Incorrect number of connections for ReaderClose / ReaderDispose / ConnectionClose! #connections: " + connections); // only 1 executing Assert.True(requests == 1, "Failure - incorrect number of requests for ReaderClose/ReaderDispose/ConnectionClose! #requests: " + requests); break; case ReaderTestType.ReaderGC: switch (gcType) { case GCType.Wait: // 1 for connection, 1 for open reader Assert.True(connections == 2, "Failure - incorrect number of connections for ReaderGCWait! #connections: " + connections); // only 1 executing Assert.True(requests == 1, "Failure - incorrect number of requests for ReaderGCWait! #requests: " + requests); break; case GCType.NoWait: // 1 for connection, 1 for open reader Assert.True(connections == 2, "Failure - incorrect number of connections for ReaderGCNoWait! #connections: " + connections); // only 1 executing Assert.True(requests == 1, "Failure - incorrect number of requests for ReaderGCNoWait! #requests: " + requests); break; } break; case ReaderTestType.NoCloses: // 1 for connection, 1 for current command, 1 for 0 based array offset, plus i for open readers Assert.True(connections == (3 + i), "Failure - incorrect number of connections for NoCloses: " + connections); // 1 for current command, 1 for 0 based array offset, plus i open readers Assert.True(requests == (2 + i), "Failure - incorrect number of requests for NoCloses: " + requests); break; } break; } } } } }
Guid IMongoDbProfiler.ExecuteStart(string collectionName, IMongoQuery query, IMongoUpdate update, ExecuteType executeType) { return MongoProfiler.ExecuteStart(collectionName, query, update, executeType); }
Guid IMongoDbProfiler.ExecuteStart(string collectionName, object query, ExecuteType executeType) { return MongoProfiler.ExecuteStart(collectionName, query, executeType); }