Feature/serialization exe (#442)

* Initial changes to have serialization generate its own .exe

* Removed additional project from sln file

* remove all references to removed temporary project

* Moved shared contracts into own dll and fixed imports. Addressed PR comments

* Undid having a separate contracts project since that'll be a task for later on. Moved dbcellvalue and saveresultsrequest to Hosting, where they will be imported and shared by the service layer and serialization projects

* Switched backslashes in project reference in csproj file to forward slashes for consistency

* Moved necessary contracts back to service layer. Refactored CommandOptions to reduce code duplication. Addressed miscellaneous PR suggestions

* Accidentally left these files out of previous commit

* Initialized loggers for serialization and credentials with the logging directory provided by the cmd line arg, if there is one

* Changed default log directory paths for serialization and credentials. Removed unnecessary cast and added a copyright

* Changed name of generated executable for serialization service

* removed unnecessary object cast

* removing unnecessary imports and addressing other PR comments
This commit is contained in:
Henry Phan
2017-09-05 16:21:42 -07:00
committed by GitHub
parent 22ccac98ae
commit 784f4c5d05
26 changed files with 425 additions and 177 deletions

View File

@@ -17,6 +17,7 @@
],
"MainProjects": [
"Microsoft.SqlTools.ServiceLayer",
"Microsoft.SqlTools.Credentials"
"Microsoft.SqlTools.Credentials",
"Microsoft.Sqltools.Serialization"
]
}

View File

@@ -70,6 +70,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.SqlTools.ServiceL
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.SqlTools.ServiceLayer.TestEnvConfig", "test\Microsoft.SqlTools.ServiceLayer.TestEnvConfig\Microsoft.SqlTools.ServiceLayer.TestEnvConfig.csproj", "{2C290C58-C98D-46B2-BCED-44D9B67F6D31}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.SqlTools.Serialization", "src\Microsoft.SqlTools.Serialization\Microsoft.SqlTools.Serialization.csproj", "{75E1A89F-9DF6-4DA3-9EF1-5FD966331E06}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -137,6 +139,12 @@ Global
{2C290C58-C98D-46B2-BCED-44D9B67F6D31}.Integration|Any CPU.Build.0 = Debug|Any CPU
{2C290C58-C98D-46B2-BCED-44D9B67F6D31}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2C290C58-C98D-46B2-BCED-44D9B67F6D31}.Release|Any CPU.Build.0 = Release|Any CPU
{75E1A89F-9DF6-4DA3-9EF1-5FD966331E06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{75E1A89F-9DF6-4DA3-9EF1-5FD966331E06}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75E1A89F-9DF6-4DA3-9EF1-5FD966331E06}.Integration|Any CPU.ActiveCfg = Debug|Any CPU
{75E1A89F-9DF6-4DA3-9EF1-5FD966331E06}.Integration|Any CPU.Build.0 = Debug|Any CPU
{75E1A89F-9DF6-4DA3-9EF1-5FD966331E06}.Release|Any CPU.ActiveCfg = Release|Any CPU
{75E1A89F-9DF6-4DA3-9EF1-5FD966331E06}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -154,5 +162,9 @@ Global
{E985A5AA-63E4-48DC-A6D8-D3953A50D7E3} = {AB9CA2B8-6F70-431C-8A1D-67479D8A7BE4}
{501DB3B2-AF92-41CF-82F6-780F9C37C219} = {AB9CA2B8-6F70-431C-8A1D-67479D8A7BE4}
{2C290C58-C98D-46B2-BCED-44D9B67F6D31} = {AB9CA2B8-6F70-431C-8A1D-67479D8A7BE4}
{75E1A89F-9DF6-4DA3-9EF1-5FD966331E06} = {2BBD7364-054F-4693-97CD-1C395E3E84A9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B31CDF4B-2851-45E5-8C5F-BE97125D9DD8}
EndGlobalSection
EndGlobal

View File

