/// <summary> /// Builds the data frame. /// </summary> /// <param name="stream">The stream.</param> /// <param name="data">The data.</param> /// <param name="final">if set to <c>true</c> than this frame is final for the stream.</param> /// <returns>returns DataFrame.</returns> public DataFrame BuildDataFrame(SMStream stream, SMData data, bool final) { DataFrame frame = BuildDataFrame(stream.StreamId, data); frame.IsFinal = final; return(frame); }
/// <summary> /// Attached to events on stream. /// </summary> /// <param name="stream">Stream.</param> private static void AttachStreamEvents(SMStream stream) { stream.OnRSTReceived += (s, e) => { _isError = true; _errorMessage = e.Reason.ToString(); _eventRaisedStream.Set(); }; stream.OnDataReceived += (s, e) => { string file = Path.GetFileName(e.Stream.Headers[SMHeaders.Path]); using (var fs = new FileStream(file, FileMode.Create)) { fs.Write(e.Data.Data, 0, e.Data.Data.Length); } string text = e.Data.AsUtf8Text(); _isReceived = !string.IsNullOrEmpty(text); if (_isClose) { _eventRaisedStream.Set(); } }; stream.OnClose += (s, e) => { _isClose = true; if (_isReceived) { _eventRaisedStream.Set(); } }; }
public void SendHeaderWithoutCompressSuccessful() { Reset(); Uri uri; Uri.TryCreate(Host + Port, UriKind.Absolute, out uri); _options.CoompressionIsStateful = false; CreateSession(uri); AttachSessionEvents(_session); _eventRaisedSession.WaitOne(); _eventRaisedSession.Reset(); Check(CheckModes.session); _eventRaisedStream.Reset(); string fileName = FileName; bool isFin = true; SMStream stream = DownloadPath(fileName, isFin); AttachStreamEvents(stream); _eventRaisedStream.WaitOne(); _eventRaisedStream.Reset(); Check(CheckModes.stream); _eventRaisedStream.Reset(); _eventRaisedStream.WaitOne(); Check(CheckModes.fin); if ((stream.State == SMStreamState.Closed) ^ isFin) { Assert.Fail("Incorrect SMStreamState."); } }
public CreditUpdateFrame BuildCreditUpdateFrame(SMStream stream, Int64 creditAddition) { CreditUpdateFrame frame = new CreditUpdateFrame(stream.StreamId, creditAddition); frame.IsFinal = true; return(frame); }
/// <summary> /// Builds the headers frame. /// </summary> /// <param name="stream">The stream.</param> /// <param name="headers">The headers.</param> /// <param name="final">if set to <c>true</c> than this frame is final for the stream.</param> /// <returns>Headers frame.</returns> public ControlFrame BuildHeadersFrame(SMStream stream, SMHeaders headers, bool final) { ControlFrame frame = BuildControlFrame(FrameType.Headers, stream, headers); frame.IsFinal = final; return(frame); }
public void ConnectionOpenAndTextDataReceivedSuccessful() { Reset(); Uri uri; Uri.TryCreate(Host + Port, UriKind.Absolute, out uri); CreateSession(uri); AttachSessionEvents(_session); _eventRaisedSession.WaitOne(); _eventRaisedSession.Reset(); Check(CheckModes.session); string fileName = FileName; bool isFin = true; SMStream stream = DownloadPath(fileName, isFin); _eventRaisedStream.WaitOne(); _eventRaisedStream.Reset(); Check(CheckModes.stream); if ((stream.State == SMStreamState.HalfClosed) ^ isFin) { Assert.Fail("Incorrect SMStreamState."); } AttachStreamEvents(stream); _eventRaisedStream.WaitOne(); _eventRaisedStream.Reset(); Check(CheckModes.fin); if ((stream.State == SMStreamState.Closed) ^ isFin) { Assert.Fail("Incorrect SMStreamState."); } }
public void IncorrectFileNameFailure() { Reset(); Uri uri; Uri.TryCreate(Host + Port, UriKind.Absolute, out uri); CreateSession(uri); AttachSessionEvents(_session); _eventRaisedSession.WaitOne(); _eventRaisedSession.Reset(); Check(CheckModes.session); Guid guid = Guid.NewGuid(); string fileName = guid + FileName; bool isFin = false; SMStream stream = DownloadPath(fileName, isFin); _eventRaisedStream.WaitOne(); _eventRaisedStream.Reset(); Check(CheckModes.stream); if ((stream.State == SMStreamState.HalfClosed) ^ isFin) { Assert.Fail("Incorrect SMStreamState."); } AttachStreamEvents(stream); _eventRaisedStream.WaitOne(); _eventRaisedStream.Reset(); Assert.True(_errorMessage == "InternalError"); }
/// <summary> /// Builds the SYN_STREAM frame. /// </summary> /// <param name="stream">The stream.</param> /// <param name="headers">The headers.</param> /// <param name="final">Indicates that stream is not going to send any more data.</param> /// <returns>SYN_STREAM frame.</returns> public ControlFrame BuildSynStreamFrame(SMStream stream, SMHeaders headers, bool final) { ControlFrame frame = BuildControlFrame(FrameType.SynStream, stream, headers); frame.Priority = SYNStreamPriority; frame.IsFinal = final; return(frame); }
/// <summary> /// Builds the control frame. /// </summary> /// <param name="type">The frame type.</param> /// <param name="stream">The SM stream object.</param> /// <param name="headers">The headers.</param> /// <returns>Returns Control frame object.</returns> private static ControlFrame BuildControlFrame(FrameType type, SMStream stream, SMHeaders headers) { ControlFrame frame = new ControlFrame(headers); frame.StreamId = stream.StreamId; frame.Type = type; frame.Priority = ControlPriority; return(frame); }
/// <summary> /// Builds the RST Frame. /// </summary> /// <param name="stream">The stream.</param> /// <param name="reason">The reason for RST.</param> /// <returns>RST frame.</returns> public ControlFrame BuildRSTFrame(SMStream stream, StatusCode reason) { ControlFrame frame = new ControlFrame(); frame.StreamId = stream.StreamId; frame.Type = FrameType.RTS; frame.StatusCode = reason; frame.Priority = RSTPriority; return(frame); }
public void ManyConnectionOpenAndTextDataReceivedSuccessfully() { Reset(); int numberSessions = Convert.ToInt32(CountSession); int numberStreams = Convert.ToInt32(CountStream); Uri uri; Uri.TryCreate(Host + Port, UriKind.Absolute, out uri); _sessions = new List <SMSession>(numberSessions); string fileName = FileName; for (int i = 0; i < numberSessions; i++) { Reset(); SMSession newSession = CreateSession(uri); AttachSessionEvents(newSession); _eventRaisedSession.WaitOne(); _eventRaisedSession.Reset(); Check(CheckModes.session); for (int j = 0; j < numberStreams; j++) { Reset(); bool isFin = true; SMStream stream = DownloadPathForList(fileName, ref newSession, isFin); _eventRaisedStream.WaitOne(); _eventRaisedStream.Reset(); Check(CheckModes.stream); if ((stream.State == SMStreamState.HalfClosed) ^ isFin) { Assert.Fail("Incorrect SMStreamState."); } AttachStreamEvents(stream); _eventRaisedStream.WaitOne(); _eventRaisedStream.Reset(); Check(CheckModes.fin); if ((stream.State == SMStreamState.Closed) ^ isFin) { Assert.Fail("Incorrect SMStreamState."); } } _sessions.Add(newSession); } Assert.Pass(); }
public void SendFrameOnCloseStreamFailure() { Reset(); Uri uri; Uri.TryCreate(Host + Port, UriKind.Absolute, out uri); CreateSession(uri); AttachSessionEvents(_session); _eventRaisedSession.WaitOne(); _eventRaisedSession.Reset(); Check(CheckModes.session); string fileName = FileName; bool isFin = true; SMStream stream = DownloadPath(fileName, isFin); _eventRaisedStream.WaitOne(); _eventRaisedStream.Reset(); Check(CheckModes.stream); if ((stream.State == SMStreamState.HalfClosed) ^ isFin) { Assert.Fail("Incorrect SMStreamState."); } AttachStreamEvents(stream); _eventRaisedStream.Reset(); _eventRaisedStream.WaitOne(); Check(CheckModes.fin); if ((stream.State == SMStreamState.Closed) ^ isFin) { Assert.Fail("Incorrect value Stream.State."); } _isError = false; SMData data = new SMData(new byte[] { 12, 3, 23, 35, 3, 11 }); stream.SendData(data, isFin); _eventRaisedSession.WaitOne(); _eventRaisedSession.Reset(); Assert.IsTrue(_isError); }
public void ConnectionOpenAndCheckControlFrameSuccessful() { Reset(); Uri uri; Uri.TryCreate(Host + Port, UriKind.Absolute, out uri); CreateSession(uri); AttachSessionEvents(_session); _eventRaisedSession.WaitOne(); _eventRaisedSession.Reset(); Check(CheckModes.session); SMProtocol smProtocol = _session.Protocol; AttachProtocolEvents(smProtocol); string fileName = FileName; bool isFin = true; SMStream stream = DownloadPath(fileName, isFin); _eventRaisedStream.WaitOne(); _eventRaisedStream.Reset(); Check(CheckModes.stream); if ((stream.State == SMStreamState.HalfClosed) ^ isFin) { Assert.Fail("Incorrect SMStreamState."); } AttachStreamEvents(stream); _eventRaisedStream.WaitOne(); _eventRaisedStream.Reset(); Check(CheckModes.fin); if ((stream.State == SMStreamState.Closed) ^ isFin) { Assert.Fail("Incorrect value Stream.State."); } _eventRaisedSmProtocol.WaitOne(); Assert.Pass(); }
/// <summary> /// Builds the data frame. /// </summary> /// <param name="stream">The stream.</param> /// <param name="data">The data.</param> /// <returns>Returns DataFrame.</returns> public DataFrame BuildDataFrame(SMStream stream, SMData data) { return(this.BuildDataFrame(stream, data, false)); }
/// <summary> /// Initializes a new instance of the <see cref="HeadersEventArgs"/> class. /// </summary> /// <param name="stream">The stream.</param> /// <param name="headers">The headers.</param> public HeadersEventArgs(SMStream stream, SMHeaders headers) : base(stream) { this.Headers = headers; }
/// <summary> /// Initializes a new instance of the <see cref="StreamDataEventArgs"/> class. /// </summary> /// <param name="stream">The stream.</param> /// <param name="data">The data.</param> /// <param name="isFin">final flag.</param> public StreamDataEventArgs(SMStream stream, SMData data, bool isFin) : base(stream) { this.Data = data; this.IsFin = isFin; }
/// <summary> /// Initializes a new instance of the <see cref="StreamErrorEventArgs"/> class. /// </summary> /// <param name="stream">The stream.</param> /// <param name="exeption">The exeption.</param> public StreamErrorEventArgs(SMStream stream, Exception exeption) : base(stream) { this.Exeption = exeption; }
/// <summary> /// Builds the headers frame. /// </summary> /// <param name="stream">The stream.</param> /// <param name="headers">The headers.</param> /// <param name="final">if set to <c>true</c> than this frame is final for the stream.</param> /// <returns>Headers frame.</returns> public ControlFrame BuildHeadersFrame(SMStream stream, SMHeaders headers, bool final) { ControlFrame frame = BuildControlFrame(FrameType.Headers, stream, headers); frame.IsFinal = final; return frame; }
/// <summary> /// Initializes a new instance of the <see cref="RSTEventArgs"/> class. /// </summary> /// <param name="stream">The stream.</param> /// <param name="reason">The reason for RST.</param> public RSTEventArgs(SMStream stream, StatusCode reason) : base(stream) { this.Reason = reason; }
/// <summary> /// Builds the data frame. /// </summary> /// <param name="stream">The stream.</param> /// <param name="data">The data.</param> /// <param name="final">if set to <c>true</c> than this frame is final for the stream.</param> /// <returns>returns DataFrame.</returns> public DataFrame BuildDataFrame(SMStream stream, SMData data, bool final) { DataFrame frame = BuildDataFrame(stream.StreamId, data); frame.IsFinal = final; return frame; }
/// <summary> /// Builds the control frame. /// </summary> /// <param name="type">The frame type.</param> /// <param name="stream">The SM stream object.</param> /// <param name="headers">The headers.</param> /// <returns>Returns Control frame object.</returns> private static ControlFrame BuildControlFrame(FrameType type, SMStream stream, SMHeaders headers) { ControlFrame frame = new ControlFrame(headers); frame.StreamId = stream.StreamId; frame.Type = type; frame.Priority = ControlPriority; return frame; }
/// <summary> /// Builds the SYN_STREAM frame. /// </summary> /// <param name="stream">The stream.</param> /// <param name="headers">The headers.</param> /// <param name="final">Indicates that stream is not going to send any more data.</param> /// <returns>SYN_STREAM frame.</returns> public ControlFrame BuildSynStreamFrame(SMStream stream, SMHeaders headers, bool final) { ControlFrame frame = BuildControlFrame(FrameType.SynStream, stream, headers); frame.Priority = SYNStreamPriority; frame.IsFinal = final; return frame; }
public CreditUpdateFrame BuildCreditUpdateFrame(SMStream stream, Int64 creditAddition) { CreditUpdateFrame frame = new CreditUpdateFrame(stream.StreamId,creditAddition); frame.IsFinal = true; return frame; }
/// <summary> /// Builds the SYN_REPLY frame. /// </summary> /// <param name="stream">The stream.</param> /// <param name="headers">The headers.</param> /// <returns>SYN_REPLY frame.</returns> public ControlFrame BuildSynReplyFrame(SMStream stream, SMHeaders headers) { return(BuildControlFrame(FrameType.SynReply, stream, headers)); }
/// <summary> /// Builds the data frame. /// </summary> /// <param name="stream">The stream.</param> /// <param name="data">The data.</param> /// <returns>Returns DataFrame.</returns> public DataFrame BuildDataFrame(SMStream stream, SMData data) { return this.BuildDataFrame(stream, data, false); }
/// <summary> /// Initializes a new instance of the <see cref="StreamEventArgs"/> class. /// </summary> /// <param name="stream">The stream.</param> public StreamEventArgs(SMStream stream) { this.Stream = stream; }
/// <summary> /// Builds the RST Frame. /// </summary> /// <param name="stream">The stream.</param> /// <param name="reason">The reason for RST.</param> /// <returns>RST frame.</returns> public ControlFrame BuildRSTFrame(SMStream stream, StatusCode reason) { ControlFrame frame = new ControlFrame(); frame.StreamId = stream.StreamId; frame.Type = FrameType.RTS; frame.StatusCode = reason; frame.Priority = RSTPriority; return frame; }
/// <summary> /// Builds the SYN_REPLY frame. /// </summary> /// <param name="stream">The stream.</param> /// <param name="headers">The headers.</param> /// <returns>SYN_REPLY frame.</returns> public ControlFrame BuildSynReplyFrame(SMStream stream, SMHeaders headers) { return BuildControlFrame(FrameType.SynReply, stream, headers); }