mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-13 03:28:37 -05:00
Move unused forked code to external directory (#1192)
* Move unused forked code to external directory * Fix SLN build errors * Add back resource provider core since it's referenced by main resource provider project * Update PackageProjects step of pipeline
This commit is contained in:
58
external/Microsoft.SqlTools.Hosting.v2/Channels/ChannelBase.cs
vendored
Normal file
58
external/Microsoft.SqlTools.Hosting.v2/Channels/ChannelBase.cs
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.Hosting.Protocol;
|
||||
|
||||
namespace Microsoft.SqlTools.Hosting.Channels
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a base implementation for servers and their clients over a
|
||||
/// single kind of communication channel.
|
||||
/// </summary>
|
||||
public abstract class ChannelBase
|
||||
{
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets a boolean that is true if the channel is connected or false if not.
|
||||
/// </summary>
|
||||
public bool IsConnected { get; protected internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the MessageReader for reading messages from the channel.
|
||||
/// </summary>
|
||||
public MessageReader MessageReader { get; protected internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the MessageWriter for writing messages to the channel.
|
||||
/// </summary>
|
||||
public MessageWriter MessageWriter { get; protected internal set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Abstract Methods
|
||||
|
||||
/// <summary>
|
||||
/// Starts the channel and initializes the MessageDispatcher.
|
||||
/// </summary>
|
||||
public abstract void Start();
|
||||
|
||||
/// <summary>
|
||||
/// Stops the channel.
|
||||
/// </summary>
|
||||
public abstract void Stop();
|
||||
|
||||
/// <summary>
|
||||
/// Returns a Task that allows the consumer of the ChannelBase
|
||||
/// implementation to wait until a connection has been made to
|
||||
/// the opposite endpoint whether it's a client or server.
|
||||
/// </summary>
|
||||
/// <returns>A Task to be awaited until a connection is made.</returns>
|
||||
public abstract Task WaitForConnection();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
111
external/Microsoft.SqlTools.Hosting.v2/Channels/StdioClientChannel.cs
vendored
Normal file
111
external/Microsoft.SqlTools.Hosting.v2/Channels/StdioClientChannel.cs
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
//
|
||||
// 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;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.Hosting.Protocol;
|
||||
|
||||
namespace Microsoft.SqlTools.Hosting.Channels
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides a client implementation for the standard I/O channel.
|
||||
/// Launches the server process and then attaches to its console
|
||||
/// streams.
|
||||
/// </summary>
|
||||
public class StdioClientChannel : ChannelBase
|
||||
{
|
||||
private readonly string serviceProcessPath;
|
||||
private readonly string serviceProcessArguments;
|
||||
|
||||
private Stream inputStream;
|
||||
private Stream outputStream;
|
||||
private Process serviceProcess;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes an instance of the StdioClient.
|
||||
/// </summary>
|
||||
/// <param name="serverProcessPath">The full path to the server process executable.</param>
|
||||
/// <param name="serverProcessArguments">Optional arguments to pass to the service process executable.</param>
|
||||
public StdioClientChannel(string serverProcessPath, params string[] serverProcessArguments)
|
||||
{
|
||||
serviceProcessPath = serverProcessPath;
|
||||
|
||||
if (serverProcessArguments != null)
|
||||
{
|
||||
serviceProcessArguments = string.Join(" ", serverProcessArguments);
|
||||
}
|
||||
}
|
||||
|
||||
public int ProcessId { get; private set; }
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
serviceProcess = new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = serviceProcessPath,
|
||||
Arguments = serviceProcessArguments,
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardInput = true,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
StandardOutputEncoding = Encoding.UTF8
|
||||
},
|
||||
EnableRaisingEvents = true
|
||||
};
|
||||
|
||||
// Start the process
|
||||
serviceProcess.Start();
|
||||
ProcessId = serviceProcess.Id;
|
||||
|
||||
// Open the standard input/output streams
|
||||
inputStream = serviceProcess.StandardOutput.BaseStream;
|
||||
outputStream = serviceProcess.StandardInput.BaseStream;
|
||||
|
||||
// Set up the message reader and writer
|
||||
MessageReader = new MessageReader(inputStream);
|
||||
MessageWriter = new MessageWriter(outputStream);
|
||||
|
||||
IsConnected = true;
|
||||
}
|
||||
|
||||
public override Task WaitForConnection()
|
||||
{
|
||||
// We're always connected immediately in the stdio channel
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
public override void Stop()
|
||||
{
|
||||
if (inputStream != null)
|
||||
{
|
||||
inputStream.Dispose();
|
||||
inputStream = null;
|
||||
}
|
||||
|
||||
if (outputStream != null)
|
||||
{
|
||||
outputStream.Dispose();
|
||||
outputStream = null;
|
||||
}
|
||||
|
||||
if (MessageReader != null)
|
||||
{
|
||||
MessageReader = null;
|
||||
}
|
||||
|
||||
if (MessageWriter != null)
|
||||
{
|
||||
MessageWriter = null;
|
||||
}
|
||||
|
||||
serviceProcess.Kill();
|
||||
}
|
||||
}
|
||||
}
|
||||
54
external/Microsoft.SqlTools.Hosting.v2/Channels/StdioServerChannel.cs
vendored
Normal file
54
external/Microsoft.SqlTools.Hosting.v2/Channels/StdioServerChannel.cs
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.Hosting.Protocol;
|
||||
|
||||
namespace Microsoft.SqlTools.Hosting.Channels
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides a server implementation for the standard I/O channel.
|
||||
/// When started in a process, attaches to the console I/O streams
|
||||
/// to communicate with the client that launched the process.
|
||||
/// </summary>
|
||||
public class StdioServerChannel : ChannelBase
|
||||
{
|
||||
private Stream inputStream;
|
||||
private Stream outputStream;
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
#if !NanoServer
|
||||
// Ensure that the console is using UTF-8 encoding
|
||||
System.Console.InputEncoding = Encoding.UTF8;
|
||||
System.Console.OutputEncoding = Encoding.UTF8;
|
||||
#endif
|
||||
|
||||
// Open the standard input/output streams
|
||||
inputStream = System.Console.OpenStandardInput();
|
||||
outputStream = System.Console.OpenStandardOutput();
|
||||
|
||||
// Set up the reader and writer
|
||||
MessageReader = new MessageReader(inputStream);
|
||||
MessageWriter = new MessageWriter(outputStream);
|
||||
|
||||
IsConnected = true;
|
||||
}
|
||||
|
||||
public override void Stop()
|
||||
{
|
||||
// No default implementation needed, streams will be
|
||||
// disposed on process shutdown.
|
||||
}
|
||||
|
||||
public override Task WaitForConnection()
|
||||
{
|
||||
// We're always connected immediately in the stdio channel
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user