Пример #1
0
        /// <summary>
        /// Create SM session. Close if previously opened.
        /// </summary>
        /// <param name="uri">The URI</param>
        /// <param name="option">Options for session</param>
        /// <returns>The return code.</returns>
        private static int CreateSession(Uri uri, SMProtocolOptions option)
        {
            int res = 0;
            CloseSession();

            session = new SMSession(uri, false, option);

            // URI can still be invalid, missing protocol prefix for example
            try
            {
                session.Open();

                session.OnOpen += OnSessionOpened;
                session.OnClose += OnSessionClosed;
                session.OnError += OnSessionError;
                session.OnStreamOpened += OnStreamOpened;
                session.OnStreamClosed += OnStreamClosed;

                // wait until session changes its state
                // for high latency connections we cannot just start using this session
                sessionMonitorEvent.Reset();
                timeoutSessionMonitor = false;
                ThreadPool.QueueUserWorkItem(new WaitCallback(SessionMonitorProc), 0);
                sessionMonitorEvent.WaitOne(300000);
                timeoutSessionMonitor = true;
            }
            catch
            {
                SMLogger.LogError("Unable to open session for " + uri);
                res = 1;
            }

            return res;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SMFramesMonitor"/> class.
 /// </summary>
 /// <param name="session">The session.</param>
 /// <param name="filter">The filter.</param>
 public SMFramesMonitor(SMSession session, Func <BaseFrame, bool> filter)
 {
     this.session = session;
     this.Filter  = filter;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SMFramesMonitor"/> class.
 /// </summary>
 /// <param name="session">The session.</param>
 public SMFramesMonitor(SMSession session)
     : this(session, null)
 {
 }
 private static SMSession CreateSession(Uri uri)
 {
     _session = new SMSession(uri, false);
     _session.Open();
     return _session;
 }
        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.Scheme] = 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;
        }
        public void IncorrectPortFailure()
        {
            ManualResetEvent eventRaised = new ManualResetEvent(false);
            Random rand = new Random(DateTime.Now.Millisecond);
            int random = rand.Next() % 1000;
            Uri uri;
            Uri.TryCreate(Host + random, UriKind.Absolute, out uri);

            if (_session != null && _session.State == SMSessionState.Opened)
                _session.End();

            _session = new SMSession(uri, false);
            bool isError = false;
            _session.OnError += (s, e) =>
                                    {
                                        isError = true;
                                    };

            SMProtocol smProtocol = _session.Protocol;
            smProtocol.OnError += (s, e) =>
            {
                isError = true;
                eventRaised.Set();
            };

            _session.Open();
            eventRaised.WaitOne();

            Assert.IsTrue(isError);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SMFramesMonitor"/> class.
 /// </summary>
 /// <param name="session">The session.</param>
 public SMFramesMonitor(SMSession session)
     : this(session, null)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SMFramesMonitor"/> class.
 /// </summary>
 /// <param name="session">The session.</param>
 /// <param name="filter">The filter.</param>
 public SMFramesMonitor(SMSession session, Func<BaseFrame, bool> filter)
 {
     this.session = session;
     this.Filter = filter;
 }
        /// <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>();
        }
        /// <summary>
        /// Create SM session. Close if previously opened.
        /// </summary>
        /// <param name="uri">The URI</param>
        private static void CreateSession(Uri uri)
        {
            CloseSession();

            session = new SMSession(uri, false);

            // URI can still be invalid, missing protocol prefix for example
            try
            {
                session.Open();

                session.OnOpen += OnSessionOpened;
                session.OnClose += OnSessionClosed;
                session.OnError += OnSessionError;
                session.OnStreamOpened += OnStreamOpened;
            }
            catch
            {
                SMLogger.LogError("Unable to open session for " + uri.ToString());
            }
        }