Пример #1
0
        /// <summary>
        /// Attached to events on session.
        /// </summary>
        /// <param name="session">Session.</param>
        private static void AttachSessionEvents(SMSession session)
        {
            session.OnOpen += (s, e) =>
            {
                _isOpenSession = true;
                _eventRaisedSession.Set();
            };

            session.OnStreamOpened += (s, e) =>
            {
                if (e.Stream.StreamId % 2 == 0)
                {
                    _isError      = true;
                    _errorMessage = "StreamId must be odd";
                }
                _isOpenStream = true;
                _eventRaisedStream.Set();
            };
            session.OnError += (s, e) =>
            {
                _isError      = true;
                _errorMessage = e.Exeption.Message;
                _eventRaisedStream.Set();
                _eventRaisedSession.Set();
            };
        }
Пример #2
0
        public void IncorrectPortFailure()
        {
            Reset();
            Random rand   = new Random(DateTime.Now.Millisecond);
            int    random = rand.Next() % 1000;
            Uri    uri;

            Uri.TryCreate(Host + random, UriKind.Absolute, out uri);

            _session = new SMSession(uri, false, _options);
            AttachSessionEvents(_session);

            SMProtocol smProtocol = _session.Protocol;

            smProtocol.OnError += (s, e) =>
            {
                _isError = true;
                _eventRaisedStream.Set();
            };

            _session.Open();
            _eventRaisedSession.WaitOne();

            Assert.IsTrue(_isError);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SMStream"/> class.
 /// </summary>
 /// <param name="id">The stream id.</param>
 /// <param name="session">The stream session.</param>
 public SMStream(int id, SMSession session)
 {
     this.StreamId = id;
     this.Session = session;
     this.Headers = new SMHeaders();
     this.protocol = session.Protocol;
     this.protocol.OnStreamFrame += this.OnProtocolData;
     this.protocol.OnStreamError += this.OnStreamError;
     this.protocol.OnSessionFrame += this.OnSessionFrame;
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SMStream"/> class.
 /// </summary>
 /// <param name="id">The stream id.</param>
 /// <param name="session">The stream session.</param>
 public SMStream(int id, SMSession session)
 {
     this.StreamId = id;
     this.Session  = session;
     this.Headers  = new SMHeaders();
     this.protocol = session.Protocol;
     this.protocol.OnStreamFrame  += this.OnProtocolData;
     this.protocol.OnStreamError  += this.OnStreamError;
     this.protocol.OnSessionFrame += this.OnSessionFrame;
 }
Пример #5
0
        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();
        }
Пример #6
0
        /// <summary>
        /// Open of stream and sent request for receive data.
        /// </summary>
        /// <param name="fileName">Path to the data on server.</param>
        /// <param name="session">Current session.</param>
        /// <param name="isFin">Flag fin.</param>
        /// <returns>New SMstream.</returns>
        private static SMStream DownloadPathForList(string fileName, ref SMSession session, bool isFin)
        {
            if (session.State == SMSessionState.Opened)
            {
                SMHeaders headers = new SMHeaders();
                headers[SMHeaders.Path]        = fileName;
                headers[SMHeaders.Version]     = "http/1.1";
                headers[SMHeaders.Method]      = "GET";
                headers[SMHeaders.Scheme]      = "http";
                headers[SMHeaders.ContentType] = ContentTypes.GetTypeFromFileName(fileName);

                return(session.OpenStream(headers, isFin));
            }
            return(null);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ProtocolMonitor"/> class.
        /// </summary>
        /// <param name="session">The sm session instance.</param>
        public ProtocolMonitor(SMSession session)
        {
            this.exclusiveLock = new object();

            if (session == null)
            {
                throw new ArgumentNullException("session");
            }

            this.totals        = new ProtocolMonitorLog();
            this.session       = session;
            this.exitEvent     = new ManualResetEvent(false);
            this.statsByStream = new StreamStats();
            this.State         = MonitorState.MonitorOff;
            this.savedStats    = new Dictionary <int, StatisticsSnapshot>();
            this.LastStartDate = DateTime.Now;
            this.LastEndDate   = this.LastStartDate;
        }
Пример #8
0
 /// <summary>
 /// Create new session.
 /// </summary>
 /// <param name="uri">Uri.</param>
 /// <returns>New session.</returns>
 private static SMSession CreateSession(Uri uri, SMProtocolOptions options)
 {
     _session = new SMSession(uri, false, options);
     _session.Open();
     return(_session);
 }