mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-15 17:23:32 -05:00
* 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
79 lines
3.0 KiB
C#
79 lines
3.0 KiB
C#
//
|
|
// 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());
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|