From eb548ef4656715ca125bad34441991464070132a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20L=2E=20Charlier?= Date: Fri, 1 Nov 2019 12:13:31 +0100 Subject: [PATCH] Fix isue with milliseconds converted to seconds --- NBi.Core/Query/Client/AdomdClient.cs | 11 ++---- .../Query/Execution/AdomdExecutionEngine.cs | 2 +- .../Execution/DbCommandExecutionEngine.cs | 39 +++++++++---------- .../Query/Execution/OdbcExecutionEngine.cs | 2 +- .../Query/Execution/OledbExecutionEngine.cs | 4 +- .../Query/Execution/SqlExecutionEngine.cs | 2 +- NBi.Core/Query/Format/AdomdFormatEngine.cs | 4 +- .../Helper/QueryResolverArgsBuilder.cs | 2 +- 8 files changed, 29 insertions(+), 37 deletions(-) diff --git a/NBi.Core/Query/Client/AdomdClient.cs b/NBi.Core/Query/Client/AdomdClient.cs index 5e3811fc5..8922954cd 100644 --- a/NBi.Core/Query/Client/AdomdClient.cs +++ b/NBi.Core/Query/Client/AdomdClient.cs @@ -17,16 +17,11 @@ class AdomdClient : IClient public Type UnderlyingSessionType => typeof(AdomdConnection); public AdomdClient(string connectionString) - { - ConnectionString = connectionString; - } + => ConnectionString = connectionString; public object CreateNew() => CreateConnection(); - public Microsoft.AnalysisServices.AdomdClient.AdomdConnection CreateConnection() - { - return new Microsoft.AnalysisServices.AdomdClient.AdomdConnection(ConnectionString); - } - + public AdomdConnection CreateConnection() + => new AdomdConnection(ConnectionString); } } diff --git a/NBi.Core/Query/Execution/AdomdExecutionEngine.cs b/NBi.Core/Query/Execution/AdomdExecutionEngine.cs index bbc92967b..2ab644865 100644 --- a/NBi.Core/Query/Execution/AdomdExecutionEngine.cs +++ b/NBi.Core/Query/Execution/AdomdExecutionEngine.cs @@ -23,7 +23,7 @@ public AdomdExecutionEngine(AdomdConnection connection, AdomdCommand command) internal override void OpenConnection(IDbConnection connection) { - var connectionString = command.Connection.ConnectionString; + var connectionString = Command.Connection.ConnectionString; try { connection.ConnectionString = connectionString; } catch (ArgumentException ex) diff --git a/NBi.Core/Query/Execution/DbCommandExecutionEngine.cs b/NBi.Core/Query/Execution/DbCommandExecutionEngine.cs index a3f522cd6..95664bd52 100644 --- a/NBi.Core/Query/Execution/DbCommandExecutionEngine.cs +++ b/NBi.Core/Query/Execution/DbCommandExecutionEngine.cs @@ -8,22 +8,21 @@ namespace NBi.Core.Query.Execution { - /// - /// Engine wrapping the System.Data.SqlClient namespace for execution of NBi tests - /// Instances of this class are built by the means of the QueryEngineFactory - /// internal abstract class DbCommandExecutionEngine : IExecutionEngine { - protected readonly IDbCommand command; + protected IDbCommand Command { get; } private readonly Stopwatch stopWatch = new Stopwatch(); - protected internal TimeSpan CommandTimeout { get; internal set; } + public TimeSpan CommandTimeout + { + get => new TimeSpan(0, 0, Command.CommandTimeout); + set => Command.CommandTimeout = Convert.ToInt32(Math.Ceiling(value.TotalSeconds)); + } protected internal string ConnectionString { get; private set; } protected DbCommandExecutionEngine(IDbConnection connection, IDbCommand command) { - this.command = command; - this.CommandTimeout = new TimeSpan(0, 0, command.CommandTimeout); - this.ConnectionString = connection.ConnectionString; + Command = command; + ConnectionString = connection.ConnectionString; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities")] @@ -32,9 +31,9 @@ public DataSet Execute() using (var connection = NewConnection()) { OpenConnection(connection); - InitializeCommand(command, CommandTimeout, command.Parameters, connection); + InitializeCommand(Command, CommandTimeout, Command.Parameters, connection); StartWatch(); - var ds = OnExecuteDataSet(command); + var ds = OnExecuteDataSet(Command); StopWatch(); return ds; } @@ -59,9 +58,9 @@ public object ExecuteScalar() using (var connection = NewConnection()) { OpenConnection(connection); - InitializeCommand(command, CommandTimeout, command.Parameters, connection); + InitializeCommand(Command, CommandTimeout, Command.Parameters, connection); StartWatch(); - var value = OnExecuteScalar(command); + var value = OnExecuteScalar(Command); StopWatch(); return value; } @@ -83,9 +82,9 @@ public IEnumerable ExecuteList() using (var connection = NewConnection()) { OpenConnection(connection); - InitializeCommand(command, CommandTimeout, command.Parameters, connection); + InitializeCommand(Command, CommandTimeout, Command.Parameters, connection); StartWatch(); - var list = OnExecuteList(command); + var list = OnExecuteList(Command); StopWatch(); return list; } @@ -112,8 +111,9 @@ protected void InitializeCommand(IDbCommand command, TimeSpan commandTimeout, ID Trace.WriteLineIf(Extensibility.NBiTraceSwitch.TraceVerbose, command.CommandText); command.Connection = connection; foreach (IDataParameter param in parameters) - Trace.WriteLineIf(Extensibility.NBiTraceSwitch.TraceVerbose, string.Format("{0} => {1}", param.ParameterName, param.Value)); + Trace.WriteLineIf(Extensibility.NBiTraceSwitch.TraceVerbose, $"{param.ParameterName} => {param.Value}"); command.CommandTimeout = Convert.ToInt32(commandTimeout.TotalSeconds); + Trace.WriteLineIf(Extensibility.NBiTraceSwitch.TraceVerbose, $"Command timeout set to {command.CommandTimeout} second{(command.CommandTimeout>1 ? "s" : string.Empty)}"); } protected abstract void HandleException(Exception ex, IDbCommand command); @@ -122,10 +122,7 @@ protected void InitializeCommand(IDbCommand command, TimeSpan commandTimeout, ID protected internal abstract IDbConnection NewConnection(); protected abstract IDataAdapter NewDataAdapter(IDbCommand command); - protected void StartWatch() - { - stopWatch.Restart(); - } + protected void StartWatch() => stopWatch.Restart(); protected void StopWatch() { @@ -134,6 +131,6 @@ protected void StopWatch() } protected internal TimeSpan Elapsed { get => stopWatch.Elapsed; } - + } } diff --git a/NBi.Core/Query/Execution/OdbcExecutionEngine.cs b/NBi.Core/Query/Execution/OdbcExecutionEngine.cs index ec3791001..a335702bf 100644 --- a/NBi.Core/Query/Execution/OdbcExecutionEngine.cs +++ b/NBi.Core/Query/Execution/OdbcExecutionEngine.cs @@ -21,7 +21,7 @@ public OdbcExecutionEngine(OdbcConnection connection, OdbcCommand command) internal override void OpenConnection(IDbConnection connection) { - var connectionString = command.Connection.ConnectionString; + var connectionString = Command.Connection.ConnectionString; try { connection.ConnectionString = connectionString; } catch (ArgumentException ex) diff --git a/NBi.Core/Query/Execution/OledbExecutionEngine.cs b/NBi.Core/Query/Execution/OledbExecutionEngine.cs index f30dbd394..c44cc12ef 100644 --- a/NBi.Core/Query/Execution/OledbExecutionEngine.cs +++ b/NBi.Core/Query/Execution/OledbExecutionEngine.cs @@ -20,7 +20,7 @@ public OleDbExecutionEngine(OleDbConnection connection, OleDbCommand command) internal override void OpenConnection(IDbConnection connection) { - var connectionString = command.Connection.ConnectionString; + var connectionString = Command.Connection.ConnectionString; try { connection.ConnectionString = connectionString; } catch (ArgumentException ex) @@ -31,7 +31,7 @@ internal override void OpenConnection(IDbConnection connection) catch (OleDbException ex) { throw new ConnectionException(ex, connectionString); } - command.Connection = connection; + Command.Connection = connection; } protected override void HandleException(Exception ex, IDbCommand command) diff --git a/NBi.Core/Query/Execution/SqlExecutionEngine.cs b/NBi.Core/Query/Execution/SqlExecutionEngine.cs index aad9cd7af..7c2ce1160 100644 --- a/NBi.Core/Query/Execution/SqlExecutionEngine.cs +++ b/NBi.Core/Query/Execution/SqlExecutionEngine.cs @@ -21,7 +21,7 @@ public SqlExecutionEngine(SqlConnection connection, SqlCommand command) internal override void OpenConnection(IDbConnection connection) { - var connectionString = command.Connection.ConnectionString; + var connectionString = Command.Connection.ConnectionString; try { connection.ConnectionString = connectionString; } catch (ArgumentException ex) diff --git a/NBi.Core/Query/Format/AdomdFormatEngine.cs b/NBi.Core/Query/Format/AdomdFormatEngine.cs index b0d6d0a0d..4e15e2224 100644 --- a/NBi.Core/Query/Format/AdomdFormatEngine.cs +++ b/NBi.Core/Query/Format/AdomdFormatEngine.cs @@ -35,9 +35,9 @@ public IEnumerable ExecuteFormat() using (var connection = NewConnection()) { OpenConnection(connection); - InitializeCommand(command, CommandTimeout, command.Parameters, connection); + InitializeCommand(Command, CommandTimeout, Command.Parameters, connection); StartWatch(); - var cs = OnExecuteCellSet(command as AdomdCommand); + var cs = OnExecuteCellSet(Command as AdomdCommand); StopWatch(); return Parse(cs); } diff --git a/NBi.NUnit/Builder/Helper/QueryResolverArgsBuilder.cs b/NBi.NUnit/Builder/Helper/QueryResolverArgsBuilder.cs index 3eee0be52..36888ed7c 100644 --- a/NBi.NUnit/Builder/Helper/QueryResolverArgsBuilder.cs +++ b/NBi.NUnit/Builder/Helper/QueryResolverArgsBuilder.cs @@ -69,7 +69,7 @@ protected void Build(QueryXml queryXml) var connectionString = new ConnectionStringHelper().Execute(queryXml, scope); var parameters = BuildParameters(queryXml.GetParameters()); var templateVariables = queryXml.GetTemplateVariables(); - var timeout = queryXml.Timeout; + var timeout = Convert.ToInt32(Math.Ceiling(queryXml.Timeout / 1000m)); //Timeout is expressed in milliseconds if (!string.IsNullOrEmpty(queryXml.InlineQuery)) args = new EmbeddedQueryResolverArgs(queryXml.InlineQuery