Skip to content

Commit eb548ef

Browse files
author
Cédric L. Charlier
committed
Fix isue with milliseconds converted to seconds
1 parent 69a5ffd commit eb548ef

File tree

8 files changed

+29
-37
lines changed

8 files changed

+29
-37
lines changed

NBi.Core/Query/Client/AdomdClient.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,11 @@ class AdomdClient : IClient
1717
public Type UnderlyingSessionType => typeof(AdomdConnection);
1818

1919
public AdomdClient(string connectionString)
20-
{
21-
ConnectionString = connectionString;
22-
}
20+
=> ConnectionString = connectionString;
2321

2422
public object CreateNew() => CreateConnection();
2523

26-
public Microsoft.AnalysisServices.AdomdClient.AdomdConnection CreateConnection()
27-
{
28-
return new Microsoft.AnalysisServices.AdomdClient.AdomdConnection(ConnectionString);
29-
}
30-
24+
public AdomdConnection CreateConnection()
25+
=> new AdomdConnection(ConnectionString);
3126
}
3227
}

NBi.Core/Query/Execution/AdomdExecutionEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public AdomdExecutionEngine(AdomdConnection connection, AdomdCommand command)
2323

2424
internal override void OpenConnection(IDbConnection connection)
2525
{
26-
var connectionString = command.Connection.ConnectionString;
26+
var connectionString = Command.Connection.ConnectionString;
2727
try
2828
{ connection.ConnectionString = connectionString; }
2929
catch (ArgumentException ex)

NBi.Core/Query/Execution/DbCommandExecutionEngine.cs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,21 @@
88

99
namespace NBi.Core.Query.Execution
1010
{
11-
/// <summary>
12-
/// Engine wrapping the System.Data.SqlClient namespace for execution of NBi tests
13-
/// <remarks>Instances of this class are built by the means of the <see>QueryEngineFactory</see></remarks>
14-
/// </summary>
1511
internal abstract class DbCommandExecutionEngine : IExecutionEngine
1612
{
17-
protected readonly IDbCommand command;
13+
protected IDbCommand Command { get; }
1814
private readonly Stopwatch stopWatch = new Stopwatch();
19-
protected internal TimeSpan CommandTimeout { get; internal set; }
15+
public TimeSpan CommandTimeout
16+
{
17+
get => new TimeSpan(0, 0, Command.CommandTimeout);
18+
set => Command.CommandTimeout = Convert.ToInt32(Math.Ceiling(value.TotalSeconds));
19+
}
2020
protected internal string ConnectionString { get; private set; }
2121

2222
protected DbCommandExecutionEngine(IDbConnection connection, IDbCommand command)
2323
{
24-
this.command = command;
25-
this.CommandTimeout = new TimeSpan(0, 0, command.CommandTimeout);
26-
this.ConnectionString = connection.ConnectionString;
24+
Command = command;
25+
ConnectionString = connection.ConnectionString;
2726
}
2827

2928
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities")]
@@ -32,9 +31,9 @@ public DataSet Execute()
3231
using (var connection = NewConnection())
3332
{
3433
OpenConnection(connection);
35-
InitializeCommand(command, CommandTimeout, command.Parameters, connection);
34+
InitializeCommand(Command, CommandTimeout, Command.Parameters, connection);
3635
StartWatch();
37-
var ds = OnExecuteDataSet(command);
36+
var ds = OnExecuteDataSet(Command);
3837
StopWatch();
3938
return ds;
4039
}
@@ -59,9 +58,9 @@ public object ExecuteScalar()
5958
using (var connection = NewConnection())
6059
{
6160
OpenConnection(connection);
62-
InitializeCommand(command, CommandTimeout, command.Parameters, connection);
61+
InitializeCommand(Command, CommandTimeout, Command.Parameters, connection);
6362
StartWatch();
64-
var value = OnExecuteScalar(command);
63+
var value = OnExecuteScalar(Command);
6564
StopWatch();
6665
return value;
6766
}
@@ -83,9 +82,9 @@ public IEnumerable<T> ExecuteList<T>()
8382
using (var connection = NewConnection())
8483
{
8584
OpenConnection(connection);
86-
InitializeCommand(command, CommandTimeout, command.Parameters, connection);
85+
InitializeCommand(Command, CommandTimeout, Command.Parameters, connection);
8786
StartWatch();
88-
var list = OnExecuteList<T>(command);
87+
var list = OnExecuteList<T>(Command);
8988
StopWatch();
9089
return list;
9190
}
@@ -112,8 +111,9 @@ protected void InitializeCommand(IDbCommand command, TimeSpan commandTimeout, ID
112111
Trace.WriteLineIf(Extensibility.NBiTraceSwitch.TraceVerbose, command.CommandText);
113112
command.Connection = connection;
114113
foreach (IDataParameter param in parameters)
115-
Trace.WriteLineIf(Extensibility.NBiTraceSwitch.TraceVerbose, string.Format("{0} => {1}", param.ParameterName, param.Value));
114+
Trace.WriteLineIf(Extensibility.NBiTraceSwitch.TraceVerbose, $"{param.ParameterName} => {param.Value}");
116115
command.CommandTimeout = Convert.ToInt32(commandTimeout.TotalSeconds);
116+
Trace.WriteLineIf(Extensibility.NBiTraceSwitch.TraceVerbose, $"Command timeout set to {command.CommandTimeout} second{(command.CommandTimeout>1 ? "s" : string.Empty)}");
117117
}
118118

119119
protected abstract void HandleException(Exception ex, IDbCommand command);
@@ -122,10 +122,7 @@ protected void InitializeCommand(IDbCommand command, TimeSpan commandTimeout, ID
122122
protected internal abstract IDbConnection NewConnection();
123123
protected abstract IDataAdapter NewDataAdapter(IDbCommand command);
124124

125-
protected void StartWatch()
126-
{
127-
stopWatch.Restart();
128-
}
125+
protected void StartWatch() => stopWatch.Restart();
129126

130127
protected void StopWatch()
131128
{
@@ -134,6 +131,6 @@ protected void StopWatch()
134131
}
135132

136133
protected internal TimeSpan Elapsed { get => stopWatch.Elapsed; }
137-
134+
138135
}
139136
}

NBi.Core/Query/Execution/OdbcExecutionEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public OdbcExecutionEngine(OdbcConnection connection, OdbcCommand command)
2121

2222
internal override void OpenConnection(IDbConnection connection)
2323
{
24-
var connectionString = command.Connection.ConnectionString;
24+
var connectionString = Command.Connection.ConnectionString;
2525
try
2626
{ connection.ConnectionString = connectionString; }
2727
catch (ArgumentException ex)

NBi.Core/Query/Execution/OledbExecutionEngine.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public OleDbExecutionEngine(OleDbConnection connection, OleDbCommand command)
2020

2121
internal override void OpenConnection(IDbConnection connection)
2222
{
23-
var connectionString = command.Connection.ConnectionString;
23+
var connectionString = Command.Connection.ConnectionString;
2424
try
2525
{ connection.ConnectionString = connectionString; }
2626
catch (ArgumentException ex)
@@ -31,7 +31,7 @@ internal override void OpenConnection(IDbConnection connection)
3131
catch (OleDbException ex)
3232
{ throw new ConnectionException(ex, connectionString); }
3333

34-
command.Connection = connection;
34+
Command.Connection = connection;
3535
}
3636

3737
protected override void HandleException(Exception ex, IDbCommand command)

NBi.Core/Query/Execution/SqlExecutionEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public SqlExecutionEngine(SqlConnection connection, SqlCommand command)
2121

2222
internal override void OpenConnection(IDbConnection connection)
2323
{
24-
var connectionString = command.Connection.ConnectionString;
24+
var connectionString = Command.Connection.ConnectionString;
2525
try
2626
{ connection.ConnectionString = connectionString; }
2727
catch (ArgumentException ex)

NBi.Core/Query/Format/AdomdFormatEngine.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public IEnumerable<string> ExecuteFormat()
3535
using (var connection = NewConnection())
3636
{
3737
OpenConnection(connection);
38-
InitializeCommand(command, CommandTimeout, command.Parameters, connection);
38+
InitializeCommand(Command, CommandTimeout, Command.Parameters, connection);
3939
StartWatch();
40-
var cs = OnExecuteCellSet(command as AdomdCommand);
40+
var cs = OnExecuteCellSet(Command as AdomdCommand);
4141
StopWatch();
4242
return Parse(cs);
4343
}

NBi.NUnit/Builder/Helper/QueryResolverArgsBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ protected void Build(QueryXml queryXml)
6969
var connectionString = new ConnectionStringHelper().Execute(queryXml, scope);
7070
var parameters = BuildParameters(queryXml.GetParameters());
7171
var templateVariables = queryXml.GetTemplateVariables();
72-
var timeout = queryXml.Timeout;
72+
var timeout = Convert.ToInt32(Math.Ceiling(queryXml.Timeout / 1000m)); //Timeout is expressed in milliseconds
7373

7474
if (!string.IsNullOrEmpty(queryXml.InlineQuery))
7575
args = new EmbeddedQueryResolverArgs(queryXml.InlineQuery

0 commit comments

Comments
 (0)