From 4f67fc4aefc11c1a4293227c70de922dbe03c652 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Thu, 7 Mar 2013 00:34:00 -0500 Subject: removed base kernel and ikernel --- .../WebSocket/AlchemyServer.cs | 113 ------------------ .../WebSocket/AlchemyWebSocket.cs | 132 --------------------- 2 files changed, 245 deletions(-) delete mode 100644 MediaBrowser.Common.Implementations/WebSocket/AlchemyServer.cs delete mode 100644 MediaBrowser.Common.Implementations/WebSocket/AlchemyWebSocket.cs (limited to 'MediaBrowser.Common.Implementations/WebSocket') diff --git a/MediaBrowser.Common.Implementations/WebSocket/AlchemyServer.cs b/MediaBrowser.Common.Implementations/WebSocket/AlchemyServer.cs deleted file mode 100644 index 236bd27b7..000000000 --- a/MediaBrowser.Common.Implementations/WebSocket/AlchemyServer.cs +++ /dev/null @@ -1,113 +0,0 @@ -using Alchemy; -using Alchemy.Classes; -using MediaBrowser.Common.Net; -using MediaBrowser.Model.Logging; -using System; -using System.Net; - -namespace MediaBrowser.Common.Implementations.WebSocket -{ - /// - /// Class AlchemyServer - /// - public class AlchemyServer : IWebSocketServer - { - /// - /// Occurs when [web socket connected]. - /// - public event EventHandler WebSocketConnected; - - /// - /// Gets or sets the web socket server. - /// - /// The web socket server. - private WebSocketServer WebSocketServer { get; set; } - - /// - /// The _logger - /// - private readonly ILogger _logger; - - /// - /// Initializes a new instance of the class. - /// - /// The logger. - /// logger - public AlchemyServer(ILogger logger) - { - if (logger == null) - { - throw new ArgumentNullException("logger"); - } - _logger = logger; - } - - /// - /// Gets the port. - /// - /// The port. - public int Port { get; private set; } - - /// - /// Starts the specified port number. - /// - /// The port number. - public void Start(int portNumber) - { - WebSocketServer = new WebSocketServer(portNumber, IPAddress.Any) - { - OnConnected = OnAlchemyWebSocketClientConnected, - TimeOut = TimeSpan.FromMinutes(60) - }; - - WebSocketServer.Start(); - - Port = portNumber; - - _logger.Info("Alchemy Web Socket Server started"); - } - - /// - /// Called when [alchemy web socket client connected]. - /// - /// The context. - private void OnAlchemyWebSocketClientConnected(UserContext context) - { - if (WebSocketConnected != null) - { - var socket = new AlchemyWebSocket(context, _logger); - - WebSocketConnected(this, new WebSocketConnectEventArgs - { - WebSocket = socket, - Endpoint = context.ClientAddress.ToString() - }); - } - } - - /// - /// Stops this instance. - /// - public void Stop() - { - } - - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - /// - /// Releases unmanaged and - optionally - managed resources. - /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected virtual void Dispose(bool dispose) - { - - } - } -} diff --git a/MediaBrowser.Common.Implementations/WebSocket/AlchemyWebSocket.cs b/MediaBrowser.Common.Implementations/WebSocket/AlchemyWebSocket.cs deleted file mode 100644 index 1ecc38f2c..000000000 --- a/MediaBrowser.Common.Implementations/WebSocket/AlchemyWebSocket.cs +++ /dev/null @@ -1,132 +0,0 @@ -using Alchemy.Classes; -using MediaBrowser.Common.Net; -using MediaBrowser.Model.Logging; -using System; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.Common.Implementations.WebSocket -{ - /// - /// Class AlchemyWebSocket - /// - public class AlchemyWebSocket : IWebSocket - { - /// - /// The logger - /// - private readonly ILogger _logger; - - /// - /// Gets or sets the web socket. - /// - /// The web socket. - private UserContext UserContext { get; set; } - - /// - /// Initializes a new instance of the class. - /// - /// The context. - /// The logger. - /// context - public AlchemyWebSocket(UserContext context, ILogger logger) - { - if (context == null) - { - throw new ArgumentNullException("context"); - } - - _logger = logger; - UserContext = context; - - context.SetOnDisconnect(OnDisconnected); - context.SetOnReceive(OnReceive); - - _logger.Info("Client connected from {0}", context.ClientAddress); - } - - /// - /// The _disconnected - /// - private bool _disconnected = false; - /// - /// Gets or sets the state. - /// - /// The state. - public WebSocketState State - { - get { return _disconnected ? WebSocketState.Closed : WebSocketState.Open; } - } - - /// - /// Called when [disconnected]. - /// - /// The context. - private void OnDisconnected(UserContext context) - { - _disconnected = true; - } - - /// - /// Called when [receive]. - /// - /// The context. - private void OnReceive(UserContext context) - { - if (OnReceiveDelegate != null) - { - var json = context.DataFrame.ToString(); - - if (!string.IsNullOrWhiteSpace(json)) - { - try - { - var bytes = Encoding.UTF8.GetBytes(json); - - OnReceiveDelegate(bytes); - } - catch (Exception ex) - { - _logger.ErrorException("Error processing web socket message", ex); - } - } - } - } - - /// - /// Sends the async. - /// - /// The bytes. - /// The type. - /// if set to true [end of message]. - /// The cancellation token. - /// Task. - public Task SendAsync(byte[] bytes, WebSocketMessageType type, bool endOfMessage, CancellationToken cancellationToken) - { - return Task.Run(() => UserContext.Send(bytes)); - } - - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - public void Dispose() - { - Dispose(true); - } - - /// - /// Releases unmanaged and - optionally - managed resources. - /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected virtual void Dispose(bool dispose) - { - } - - /// - /// Gets or sets the receive action. - /// - /// The receive action. - public Action OnReceiveDelegate { get; set; } - } -} -- cgit v1.2.3