Skip to content

Commit

Permalink
Fix isue with milliseconds converted to seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric L. Charlier committed Nov 1, 2019
1 parent 69a5ffd commit eb548ef
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 37 deletions.
11 changes: 3 additions & 8 deletions NBi.Core/Query/Client/AdomdClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion NBi.Core/Query/Execution/AdomdExecutionEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
39 changes: 18 additions & 21 deletions NBi.Core/Query/Execution/DbCommandExecutionEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,21 @@

namespace NBi.Core.Query.Execution
{
/// <summary>
/// Engine wrapping the System.Data.SqlClient namespace for execution of NBi tests
/// <remarks>Instances of this class are built by the means of the <see>QueryEngineFactory</see></remarks>
/// </summary>
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")]
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -83,9 +82,9 @@ public IEnumerable<T> ExecuteList<T>()
using (var connection = NewConnection())
{
OpenConnection(connection);
InitializeCommand(command, CommandTimeout, command.Parameters, connection);
InitializeCommand(Command, CommandTimeout, Command.Parameters, connection);
StartWatch();
var list = OnExecuteList<T>(command);
var list = OnExecuteList<T>(Command);
StopWatch();
return list;
}
Expand All @@ -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);
Expand All @@ -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()
{
Expand All @@ -134,6 +131,6 @@ protected void StopWatch()
}

protected internal TimeSpan Elapsed { get => stopWatch.Elapsed; }

}
}
2 changes: 1 addition & 1 deletion NBi.Core/Query/Execution/OdbcExecutionEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions NBi.Core/Query/Execution/OledbExecutionEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion NBi.Core/Query/Execution/SqlExecutionEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions NBi.Core/Query/Format/AdomdFormatEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public IEnumerable<string> 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);
}
Expand Down
2 changes: 1 addition & 1 deletion NBi.NUnit/Builder/Helper/QueryResolverArgsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eb548ef

Please sign in to comment.