예제 #1
0
 private void StopStreaming()
 {
     StreamManifest.Dispose();
     StreamManifest = null;
     buffer         = null;
     TerminalConnection?.Unsuspend();
 }
예제 #2
0
 /// <inheritdoc />
 public void StreamResult(ISerializedResult result, int messageSize, TimeSpan?timeElapsed = null, bool writeHeaders = false,
                          bool disposeResult = true)
 {
     if (result == null)
     {
         throw new ArgumentNullException(nameof(result));
     }
     if (!result.IsSerialized)
     {
         result = result.Serialize();
     }
     if (!(result is Content content) || !(content.Body?.Length > 0))
     {
         SendResult(result, result.TimeElapsed, writeHeaders, disposeResult);
         return;
     }
     if (content.IsLocked)
     {
         throw new InvalidOperationException("Unable to stream a result that is already assigned to a different streaming " +
                                             "job. A result can only be streamed once.");
     }
     content.IsLocked = true;
     TerminalConnection?.Suspend();
     if (messageSize < MinStreamBufferSize)
     {
         messageSize = MinStreamBufferSize;
     }
     else if (MaxStreamBufferSize < messageSize)
     {
         messageSize = MaxStreamBufferSize;
     }
     StreamManifest?.Dispose();
     StreamManifest = new StreamManifest(content, messageSize);
     SendJson(StreamManifest);
     buffer = null;
 }
예제 #3
0
        /// <inheritdoc />
        /// <summary>
        /// Disposes the WebSocket. Same as Disconnect()
        /// </summary>
        public void Dispose()
        {
            if (disposed)
            {
                return;
            }
            Status = WebSocketStatus.PendingClose;
            StreamManifest?.Dispose();
            StreamManifest = null;
            var terminalName = TerminalConnection?.Resource?.Name;

            ReleaseTerminal();
            if (IsConnected)
            {
                DisconnectWebSocket(DisconnectMessage);
            }
            Status = WebSocketStatus.Closed;
            Closed = DateTime.Now;
            if (terminalName != Console.TypeName)
            {
                Console.Log(new WebSocketEvent(MessageType.WebSocketClose, this));
            }
            disposed = true;
        }