public override void Connect()
        {
            if (EventSource != null)
            {
                HTTPManager.Logger.Warning("ServerSentEventsTransport", "Start - EventSource already created!");
                return;
            }

            // Skip the Connecting state if we are reconnecting. If the connect succeeds, we will set the Started state directly
            if (this.State != TransportStates.Reconnecting)
                this.State = TransportStates.Connecting;

            RequestTypes requestType = this.State == TransportStates.Reconnecting ? RequestTypes.Reconnect : RequestTypes.Connect;

            Uri uri = Connection.BuildUri(requestType, this);
            
            EventSource = new EventSource(uri);

            EventSource.OnOpen += OnEventSourceOpen;
            EventSource.OnMessage += OnEventSourceMessage;
            EventSource.OnError += OnEventSourceError;
            EventSource.OnClosed += OnEventSourceClosed;

            // Disable internal retry
            EventSource.OnRetry += (es) => false;

            // Start connecting to the server.
            EventSource.Open();
        }
 public override void Connect()
 {
     if (this.EventSource != null)
     {
         HTTPManager.Logger.Warning("ServerSentEventsTransport", "Start - EventSource already created!");
     }
     else
     {
         if (base.State != TransportStates.Reconnecting)
         {
             base.State = TransportStates.Connecting;
         }
         RequestTypes type = (base.State != TransportStates.Reconnecting) ? RequestTypes.Connect : RequestTypes.Reconnect;
         Uri          uri  = base.Connection.BuildUri(type, this);
         this.EventSource            = new BestHTTP.ServerSentEvents.EventSource(uri);
         this.EventSource.OnOpen    += new OnGeneralEventDelegate(this.OnEventSourceOpen);
         this.EventSource.OnMessage += new OnMessageDelegate(this.OnEventSourceMessage);
         this.EventSource.OnError   += new OnErrorDelegate(this.OnEventSourceError);
         this.EventSource.OnClosed  += new OnGeneralEventDelegate(this.OnEventSourceClosed);
         if (< > f__am$cache0 == null)
         {
        public override void Stop()
        {
            EventSource.OnOpen -= OnEventSourceOpen;
            EventSource.OnMessage -= OnEventSourceMessage;
            EventSource.OnError -= OnEventSourceError;
            EventSource.OnClosed -= OnEventSourceClosed;

            EventSource.Close();

            EventSource = null;
        }
        private void OnEventSourceError(EventSource eventSource, string error)
        {
            HTTPManager.Logger.Information("Transport - " + this.Name, "OnEventSourceError");

            // We are in a reconnecting phase, we have to connect now.
            if (this.State == TransportStates.Reconnecting)
            {
                Connect();
                return;
            }

            // Already closed?
            if (this.State == TransportStates.Closed)
                return;

            // Closing? Then we are closed now.
            if (this.State == TransportStates.Closing)
                this.State = TransportStates.Closed;
            else // Errored when we didn't expected it.
                Connection.Error(error);
        }
        private void OnEventSourceMessage(EventSource eventSource, BestHTTP.ServerSentEvents.Message message)
        {
            if (message.Data.Equals("initialized"))
            {
                base.OnConnected();

                return;
            }

            IServerMessage msg = TransportBase.Parse(Connection.JsonEncoder, message.Data);

            if (msg != null)
                Connection.OnMessage(msg);

        }
 private void OnEventSourceOpen(EventSource eventSource)
 {
     HTTPManager.Logger.Information("Transport - " + this.Name, "OnEventSourceOpen");
 }