Example #1
0
        public PerformanceResult CheckPerformance(int timeout)
        {
            bool     isTimeout = false;
            DateTime tsStart, tsStop = DateTime.Now;

            if (command.Connection.State == ConnectionState.Closed)
            {
                try
                {
                    command.Connection.Open();
                }
                catch (SqlException ex)
                {
                    throw new ConnectionException(ex, command.Connection.ConnectionString);
                }
            }

            Trace.WriteLineIf(NBiTraceSwitch.TraceVerbose, command.CommandText);
            foreach (SqlParameter param in command.Parameters)
            {
                Trace.WriteLineIf(NBiTraceSwitch.TraceVerbose, string.Format("{0} => {1}", param.ParameterName, param.Value));
            }

            command.CommandTimeout = timeout / 1000;

            tsStart = DateTime.Now;
            try
            {
                command.ExecuteNonQuery();
                tsStop = DateTime.Now;
            }
            catch (SqlException e)
            {
                if (!e.Message.StartsWith("Timeout expired."))
                {
                    throw;
                }
                isTimeout = true;
            }


            if (command.Connection.State == ConnectionState.Open)
            {
                command.Connection.Close();
            }

            if (isTimeout)
            {
                return(PerformanceResult.Timeout(timeout));
            }
            else
            {
                return(new PerformanceResult(tsStop.Subtract(tsStart)));
            }
        }
 /// <summary>
 /// Handle a sql string and check it with the engine
 /// </summary>
 /// <param name="actual">SQL string</param>
 /// <returns>true, if the query defined in parameter is executed in less that expected else false</returns>
 public bool doMatch(IDbCommand actual)
 {
     var engine = GetEngine(actual);
     if (cleanCache)
         engine.CleanCache();
     performanceResult = engine.CheckPerformance(timeOutMilliSeconds);
     return
         (
             performanceResult.TimeElapsed.TotalMilliseconds < maxTimeMilliSeconds
             && ! performanceResult.IsTimeOut
         );
 }
Example #3
0
        public PerformanceResult CheckPerformance(int timeout)
        {
            bool     isTimeout = false;
            DateTime tsStart, tsStop = DateTime.Now;

            if (command.Connection.State == ConnectionState.Closed)
            {
                command.Connection.Open();
            }

            tsStart = DateTime.Now;
            try
            {
                command.ExecuteNonQuery();
                tsStop = DateTime.Now;
            }
            catch (OleDbException e)
            {
                if (!e.Message.StartsWith("Timeout expired."))
                {
                    throw;
                }
                isTimeout = true;
            }

            if (command.Connection.State == ConnectionState.Open)
            {
                command.Connection.Close();
            }

            if (isTimeout)
            {
                return(PerformanceResult.Timeout(timeout));
            }
            else
            {
                return(new PerformanceResult(tsStop.Subtract(tsStart)));
            }
        }