Feature/timestamp messages (#68)

* added support for timestamps

* fixed tests

* Moved message class to own file; added 'z' to end of date strings

* added default time constructor

* removed unnecessary z

* added time string format info in comment

* changed from utc time to using local time
This commit is contained in:
Anthony Dresser
2016-09-30 11:46:32 -07:00
committed by GitHub
parent 3f77e14347
commit d451447ebc
5 changed files with 59 additions and 14 deletions

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration >
<packageSources>
<add key="Nuget" value="https://www.nuget.org/api/v2" />
<add key="DataTools Nuget" value="http://dtnuget/api/v2/" />
</packageSources>
</configuration>

View File

@@ -38,7 +38,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
/// <summary>
/// Internal representation of the messages so we can modify internally
/// </summary>
private readonly List<string> resultMessages;
private readonly List<ResultMessage> resultMessages;
/// <summary>
/// Internal representation of the result sets so we can modify internally
@@ -58,7 +58,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
Selection = new SelectionData(startLine, startColumn, endLine, endColumn);
HasExecuted = false;
resultSets = new List<ResultSet>();
resultMessages = new List<string>();
resultMessages = new List<ResultMessage>();
this.outputFileFactory = outputFileFactory;
}
@@ -82,7 +82,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
/// <summary>
/// Messages that have come back from the server
/// </summary>
public IEnumerable<string> ResultMessages
public IEnumerable<ResultMessage> ResultMessages
{
get { return resultMessages; }
}
@@ -168,9 +168,9 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
if (!reader.HasRows && reader.FieldCount == 0)
{
// Create a message with the number of affected rows -- IF the query affects rows
resultMessages.Add(reader.RecordsAffected >= 0
? SR.QueryServiceAffectedRows(reader.RecordsAffected)
: SR.QueryServiceCompletedSuccessfully);
resultMessages.Add(new ResultMessage(reader.RecordsAffected >= 0
? SR.QueryServiceAffectedRows(reader.RecordsAffected)
: SR.QueryServiceCompletedSuccessfully));
continue;
}
@@ -183,7 +183,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
resultSets.Add(resultSet);
// Add a message for the number of rows the query returned
resultMessages.Add(SR.QueryServiceAffectedRows(resultSet.RowCount));
resultMessages.Add(new ResultMessage(SR.QueryServiceAffectedRows(resultSet.RowCount)));
} while (await reader.NextResultAsync(cancellationToken));
}
}
@@ -244,7 +244,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
/// <param name="args">Arguments from the event</param>
private void StoreDbMessage(object sender, SqlInfoMessageEventArgs args)
{
resultMessages.Add(args.Message);
resultMessages.Add(new ResultMessage(args.Message));
}
/// <summary>
@@ -268,13 +268,13 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
string message = string.Format("Msg {0}, Level {1}, State {2}, Line {3}{4}{5}",
sqlError.Number, sqlError.Class, sqlError.State, lineNumber,
Environment.NewLine, sqlError.Message);
resultMessages.Add(message);
resultMessages.Add(new ResultMessage(message));
}
}
}
else
{
resultMessages.Add(dbe.Message);
resultMessages.Add(new ResultMessage(dbe.Message));
}
}

View File

@@ -28,7 +28,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
/// <summary>
/// Any messages that came back from the server during execution of the batch
/// </summary>
public string[] Messages { get; set; }
public ResultMessage[] Messages { get; set; }
/// <summary>
/// The summaries of the result sets inside the batch

View File

@@ -0,0 +1,44 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
{
/// <summary>
/// Result message object with timestamp and actual message
/// </summary>
public class ResultMessage
{
/// <summary>
/// Timestamp of the message
/// Stored in UTC ISO 8601 format; should be localized before displaying to any user
/// </summary>
public string Time { get; set; }
/// <summary>
/// Message contents
/// </summary>
public string Message { get; set; }
/// <summary>
/// Full constructor
/// </summary>
public ResultMessage(string timeStamp, string message)
{
Time = timeStamp;
Message = message;
}
/// <summary>
/// Constructor with default "Now" time
/// </summary>
public ResultMessage(string message)
{
Time = DateTime.Now.ToString("o");
Message = message;
}
}
}

View File

@@ -74,7 +74,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
// ... There should be a message for how many rows were affected
Assert.Equal(1, batch.ResultMessages.Count());
Assert.Contains("1 ", batch.ResultMessages.First());
Assert.Contains("1 ", batch.ResultMessages.First().Message);
// NOTE: 1 is expected because this test simulates a 'update' statement where 1 row was affected.
// The 1 in quotes is to make sure the 1 isn't part of a larger number
}
@@ -108,7 +108,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
// ... There should be a message for how many rows were affected
Assert.Equal(resultSets, batch.ResultMessages.Count());
Assert.Contains(Common.StandardRows.ToString(), batch.ResultMessages.First());
Assert.Contains(Common.StandardRows.ToString(), batch.ResultMessages.First().Message);
}
[Fact]
@@ -155,7 +155,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
Assert.Equal(resultSets, batch.ResultMessages.Count());
foreach (var rsm in batch.ResultMessages)
{
Assert.Contains(Common.StandardRows.ToString(), rsm);
Assert.Contains(Common.StandardRows.ToString(), rsm.Message);
}
}