mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
BatchParser target netstandard2.0 and remove Hosting dependency (#1564)
* Remove Hosting dependency from BatchParser, wip for logging replacement * netstandard2.0 and fixes * comment + cleanup * comment * fix build * Update newtonsoft * localize errors
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
//
|
//
|
||||||
|
|
||||||
using Microsoft.SqlTools.Utility;
|
using Microsoft.SqlTools.BatchParser.Utility;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using System.Diagnostics;
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection;
|
using Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection;
|
||||||
using Microsoft.SqlTools.Utility;
|
using Microsoft.SqlTools.BatchParser.Utility;
|
||||||
using Microsoft.SqlTools.ManagedBatchParser;
|
using Microsoft.SqlTools.ManagedBatchParser;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.BatchParser.ExecutionEngineCode
|
namespace Microsoft.SqlTools.ServiceLayer.BatchParser.ExecutionEngineCode
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ using System.IO;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.SqlTools.ManagedBatchParser;
|
using Microsoft.SqlTools.ManagedBatchParser;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection;
|
using Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection;
|
||||||
using Microsoft.SqlTools.Utility;
|
using Microsoft.SqlTools.BatchParser.Utility;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.BatchParser.ExecutionEngineCode
|
namespace Microsoft.SqlTools.ServiceLayer.BatchParser.ExecutionEngineCode
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using Microsoft.SqlTools.Utility;
|
using Microsoft.SqlTools.BatchParser.Utility;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.BatchParser.ExecutionEngineCode
|
namespace Microsoft.SqlTools.ServiceLayer.BatchParser.ExecutionEngineCode
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -285,6 +285,14 @@ namespace Microsoft.SqlTools.ManagedBatchParser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string NullEmptyOrWhitespaceString
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Keys.GetString(Keys.NullEmptyOrWhitespaceString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
public class Keys
|
public class Keys
|
||||||
{
|
{
|
||||||
@@ -389,6 +397,9 @@ namespace Microsoft.SqlTools.ManagedBatchParser
|
|||||||
public const string SqlCmd_FailedInclude = "SqlCmd_FailedInclude";
|
public const string SqlCmd_FailedInclude = "SqlCmd_FailedInclude";
|
||||||
|
|
||||||
|
|
||||||
|
public const string NullEmptyOrWhitespaceString = "NullEmptyOrWhitespaceString";
|
||||||
|
|
||||||
|
|
||||||
private Keys()
|
private Keys()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|||||||
@@ -245,4 +245,8 @@
|
|||||||
<value>Could not find included file {0}.</value>
|
<value>Could not find included file {0}.</value>
|
||||||
<comment></comment>
|
<comment></comment>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="NullEmptyOrWhitespaceString" xml:space="preserve">
|
||||||
|
<value>Parameter contains a null, empty, or whitespace string.</value>
|
||||||
|
<comment></comment>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|||||||
@@ -88,3 +88,5 @@ SqlCmd_PathLong = Path too long.
|
|||||||
|
|
||||||
SqlCmd_FailedInclude = Could not find included file {0}.
|
SqlCmd_FailedInclude = Could not find included file {0}.
|
||||||
|
|
||||||
|
NullEmptyOrWhitespaceString = Parameter contains a null, empty, or whitespace string.
|
||||||
|
|
||||||
|
|||||||
@@ -162,6 +162,11 @@
|
|||||||
<target state="new">Could not find included file {0}.</target>
|
<target state="new">Could not find included file {0}.</target>
|
||||||
<note></note>
|
<note></note>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
|
<trans-unit id="NullEmptyOrWhitespaceString">
|
||||||
|
<source>Parameter contains a null, empty, or whitespace string.</source>
|
||||||
|
<target state="new">Parameter contains a null, empty, or whitespace string.</target>
|
||||||
|
<note></note>
|
||||||
|
</trans-unit>
|
||||||
</body>
|
</body>
|
||||||
</file>
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
<!-- Targeting netstandard2.0 so that other things such as PS cmdlets can use this which need to support a wider range of machines -->
|
||||||
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
|
<Nullable>disable</Nullable>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
<EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
|
<EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
|
||||||
<EmbeddedResourceUseDependentUponConvention>false</EmbeddedResourceUseDependentUponConvention>
|
<EmbeddedResourceUseDependentUponConvention>false</EmbeddedResourceUseDependentUponConvention>
|
||||||
@@ -12,12 +15,10 @@
|
|||||||
<PackageReference Include="Microsoft.SqlServer.DACFx" />
|
<PackageReference Include="Microsoft.SqlServer.DACFx" />
|
||||||
<PackageReference Include="Microsoft.SqlServer.SqlManagementObjects" />
|
<PackageReference Include="Microsoft.SqlServer.SqlManagementObjects" />
|
||||||
<PackageReference Include="Microsoft.SqlServer.Management.SmoMetadataProvider" />
|
<PackageReference Include="Microsoft.SqlServer.Management.SmoMetadataProvider" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="Localization\*.resx" />
|
<EmbeddedResource Include="Localization\*.resx" />
|
||||||
<None Include="Localization\sr.strings" />
|
<None Include="Localization\sr.strings" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\Microsoft.SqlTools.Hosting\Microsoft.SqlTools.Hosting.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Microsoft.SqlTools.Utility;
|
using Microsoft.SqlTools.BatchParser.Utility;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ using System.Diagnostics;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.SqlServer.Management.Common;
|
using Microsoft.SqlServer.Management.Common;
|
||||||
using Microsoft.SqlServer.Management.Dmf;
|
using Microsoft.SqlServer.Management.Dmf;
|
||||||
using Microsoft.SqlTools.Utility;
|
using Microsoft.SqlTools.BatchParser.Utility;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using Microsoft.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using Microsoft.SqlTools.Utility;
|
using Microsoft.SqlTools.BatchParser.Utility;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using Microsoft.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using Microsoft.SqlTools.Utility;
|
using Microsoft.SqlTools.BatchParser.Utility;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ using System.Diagnostics;
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Security;
|
using System.Security;
|
||||||
using Microsoft.SqlTools.Utility;
|
using Microsoft.SqlTools.BatchParser.Utility;
|
||||||
using Microsoft.SqlServer.Management.Common;
|
using Microsoft.SqlServer.Management.Common;
|
||||||
using Microsoft.SqlServer.Management.Smo;
|
using Microsoft.SqlServer.Management.Smo;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ using System.Text;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.SqlServer.Management.Common;
|
using Microsoft.SqlServer.Management.Common;
|
||||||
using Microsoft.SqlTools.Utility;
|
using Microsoft.SqlTools.BatchParser.Utility;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
using Microsoft.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Microsoft.SqlTools.Utility;
|
using Microsoft.SqlTools.BatchParser.Utility;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ using System.Diagnostics;
|
|||||||
using System.Diagnostics.Contracts;
|
using System.Diagnostics.Contracts;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Microsoft.SqlTools.Utility;
|
using Microsoft.SqlTools.BatchParser.Utility;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Microsoft.SqlTools.Utility;
|
using Microsoft.SqlTools.BatchParser.Utility;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ using System.Collections.Generic;
|
|||||||
using Microsoft.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Microsoft.SqlTools.Utility;
|
using Microsoft.SqlTools.BatchParser.Utility;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
||||||
{
|
{
|
||||||
|
|||||||
91
src/Microsoft.SqlTools.ManagedBatchParser/Utility/Logger.cs
Normal file
91
src/Microsoft.SqlTools.ManagedBatchParser/Utility/Logger.cs
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
//
|
||||||
|
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.BatchParser.Utility
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Provides a simple logging interface built on top of .Net tracing frameworks
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>This functionality is a simplified version of other similar implementations such as from Microsoft.SqlTools.Hosting, using
|
||||||
|
/// just pure Trace calls instead of setting up a TraceSource and/or listeners to keep this as simple as possible.</remarks>
|
||||||
|
public static class Logger
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Writes a message to the log file with the Verbose event level
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="logMessage">The message text to be written.</param>
|
||||||
|
public static void Verbose(string logMessage) => Write(TraceEventType.Verbose, logMessage);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes a message to the log file with the Information event level
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="logMessage">The message text to be written.</param>
|
||||||
|
public static void Information(string logMessage) => Write(TraceEventType.Information, logMessage);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes a message to the log file with the Warning event level
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="logMessage">The message text to be written.</param>
|
||||||
|
public static void Warning(string logMessage) => Write(TraceEventType.Warning, logMessage);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes a message to the log file with the Error event level
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="logMessage">The message text to be written.</param>
|
||||||
|
public static void Error(string logMessage) => Write(TraceEventType.Error, logMessage);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes a message to the log file with the Critical event level
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="logMessage">The message text to be written.</param>
|
||||||
|
public static void Critical(string logMessage) => Write(TraceEventType.Critical, logMessage);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes a message to the log file.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="eventType">The level at which the message will be written.</param>
|
||||||
|
/// <param name="logEvent">The event id enumeration for the log event.</param>
|
||||||
|
/// <param name="logMessage">The message text to be written.</param>
|
||||||
|
public static void Write(
|
||||||
|
TraceEventType eventType,
|
||||||
|
string logMessage)
|
||||||
|
{
|
||||||
|
// Note that despite the more fine grained TraceEventType we expose in this class we currently are using just the default
|
||||||
|
// Trace methods available which only allow Error/Warning/Information. An improvement would be to fully implement a TraceSource/EventSource
|
||||||
|
// and use that instead, then ensure that users of this library are set up to consume events from that source.
|
||||||
|
switch (eventType)
|
||||||
|
{
|
||||||
|
case TraceEventType.Critical:
|
||||||
|
case TraceEventType.Error:
|
||||||
|
if (eventType == TraceEventType.Critical)
|
||||||
|
{
|
||||||
|
logMessage = $@"event={eventType}: {logMessage}";
|
||||||
|
}
|
||||||
|
|
||||||
|
Trace.TraceError(logMessage);
|
||||||
|
break;
|
||||||
|
case TraceEventType.Warning:
|
||||||
|
Trace.TraceWarning(logMessage);
|
||||||
|
break;
|
||||||
|
case TraceEventType.Information:
|
||||||
|
case TraceEventType.Resume:
|
||||||
|
case TraceEventType.Start:
|
||||||
|
case TraceEventType.Stop:
|
||||||
|
case TraceEventType.Suspend:
|
||||||
|
case TraceEventType.Transfer:
|
||||||
|
case TraceEventType.Verbose:
|
||||||
|
if (eventType != TraceEventType.Information)
|
||||||
|
{
|
||||||
|
logMessage = $@"event={eventType}: {logMessage}";
|
||||||
|
}
|
||||||
|
|
||||||
|
Trace.TraceInformation(logMessage);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
//
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using Microsoft.SqlTools.ManagedBatchParser;
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.BatchParser.Utility
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Provides common validation methods to simplify method
|
||||||
|
/// parameter checks.
|
||||||
|
/// </summary>
|
||||||
|
public static class Validate
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Throws ArgumentNullException if value is null.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="parameterName">The name of the parameter being validated.</param>
|
||||||
|
/// <param name="valueToCheck">The value of the parameter being validated.</param>
|
||||||
|
public static void IsNotNull(string parameterName, object valueToCheck)
|
||||||
|
{
|
||||||
|
if (valueToCheck == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(parameterName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Throws ArgumentException if the value is null or an empty string.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="parameterName">The name of the parameter being validated.</param>
|
||||||
|
/// <param name="valueToCheck">The value of the parameter being validated.</param>
|
||||||
|
public static void IsNotNullOrEmptyString(string parameterName, string valueToCheck)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(valueToCheck))
|
||||||
|
{
|
||||||
|
throw new ArgumentException(
|
||||||
|
SR.NullEmptyOrWhitespaceString,
|
||||||
|
parameterName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Throws ArgumentException if the value is null, an empty string,
|
||||||
|
/// or a string containing only whitespace.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="parameterName">The name of the parameter being validated.</param>
|
||||||
|
/// <param name="valueToCheck">The value of the parameter being validated.</param>
|
||||||
|
public static void IsNotNullOrWhitespaceString(string parameterName, string valueToCheck)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(valueToCheck))
|
||||||
|
{
|
||||||
|
throw new ArgumentException(
|
||||||
|
SR.NullEmptyOrWhitespaceString,
|
||||||
|
parameterName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user