private void SaveDataFrame(Http2Stream stream, DataFrame dataFrame) { lock (_writeLock) { string originalPath = stream.Headers.GetValue(":path".ToLower()); //If user sets the empty file in get command we return notFound webpage string fileName = string.IsNullOrEmpty(Path.GetFileName(originalPath)) ? NotFound : Path.GetFileName(originalPath); string path = Path.Combine(AssemblyPath, fileName); try { _fileHelper.SaveToFile(dataFrame.Data.Array, dataFrame.Data.Offset, dataFrame.Data.Count, path, stream.ReceivedDataAmount != 0); } catch (IOException) { Http2Logger.LogError("File is still downloading. Repeat request later"); stream.WriteDataFrame(new byte[0], true); stream.Dispose(); } stream.ReceivedDataAmount += dataFrame.FrameLength; if (dataFrame.IsEndStream) { if (!stream.EndStreamSent) { //send terminator stream.WriteDataFrame(new byte[0], true); Http2Logger.LogConsole("Terminator was sent"); } _fileHelper.RemoveStream(path); Http2Logger.LogConsole("Bytes received " + stream.ReceivedDataAmount); #if DEBUG const string wayToServerRoot1 = @"..\..\..\..\..\Drop\Root"; const string wayToServerRoot2 = @".\Root"; var areFilesEqual = _fileHelper.CompareFiles(path, wayToServerRoot1 + originalPath) || _fileHelper.CompareFiles(path, wayToServerRoot2 + originalPath); if (!areFilesEqual) { Console.ForegroundColor = ConsoleColor.Red; Http2Logger.LogError("Files are NOT EQUAL!"); } else { Console.ForegroundColor = ConsoleColor.Green; Http2Logger.LogConsole("Files are EQUAL!"); } Console.ForegroundColor = ConsoleColor.Gray; #endif } } }
protected override void Dispose(bool disposing) { if (Interlocked.Exchange(ref _disposed, 1) != 0) { return; } if (disposing) { Debug.Assert(_http2Stream != null); _http2Stream.Dispose(); } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { Http2Stream http2Stream = Interlocked.Exchange(ref _http2Stream, null); if (http2Stream == null) { return; } if (disposing) { http2Stream.Dispose(); } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { Http2Stream http2Stream = Interlocked.Exchange(ref _http2Stream, null); if (http2Stream == null) { return; } if (disposing) { if (http2Stream._state != StreamState.Aborted && http2Stream._state != StreamState.Complete) { // If we abort response stream before endOfStream, let server know. IgnoreExceptions(http2Stream._connection.SendRstStreamAsync(http2Stream._streamId, Http2ProtocolErrorCode.Cancel)); } http2Stream.Dispose(); } base.Dispose(disposing); }
private void SaveDataFrame(Http2Stream stream, DataFrame dataFrame) { lock (_writeLock) { string path = stream.Headers.GetValue(":path".ToLower()); try { string pathToSave = AssemblyPath + Root + path; if (!Directory.Exists(Path.GetDirectoryName(pathToSave))) { throw new DirectoryNotFoundException("Access denied"); } _fileHelper.SaveToFile(dataFrame.Data.Array, dataFrame.Data.Offset, dataFrame.Data.Count, pathToSave, stream.ReceivedDataAmount != 0); } catch (Exception ex) { Http2Logger.LogError(ex.Message); stream.WriteDataFrame(new byte[0], true); stream.Dispose(); } stream.ReceivedDataAmount += dataFrame.FrameLength; if (dataFrame.IsEndStream) { if (!stream.EndStreamSent) { //send terminator stream.WriteDataFrame(new byte[0], true); Http2Logger.LogDebug("Terminator was sent"); } _fileHelper.RemoveStream(AssemblyPath + Root + path); } } }