@@ -6,8 +6,9 @@ using Microsoft.SqlTools.Extensibility;
using Microsoft.SqlTools.Hosting;
using Microsoft.SqlTools.Hosting.Protocol;
using Microsoft.SqlTools.ServiceLayer.SqlContext;
using Microsoft.SqlTools.Utility;
namespace Microsoft.SqlTools.Credentials
namespace Microsoft.SqlTools.Credentials.Utility
{
/// <summary>
/// Provides support for starting up a service host. This is a common responsibility
@@ -18,9 +19,9 @@ namespace Microsoft.SqlTools.Credentials
private static object lockObject = new object();
private static bool isLoaded;
internal static CredentialsServiceHost CreateAndStartServiceHost(SqlToolsContext sqlToolsContext)
internal static UtilityServiceHost CreateAndStartServiceHost(SqlToolsContext sqlToolsContext)
{
CredentialsServiceHost serviceHost = CredentialsServiceHost.Instance;
UtilityServiceHost serviceHost = UtilityServiceHost.Instance;
lock (lockObject)
{
if (!isLoaded)
@@ -40,7 +41,7 @@ namespace Microsoft.SqlTools.Credentials
return serviceHost;
}
private static void InitializeRequestHandlersAndServices(CredentialsServiceHost serviceHost, SqlToolsContext sqlToolsContext)
private static void InitializeRequestHandlersAndServices(UtilityServiceHost serviceHost, SqlToolsContext sqlToolsContext)
{
// Load extension provider, which currently finds all exports in current DLL. Can be changed to find based
// on directory or assembly list quite easily in the future

View File

@@ -35,4 +35,7 @@
<ItemGroup>
<EmbeddedResource Include="Localization\sr.resx" />
</ItemGroup>
<ItemGroup>
<Folder Include="Utility\" />
</ItemGroup>
</Project>

View File

@@ -5,6 +5,7 @@
using System;
using System.IO;
using Microsoft.SqlTools.Credentials.Utility;
using Microsoft.SqlTools.Hosting.Utility;
using Microsoft.SqlTools.ServiceLayer.SqlContext;
using Microsoft.SqlTools.Utility;
@@ -15,6 +16,8 @@ namespace Microsoft.SqlTools.Credentials
/// </summary>
internal class Program
{
private const string ServiceName = "MicrosoftSqlToolsCredentials.exe";
/// <summary>
/// Main entry point into the Credentials Service Host
/// </summary>
@@ -23,7 +26,7 @@ namespace Microsoft.SqlTools.Credentials
try
{
// read command-line arguments
CommandOptions commandOptions = new CommandOptions(args);
CommandOptions commandOptions = new CommandOptions(args, ServiceName);
if (commandOptions.ShouldExit)
{
return;
@@ -37,7 +40,7 @@ namespace Microsoft.SqlTools.Credentials
// turn on Verbose logging during early development
// we need to switch to Normal when preparing for public preview
Logger.Initialize(logFilePath, minimumLogLevel: LogLevel.Verbose, isEnabled: commandOptions.EnableLogging);
Logger.Initialize(logFilePath: logFilePath, minimumLogLevel: LogLevel.Verbose, isEnabled: commandOptions.EnableLogging);
Logger.Write(LogLevel.Normal, "Starting SqlTools Credentials Provider");
// set up the host details and profile paths
@@ -47,7 +50,7 @@ namespace Microsoft.SqlTools.Credentials
version: new Version(1, 0));
SqlToolsContext sqlToolsContext = new SqlToolsContext(hostDetails);
CredentialsServiceHost serviceHost = HostLoader.CreateAndStartServiceHost(sqlToolsContext);
UtilityServiceHost serviceHost = HostLoader.CreateAndStartServiceHost(sqlToolsContext);
serviceHost.WaitForExit();
}

View File

@@ -1,113 +0,0 @@
//
// 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 System.IO;
namespace Microsoft.SqlTools.Credentials.Utility
{
/// <summary>
/// The command-line options helper class.
/// </summary>
internal class CommandOptions
{
/// <summary>
/// Construct and parse command line options from the arguments array
/// </summary>
public CommandOptions(string[] args)
{
ErrorMessage = string.Empty;
try
{
for (int i = 0; i < args.Length; ++i)
{
string arg = args[i];
if (arg.StartsWith("--") || arg.StartsWith("-"))
{
if (arg.StartsWith("--"))
{
// Extracting arguments and properties
arg = arg.Substring(1).ToLowerInvariant();
}
switch (arg)
{
case "-enable-logging":
EnableLogging = true;
break;
case "-log-dir":
SetLoggingDirectory(args[++i]);
break;
case "h":
case "-help":
ShouldExit = true;
return;
default:
ErrorMessage += String.Format("Unknown argument \"{0}\"" + Environment.NewLine, arg);
break;
}
}
}
}
catch (Exception ex)
{
ErrorMessage += ex.ToString();
return;
}
finally
{
if (!string.IsNullOrEmpty(ErrorMessage) || ShouldExit)
{
Console.WriteLine(Usage);
ShouldExit = true;
}
}
}
internal string ErrorMessage { get; private set; }
/// <summary>
/// Whether diagnostic logging is enabled
/// </summary>
public bool EnableLogging { get; private set; }
/// <summary>
/// Gets the directory where log files are output.
/// </summary>
public string LoggingDirectory { get; private set; }
/// <summary>
/// Whether the program should exit immediately. Set to true when the usage is printed.
/// </summary>
public bool ShouldExit { get; private set; }
private void SetLoggingDirectory(string loggingDirectory)
{
if (string.IsNullOrWhiteSpace(loggingDirectory))
{
return;
}
this.LoggingDirectory = Path.GetFullPath(loggingDirectory);
}
/// <summary>
/// Get the usage string describing command-line arguments for the program
/// </summary>
public string Usage
{
get
{
var str = string.Format("{0}" + Environment.NewLine +
"Microsoft.SqlTools.Credentials " + Environment.NewLine +
" Options:" + Environment.NewLine +
" [--enable-logging]" + Environment.NewLine +
" [--help]" + Environment.NewLine,
ErrorMessage);
return str;
}
}
}
}

View File

@@ -7,18 +7,19 @@ using System;
using System.Globalization;
using System.IO;
namespace Microsoft.SqlTools.ServiceLayer.Utility
namespace Microsoft.SqlTools.Hosting.Utility
{
/// <summary>
/// The command-line options helper class.
/// </summary>
internal class CommandOptions
public class CommandOptions
{
/// <summary>
/// Construct and parse command line options from the arguments array
/// </summary>
public CommandOptions(string[] args)
public CommandOptions(string[] args, string serviceName)
{
ServiceName = serviceName;
ErrorMessage = string.Empty;
Locale = string.Empty;
@@ -70,7 +71,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility
}
}
internal string ErrorMessage { get; private set; }
/// <summary>
/// Contains any error messages during execution
/// </summary>
public string ErrorMessage { get; private set; }
/// <summary>
@@ -93,6 +97,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility
/// </summary>
public string Locale { get; private set; }
/// <summary>
/// Name of service that is receiving command options
/// </summary>
public string ServiceName { get; private set; }
/// <summary>
/// Get the usage string describing command-line arguments for the program
/// </summary>
@@ -101,7 +110,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility
get
{
var str = string.Format("{0}" + Environment.NewLine +
"Microsoft.SqlTools.ServiceLayer.exe " + Environment.NewLine +
ServiceName + " " + Environment.NewLine +
" Options:" + Environment.NewLine +
" [--enable-logging]" + Environment.NewLine +
" [--log-dir **] (default: current directory)" + Environment.NewLine +
@@ -122,20 +131,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility
this.LoggingDirectory = Path.GetFullPath(loggingDirectory);
}
private void SetLocale(string locale)
public virtual void SetLocale(string locale)
{
try
{
// Creating cultureInfo from our given locale
CultureInfo language = new CultureInfo(locale);
Locale = locale;
// Setting our language globally
CultureInfo.CurrentCulture = language;
CultureInfo.CurrentUICulture = language;
// Setting our internal SR culture to our global culture
SR.Culture = CultureInfo.CurrentCulture;
LocaleSetter(locale);
}
catch (CultureNotFoundException)
{
@@ -144,5 +144,21 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility
// into the CultureInfo constructor.
}
}
/// <summary>
/// Sets the Locale field used for testing and also sets the global CultureInfo used for
/// culture-specific messages
/// </summary>
/// <param name="locale"></param>
internal void LocaleSetter(string locale)
{
// Creating cultureInfo from our given locale
CultureInfo language = new CultureInfo(locale);
Locale = locale;
// Setting our language globally
CultureInfo.CurrentCulture = language;
CultureInfo.CurrentUICulture = language;
}
}
}

View File

@@ -1,4 +1,4 @@
//
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
@@ -12,34 +12,33 @@ using Microsoft.SqlTools.Hosting;
using Microsoft.SqlTools.Hosting.Contracts;
using Microsoft.SqlTools.Hosting.Protocol;
using Microsoft.SqlTools.Hosting.Protocol.Channel;
using Microsoft.SqlTools.Utility;
namespace Microsoft.SqlTools.Credentials
namespace Microsoft.SqlTools.Utility
{
/// <summary>
/// SQL Tools Credentials Service request handler. Provides the entire JSON RPC
/// SQL Tools Service request handler for any utility services. Provides the entire JSON RPC
/// implementation for sending/receiving JSON requests and dispatching the requests to
/// handlers that are registered prior to startup.
/// </summary>
public sealed class CredentialsServiceHost : ServiceHostBase
public sealed class UtilityServiceHost : ServiceHostBase
{
/// <summary>
/// This timeout limits the amount of time that shutdown tasks can take to complete
/// prior to the process shutting down.
/// </summary>
private const int ShutdownTimeoutInSeconds = 120;
private const int ShutdownTimeoutInSeconds = 120;
#region Singleton Instance Code
/// <summary>
/// Singleton instance of the service host for internal storage
/// </summary>
private static readonly Lazy<CredentialsServiceHost> instance = new Lazy<CredentialsServiceHost>(() => new CredentialsServiceHost());
private static readonly Lazy<UtilityServiceHost> instance = new Lazy<UtilityServiceHost>(() => new UtilityServiceHost());
/// <summary>
/// Current instance of the ServiceHost
/// </summary>
public static CredentialsServiceHost Instance
public static UtilityServiceHost Instance
{
get { return instance.Value; }
}
@@ -48,7 +47,7 @@ namespace Microsoft.SqlTools.Credentials
/// Constructs new instance of ServiceHost using the host and profile details provided.
/// Access is private to ensure only one instance exists at a time.
/// </summary>
private CredentialsServiceHost() : base(new StdioServerChannel())
private UtilityServiceHost() : base(new StdioServerChannel())
{
// Initialize the shutdown activities
shutdownCallbacks = new List<ShutdownCallback>();

View File

@@ -0,0 +1,83 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.SqlTools.Extensibility;
using Microsoft.SqlTools.Hosting;
using Microsoft.SqlTools.Hosting.Protocol;
using Microsoft.SqlTools.ServiceLayer.SqlContext;
using Microsoft.SqlTools.Utility;
namespace Microsoft.SqlTools.Serialization
{
/// <summary>
/// Provides support for starting up a service host. This is a common responsibility
/// for both the main service program and test driver that interacts with it
/// </summary>
public static class HostLoader
{
private static object lockObject = new object();
private static bool isLoaded;
internal static UtilityServiceHost CreateAndStartServiceHost(SqlToolsContext sqlToolsContext)
{
UtilityServiceHost serviceHost = UtilityServiceHost.Instance;
lock (lockObject)
{
if (!isLoaded)
{
// Grab the instance of the service host
serviceHost.Initialize();
InitializeRequestHandlersAndServices(serviceHost, sqlToolsContext);
// Start the service only after all request handlers are setup. This is vital
// as otherwise the Initialize event can be lost - it's processed and discarded before the handler
// is hooked up to receive the message
serviceHost.Start().Wait();
isLoaded = true;
}
}
return serviceHost;
}
private static void InitializeRequestHandlersAndServices(UtilityServiceHost serviceHost, SqlToolsContext sqlToolsContext)
{
// Load extension provider, which currently finds all exports in current DLL. Can be changed to find based
// on directory or assembly list quite easily in the future
ExtensionServiceProvider serviceProvider = ExtensionServiceProvider.CreateDefaultServiceProvider();
serviceProvider.RegisterSingleService(sqlToolsContext);
serviceProvider.RegisterSingleService(serviceHost);
SerializationService serializationService = serviceProvider.GetService<SerializationService>();
serializationService.InitializeService(serviceHost);
serviceProvider.RegisterSingleService(serializationService);
InitializeHostedServices(serviceProvider, serviceHost);
serviceHost.InitializeRequestHandlers();
}
/// <summary>
/// Internal to support testing. Initializes <see cref="IHostedService"/> instances in the service,
/// and registers them for their preferred service type
/// </summary>
internal static void InitializeHostedServices(RegisteredServiceProvider provider, IProtocolEndpoint host)
{
// Pre-register all services before initializing. This ensures that if one service wishes to reference
// another one during initialization, it will be able to safely do so
foreach (IHostedService service in provider.GetServices<IHostedService>())
{
provider.RegisterSingleService(service.ServiceType, service);
}
foreach (IHostedService service in provider.GetServices<IHostedService>())
{
// Initialize all hosted services, and register them in the service provider for their requested
// service type. This ensures that when searching for the ConnectionService you can get it without
// searching for an IHostedService of type ConnectionService
service.InitializeService(host);
}
}
}
}

View File

@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<PackageId>SqlSerializationService</PackageId>
<AssemblyName>SqlSerializationService</AssemblyName>
<Company>Microsoft</Company>
<Product>Sql Tools Serialization Service</Product>
<Description>Provides serialization functionality.</Description>
<Copyright><EFBFBD> Microsoft Corporation. All rights reserved.</Copyright>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>TRACE;DEBUG;NETCOREAPP1_0;NETCOREAPP2_0</DefineConstants>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.SqlTools.Hosting\Microsoft.SqlTools.Hosting.csproj" />
<ProjectReference Include="..\Microsoft.SqlTools.ServiceLayer\Microsoft.SqlTools.ServiceLayer.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,63 @@
//
// 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 System.IO;
using Microsoft.SqlTools.Hosting.Utility;
using Microsoft.SqlTools.ServiceLayer.SqlContext;
using Microsoft.SqlTools.Utility;
namespace Microsoft.SqlTools.Serialization
{
/// <summary>
/// Main application class for Serialization Service Host executable
/// </summary>
internal class Program
{
private const string ServiceName = "SqlSerializationService.exe";
/// <summary>
/// Main entry point into the Serialization Service Host
/// </summary>
internal static void Main(string[] args)
{
try
{
// read command-line arguments
CommandOptions commandOptions = new CommandOptions(args, ServiceName);
if (commandOptions.ShouldExit)
{
return;
}
string logFilePath = "serialization";
if (!string.IsNullOrWhiteSpace(commandOptions.LoggingDirectory))
{
logFilePath = Path.Combine(commandOptions.LoggingDirectory, logFilePath);
}
// turn on Verbose logging during early development
// we need to switch to Normal when preparing for public preview
Logger.Initialize(logFilePath: logFilePath, minimumLogLevel: LogLevel.Verbose, isEnabled: commandOptions.EnableLogging);
Logger.Write(LogLevel.Normal, "Starting SqlTools Serialization Provider");
// set up the host details and profile paths
var hostDetails = new HostDetails(
name: "SqlTools Serialization Provider",
profileId: "Microsoft.SqlTools.Serialization",
version: new Version(1, 0));
SqlToolsContext sqlToolsContext = new SqlToolsContext(hostDetails);
UtilityServiceHost serviceHost = HostLoader.CreateAndStartServiceHost(sqlToolsContext);
serviceHost.WaitForExit();
}
catch (Exception e)
{
Logger.Write(LogLevel.Error, string.Format("An unhandled exception occurred: {0}", e));
Environment.Exit(1);
}
}
}
}

View File

@@ -0,0 +1,78 @@
//
// 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 System.Composition;
using System.Threading.Tasks;
using Microsoft.SqlTools.Extensibility;
using Microsoft.SqlTools.Hosting;
using Microsoft.SqlTools.Hosting.Protocol;
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
using Microsoft.SqlTools.Utility;
namespace Microsoft.SqlTools.Serialization
{
/// <summary>
/// Service responsible for securing credentials in a platform-neutral manner. This provides
/// a generic API for read, save and delete credentials
/// </summary>
[Export(typeof(IHostedService))]
public class SerializationService : HostedService<SerializationService>, IComposableService
{
public override void InitializeService(IProtocolEndpoint serviceHost)
{
Logger.Write(LogLevel.Verbose, "Serialization initialized");
// Register request and event handlers with the Service Host
serviceHost.SetRequestHandler(SaveAsRequest.Type, HandleSaveAsRequest);
}
public async Task HandleSaveAsRequest(SaveResultsInfo resultsInfo, RequestContext<SaveResultRequestResult> requestContext)
{
Func<Task<SaveResultRequestResult>> doSave = () =>
{
return SaveAsAsync(resultsInfo, requestContext);
};
await HandleRequest(doSave, requestContext, "HandleSaveAsRequest");
}
public async Task<SaveResultRequestResult> SaveAsAsync(SaveResultsInfo resultsInfo, RequestContext<SaveResultRequestResult> requestContext)
{
// TODO: Refactor currently available serialization code in sqltools to be utilized here
// Issue here: https://github.com/Microsoft/carbon/issues/1789
switch (resultsInfo.SaveFormat) {
case "json":
throw new NotImplementedException("Converting to " + resultsInfo.SaveFormat + " is not implemented.");
break;
case "csv":
throw new NotImplementedException("Converting to " + resultsInfo.SaveFormat + " is not implemented.");
break;
case "excel":
throw new NotImplementedException("Converting to " + resultsInfo.SaveFormat + " is not implemented.");
break;
default:
throw new NotImplementedException("Converting to " + resultsInfo.SaveFormat + " is not implemented.");
}
}
private async Task HandleRequest<T>(Func<Task<T>> handler, RequestContext<T> requestContext, string requestType)
{
Logger.Write(LogLevel.Verbose, requestType);
try
{
T result = await handler();
await requestContext.SendResult(result);
}
catch (Exception ex)
{
await requestContext.SendError(ex.ToString());
}
}
}
}

View File

@@ -3,9 +3,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
using System.Collections.Generic;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlTools.Hosting.Contracts;
using Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts;
using Microsoft.SqlTools.ServiceLayer.DisasterRecovery.RestoreOperation;

View File

@@ -23,7 +23,7 @@ namespace Microsoft.SqlTools.ServiceLayer
try
{
// read command-line arguments
CommandOptions commandOptions = new CommandOptions(args);
ServiceLayerCommandOptions commandOptions = new ServiceLayerCommandOptions(args);
if (commandOptions.ShouldExit)
{
return;

View File

@@ -3,7 +3,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts

View File

@@ -0,0 +1,57 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
{
/// <summary>
/// Class used for storing results and how the results are to be serialized
/// </summary>
public class SaveResultsInfo
{
/// <summary>
/// String representation of the type that service is supposed to serialize to
/// E.g. "json" or "csv"
/// </summary>
public string SaveFormat { get; set; }
/// <summary>
/// Path to file that the serialized results will be stored in
/// </summary>
public string SavePath { get; set; }
/// <summary>
/// Results that are to be serialized into 'SaveFormat' format
/// </summary>
public DbCellValue[][] Rows { get; set; }
/// <summary>
/// Whether the current set of Rows passed in is the last for this file
// </summary>
public bool IsLast { get; set; }
/// <summary>
/// Constructor
/// </summary>
public SaveResultsInfo(string saveFormat,
string savePath,
DbCellValue[][] rows,
bool isLast)
{
this.SaveFormat = saveFormat;
this.SavePath = savePath;
this.Rows = Rows;
this.IsLast = isLast;
}
}
public class SaveAsRequest
{
public static readonly
RequestType<SaveResultsInfo, SaveResultRequestResult> Type =
RequestType<SaveResultsInfo, SaveResultRequestResult>.Create("query/saveAs");
}
}

View File

@@ -3,11 +3,8 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage

View File

@@ -3,12 +3,12 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Xml;
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
{

View File

@@ -4,8 +4,6 @@
//
using System;
using System.Collections.Concurrent;
using System.Data.Common;
using System.Data.SqlClient;
using System.IO;
using System.Threading.Tasks;
using Microsoft.SqlTools.ServiceLayer.Connection;

View File

@@ -0,0 +1,36 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Globalization;
using Microsoft.SqlTools.Hosting.Utility;
namespace Microsoft.SqlTools.ServiceLayer.Utility
{
class ServiceLayerCommandOptions : CommandOptions
{
private const string ServiceLayerServiceName = "MicrosoftSqlToolsServiceLayer.exe";
public ServiceLayerCommandOptions(string[] args) : base(args, ServiceLayerServiceName)
{
}
public override void SetLocale(string locale)
{
try
{
LocaleSetter(locale);
// Setting our internal SR culture to our global culture
SR.Culture = CultureInfo.CurrentCulture;
}
catch (CultureNotFoundException)
{
// Ignore CultureNotFoundException since it only is thrown before Windows 10. Windows 10,
// along with macOS and Linux, pick up the default culture if an invalid locale is passed
// into the CultureInfo constructor.
}
}
}
}

View File

@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlTools.ServiceLayer.TaskServices;
using Microsoft.SqlTools.ServiceLayer.TaskServices;
using Microsoft.SqlTools.ServiceLayer.Utility;
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.TaskServices

View File

@@ -6,7 +6,6 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
using Microsoft.SqlTools.ServiceLayer.Test.Common;
using Xunit;

View File

@@ -3,7 +3,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
using Microsoft.SqlTools.ServiceLayer.Test.Common;
using Moq;
@@ -12,6 +11,7 @@ using System.IO;
using System.IO.Compression;
using System.Text.RegularExpressions;
using System.Xml;
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
using Xunit;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage

View File

@@ -213,7 +213,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ServiceHost
{
string locale = "en";
var args = new string[] { "--locale", locale };
CommandOptions options = new CommandOptions(args);
ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);
Assert.Equal(SR.Culture.Name, options.Locale);
Assert.Equal(options.Locale, locale);
@@ -226,7 +226,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ServiceHost
{
string locale = "es";
var args = new string[] { "--locale", locale };
CommandOptions options = new CommandOptions(args);
ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);
Assert.Equal(SR.Culture.Name, options.Locale);
Assert.Equal(options.Locale, locale);
@@ -242,7 +242,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ServiceHost
{
SR.Culture = null;
var args = new string[] { "" };
CommandOptions options = new CommandOptions(args);
ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);
Assert.Null(SR.Culture);
Assert.Equal(options.Locale, "");

View File

@@ -3,8 +3,8 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlTools.ServiceLayer.Utility;
using System.IO;
using Microsoft.SqlTools.ServiceLayer.Utility;
using Xunit;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
@@ -18,7 +18,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
public void LoggingEnabledWhenFlagProvided()
{
var args = new string[] {"--enable-logging"};
CommandOptions options = new CommandOptions(args);
ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);
Assert.NotNull(options);
Assert.True(options.EnableLogging);
@@ -30,7 +30,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
public void LoggingDisabledWhenFlagNotProvided()
{
var args = new string[] {};
CommandOptions options = new CommandOptions(args);
ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);
Assert.NotNull(options);
Assert.False(options.EnableLogging);
@@ -42,7 +42,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
public void UsageIsShownWhenHelpFlagProvided()
{
var args = new string[] {"--help"};
CommandOptions options = new CommandOptions(args);
ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);
Assert.NotNull(options);
Assert.True(options.ShouldExit);
@@ -53,7 +53,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
public void UsageIsShownWhenBadArgumentsProvided()
{
var args = new string[] {"--unknown-argument", "/bad-argument"};
CommandOptions options = new CommandOptions(args);
ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);
Assert.NotNull(options);
Assert.True(options.ShouldExit);
@@ -64,7 +64,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
public void DefaultValuesAreUsedWhenNoArgumentsAreProvided()
{
var args = new string[] {};
CommandOptions options = new CommandOptions(args);
ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);
Assert.NotNull(options);
Assert.False(options.EnableLogging);
@@ -79,7 +79,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
public void LocaleSetWhenProvided(string locale)
{
var args = new string[] {"--locale", locale};
CommandOptions options = new CommandOptions(args);
ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args); ;
// Asserting all options were properly set
Assert.NotNull(options);
@@ -92,7 +92,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
{
string locale = "invalid";
var args = new string[] { "--locale", locale };
CommandOptions options = new CommandOptions(args);
ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);
// Asserting all options were properly set
Assert.NotNull(options);
@@ -103,7 +103,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
public void LocaleNotSetWhenNotProvided()
{
var args = new string[] {};
CommandOptions options = new CommandOptions(args);
ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);
// Asserting all options were properly set
Assert.NotNull(options);
@@ -117,7 +117,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
{
string logDir = Directory.GetCurrentDirectory();
var args = new string[] { "--log-dir", logDir };
CommandOptions options = new CommandOptions(args);
ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);
// Asserting all options were properly set
Assert.NotNull(options);

View File

@@ -7,8 +7,6 @@ using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Text.RegularExpressions;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.SqlParser.SqlCodeDom;
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
using Microsoft.SqlTools.ServiceLayer.Utility;
using Xunit;