From 60819f28deba6821f465c1cfa5a74288dc4d52b0 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Mon, 17 Jun 2019 10:13:55 -0700 Subject: [PATCH] delete stale code --- ...ellEditorServices.Channel.WebSocket.csproj | 36 ---- .../WebsocketClientChannel.cs | 163 ------------------ .../WebsocketServerChannel.cs | 158 ----------------- ...itorServices.Test.Channel.WebSocket.csproj | 43 ----- .../WebSocketChannelTest.cs | 72 -------- .../app.config | 11 -- 6 files changed, 483 deletions(-) delete mode 100644 src/PowerShellEditorServices.Channel.WebSocket/PowerShellEditorServices.Channel.WebSocket.csproj delete mode 100644 src/PowerShellEditorServices.Channel.WebSocket/WebsocketClientChannel.cs delete mode 100644 src/PowerShellEditorServices.Channel.WebSocket/WebsocketServerChannel.cs delete mode 100644 test/PowerShellEditorServices.Test.Channel.WebSocket/PowerShellEditorServices.Test.Channel.WebSocket.csproj delete mode 100644 test/PowerShellEditorServices.Test.Channel.WebSocket/WebSocketChannelTest.cs delete mode 100644 test/PowerShellEditorServices.Test.Channel.WebSocket/app.config diff --git a/src/PowerShellEditorServices.Channel.WebSocket/PowerShellEditorServices.Channel.WebSocket.csproj b/src/PowerShellEditorServices.Channel.WebSocket/PowerShellEditorServices.Channel.WebSocket.csproj deleted file mode 100644 index 612263d23..000000000 --- a/src/PowerShellEditorServices.Channel.WebSocket/PowerShellEditorServices.Channel.WebSocket.csproj +++ /dev/null @@ -1,36 +0,0 @@ - - - - - PowerShell Editor Services WebSocket Protocol Channel - net452 - Microsoft.PowerShell.EditorServices.Channel.WebSocket - - - - - - - - - - 10.0.3 - - - - - - - - - - - - $(DefineConstants);CoreCLR - - - - - - - diff --git a/src/PowerShellEditorServices.Channel.WebSocket/WebsocketClientChannel.cs b/src/PowerShellEditorServices.Channel.WebSocket/WebsocketClientChannel.cs deleted file mode 100644 index edf2fd52f..000000000 --- a/src/PowerShellEditorServices.Channel.WebSocket/WebsocketClientChannel.cs +++ /dev/null @@ -1,163 +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; -using System.Linq; -using System.Net.WebSockets; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol; -using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.Channel; -using Microsoft.PowerShell.EditorServices.Utility; - -namespace Microsoft.PowerShell.EditorServices.Channel.WebSocket -{ - /// - /// Implementation of that enables WebSocket communication. - /// - public class WebsocketClientChannel : ChannelBase - { - private readonly string serverUrl; - private ClientWebSocket socket; - private ClientWebSocketStream inputStream; - private ClientWebSocketStream outputStream; - - /// - /// Gets the process ID of the server process. - /// - public int ProcessId { get; private set; } - - /// - /// Initializes an instance of the WebsocketClientChannel. - /// - /// The full path to the server process executable. - public WebsocketClientChannel(string url) - { - this.serverUrl = url; - } - - public override async Task WaitForConnectionAsync() - { - try - { - await this.socket.ConnectAsync(new Uri(serverUrl), CancellationToken.None); - } - catch (AggregateException ex) - { - var wsException= ex.InnerExceptions.FirstOrDefault() as WebSocketException; - if (wsException != null) - { - Logger.Write(LogLevel.Warning, - string.Format("Failed to connect to WebSocket server. Error was '{0}'", wsException.Message)); - - } - - throw; - } - - this.IsConnected = true; - } - - protected override void Initialize(IMessageSerializer messageSerializer) - { - this.socket = new ClientWebSocket(); - this.inputStream = new ClientWebSocketStream(socket); - this.outputStream = new ClientWebSocketStream(socket); - - // Set up the message reader and writer - this.MessageReader = - new MessageReader( - this.inputStream, - messageSerializer); - - this.MessageWriter = - new MessageWriter( - this.outputStream, - messageSerializer); - } - - protected override void Shutdown() - { - if (this.MessageReader != null) - { - this.MessageReader = null; - } - - if (this.MessageWriter != null) - { - this.MessageWriter = null; - } - - if (this.socket != null) - { - socket.Dispose(); - } - } - } - - /// - /// Extension of that sends data to a WebSocket during FlushAsync - /// and reads during WriteAsync. - /// - internal class ClientWebSocketStream : MemoryStream - { - private readonly ClientWebSocket socket; - - /// - /// Constructor - /// - /// - /// It is expected that the socket is in an Open state. - /// - /// - public ClientWebSocketStream(ClientWebSocket socket) - { - this.socket = socket; - } - - /// - /// Reads from the WebSocket. - /// - /// - /// - /// - /// - /// - public override async Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) - { - if (socket.State != WebSocketState.Open) - { - return 0; - } - - WebSocketReceiveResult result; - do - { - result = await socket.ReceiveAsync(new ArraySegment(buffer, offset, count), cancellationToken); - } while (!result.EndOfMessage); - - if (result.MessageType == WebSocketMessageType.Close) - { - await socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Closing", cancellationToken); - return 0; - } - - return result.Count; - } - - /// - /// Sends the data in the stream to the buffer and clears the stream. - /// - /// - /// - public override async Task FlushAsync(CancellationToken cancellationToken) - { - await socket.SendAsync(new ArraySegment(ToArray()), WebSocketMessageType.Binary, true, cancellationToken); - SetLength(0); - } - } -} - diff --git a/src/PowerShellEditorServices.Channel.WebSocket/WebsocketServerChannel.cs b/src/PowerShellEditorServices.Channel.WebSocket/WebsocketServerChannel.cs deleted file mode 100644 index c3cb907de..000000000 --- a/src/PowerShellEditorServices.Channel.WebSocket/WebsocketServerChannel.cs +++ /dev/null @@ -1,158 +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; -using System.Linq; -using System.Net.WebSockets; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol; -using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.Channel; -using Microsoft.PowerShell.EditorServices.Protocol.Server; -using Owin.WebSocket; - -namespace Microsoft.PowerShell.EditorServices.Channel.WebSocket -{ - /// - /// Implementation of that implements the streams necessary for - /// communicating via OWIN WebSockets. - /// - public class WebSocketServerChannel : ChannelBase - { - private MemoryStream inStream; - private readonly WebSocketConnection socketConnection; - - public WebSocketServerChannel(WebSocketConnection socket) - { - socketConnection = socket; - } - - protected override void Initialize(IMessageSerializer messageSerializer) - { - inStream = new MemoryStream(); - - // Set up the reader and writer - this.MessageReader = - new MessageReader( - this.inStream, - messageSerializer); - - this.MessageWriter = - new MessageWriter( - new WebSocketStream(socketConnection), - messageSerializer); - } - - /// - /// Dispatches data received during calls to OnMessageReceivedAsync in the class. - /// - /// - /// This method calls an overriden version of the that dispatches messages on - /// demand rather than running on a background thread. - /// - /// - /// - public async Task DispatchAsync(ArraySegment message) - { - //Clear our stream - inStream.SetLength(0); - - //Write data and dispatch to handlers - await inStream.WriteAsync(message.ToArray(), 0, message.Count); - inStream.Position = 0; - } - - protected override void Shutdown() - { - this.socketConnection.Close(WebSocketCloseStatus.NormalClosure, "Server shutting down"); - } - - public override Task WaitForConnectionAsync() - { - // TODO: Need to update behavior here - return Task.FromResult(true); - } - } - - /// - /// Overriden that sends data through a during the FlushAsync call. - /// - /// - /// FlushAsync will send data via the SendBinary method of the class. The memory streams length will - /// then be set to 0 to reset the stream for additional data to be written. - /// - internal class WebSocketStream : MemoryStream - { - private readonly WebSocketConnection _connection; - - public WebSocketStream(WebSocketConnection connection) - { - _connection = connection; - } - - public override async Task FlushAsync(CancellationToken cancellationToken) - { - //Send to client socket and reset stream - await _connection.SendBinary(new ArraySegment(ToArray()), true); - SetLength(0); - } - } - - /// - /// Base class for WebSocket connections that expose editor services. - /// - public abstract class EditorServiceWebSocketConnection : WebSocketConnection - { - protected EditorServiceWebSocketConnection() - { - Channel = new WebSocketServerChannel(this); - } - - protected ProtocolEndpoint Server { get; set; } - - protected WebSocketServerChannel Channel { get; private set; } - - public override void OnOpen() - { - Server.Start(); - } - - public override async Task OnMessageReceivedAsync(ArraySegment message, WebSocketMessageType type) - { - await Channel.DispatchAsync(message); - } - - public override Task OnCloseAsync(WebSocketCloseStatus? closeStatus, string closeStatusDescription) - { - Server.Stop(); - - return base.OnCloseAsync(closeStatus, closeStatusDescription); - } - } - - /// - /// Web socket connections that expose the . - /// - public class LanguageServerWebSocketConnection : EditorServiceWebSocketConnection - { - public LanguageServerWebSocketConnection() - { - Server = new LanguageServer(null, null, Channel); - } - } - - /// - /// Web socket connections that expose the . - /// - public class DebugAdapterWebSocketConnection : EditorServiceWebSocketConnection - { - public DebugAdapterWebSocketConnection() - { - Server = new DebugAdapter(null, null, Channel, null); - } - } -} - diff --git a/test/PowerShellEditorServices.Test.Channel.WebSocket/PowerShellEditorServices.Test.Channel.WebSocket.csproj b/test/PowerShellEditorServices.Test.Channel.WebSocket/PowerShellEditorServices.Test.Channel.WebSocket.csproj deleted file mode 100644 index 70f5ae7e7..000000000 --- a/test/PowerShellEditorServices.Test.Channel.WebSocket/PowerShellEditorServices.Test.Channel.WebSocket.csproj +++ /dev/null @@ -1,43 +0,0 @@ - - - - - net452 - Microsoft.PowerShell.EditorServices.Test.Channel.WebSocket - $(PackageTargetFallback);dnxcore50;portable-net45+win8 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - $(DefineConstants);CoreCLR - - - - - - - diff --git a/test/PowerShellEditorServices.Test.Channel.WebSocket/WebSocketChannelTest.cs b/test/PowerShellEditorServices.Test.Channel.WebSocket/WebSocketChannelTest.cs deleted file mode 100644 index bfc74168d..000000000 --- a/test/PowerShellEditorServices.Test.Channel.WebSocket/WebSocketChannelTest.cs +++ /dev/null @@ -1,72 +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.Threading.Tasks; -using Microsoft.Owin.Hosting; -using Microsoft.PowerShell.EditorServices.Protocol.Client; -using Microsoft.PowerShell.EditorServices.Protocol.LanguageServer; -using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol; -using Owin; -using Owin.WebSocket.Extensions; -using Xunit; -using Microsoft.PowerShell.EditorServices.Channel.WebSocket; - -namespace Microsoft.PowerShell.EditorServices.Test.Channel.WebSocket -{ - public class WebSocketChannelTest : IAsyncLifetime - { - private IDisposable webapp; - private LanguageServiceClient languageServiceClient; - - public async Task InitializeAsync() - { - webapp = WebApp.Start("http://localhost:9999"); - - this.languageServiceClient = - new LanguageServiceClient( - new WebsocketClientChannel("ws://localhost:9999/language")); - - await this.languageServiceClient.Start(); - } - - public Task DisposeAsync() - { - webapp.Dispose(); - return Task.Delay(0); - } - - [Fact(Skip = "Disabling WebSocket test until the channel implementation is refactored.")] - public async Task ServiceCommunicatesOverWebsockets() - { - string expandedText = - await this.SendRequest( - ExpandAliasRequest.Type, - "gci\r\npwd"); - - Assert.Equal("Get-ChildItem\r\nGet-Location", expandedText); - } - - private Task SendRequest( - RequestType requestType, - TParams requestParams) - { - return - this.languageServiceClient.SendRequest( - requestType, - requestParams); - } - } - - public class Startup - { - public void Configuration(IAppBuilder app) - { - app.MapWebSocketRoute("/language"); - app.MapWebSocketRoute("/debug"); - } - } -} - diff --git a/test/PowerShellEditorServices.Test.Channel.WebSocket/app.config b/test/PowerShellEditorServices.Test.Channel.WebSocket/app.config deleted file mode 100644 index 2fa674d47..000000000 --- a/test/PowerShellEditorServices.Test.Channel.WebSocket/app.config +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file