Esempio n. 1
0
 private void SetupEvents()
 {
     Socket.OnMessage((s, e) =>
     {
         SocketMessageEventArgs args = new SocketMessageEventArgs
         {
             Message = s
         };
         MessageReceived?.Invoke(this, args);
     });
     Socket.OnConnect((s) =>
     {
         SocketOpened?.Invoke(this, null);
     });
     Socket.OnDisconnect((status, reason, socket) =>
     {
         SocketClosedEventArgs args = new SocketClosedEventArgs
         {
             Reason   = reason,
             WasClean = false,
             Code     = status
         };
         Console.WriteLine(status);
         SocketClosed?.Invoke(this, args);
     });
 }
Esempio n. 2
0
        /// <summary>
        /// Connects to the WebSocket server.
        /// </summary>
        public void Connect()
        {
            //await _ws.ConnectAsync(_uri, _cancellationToken);
            _ws.ConnectAsync(_uri, _cancellationToken).Wait();

            SocketOpened?.Invoke(this, null);

            StartListen();
        }
        /// <summary>
        /// Raises the SocketOpened event.
        /// </summary>
        protected void InvokeSocketOpened()
        {
            var prevSocketOpenedEventCount = Interlocked.CompareExchange(ref _socketOpenedEventCount, 1, 0);

            if (prevSocketOpenedEventCount == 0)
            {
                SocketOpened?.Invoke(this, EventArgs.Empty);
            }
        }
Esempio n. 4
0
        protected override void OnProcessOutputSchema(MutableObject newSchema)
        {
            SocketOpened.TransmitSchema(newSchema);

            var perStepSchema = newSchema.CloneKeys();

            StringDataTarget.SetValue("String Data", perStepSchema);

            ReceivedData.TransmitSchema(perStepSchema);
        }
Esempio n. 5
0
        private async Task Connect()
        {
            if (_conn != null)
            {
                await _conn.DisposeAsync();
            }

            _currentHeartbeatInterval = null;

            _conn = new ShardConnection(_uri, _logger, _jsonSerializerOptions)
            {
                OnReceive = OnReceive,
                OnOpen    = () => SocketOpened?.Invoke(),
                OnClose   = (closeStatus, message) => SocketClosed?.Invoke(closeStatus, message)
            };
        }
Esempio n. 6
0
        /// <summary>
        /// Hooks up events to automatically be redirected to the interface's events.
        /// </summary>
        private void HookupEvents()
        {
            Socket.OnMessage += (sender, e) =>
            {
                SocketMessageEventArgs args = new SocketMessageEventArgs
                {
                    Message = e.Data
                };
                MessageReceived?.Invoke(this, args);
            };

            Socket.OnError += (sender, e) =>
            {
                SocketErrorEventArgs args = new SocketErrorEventArgs
                {
                    Exception = e.Exception,
                    Message   = e.Message
                };
                SocketError?.Invoke(this, args);
            };

            Socket.OnClose += (sender, e) =>
            {
                SocketClosedEventArgs args = new SocketClosedEventArgs
                {
                    Code     = e.Code,
                    Reason   = e.Reason,
                    WasClean = e.WasClean
                };
                SocketClosed?.Invoke(this, args);
            };

            Socket.OnOpen += (sender, e) =>
            {
                SocketOpened?.Invoke(this, null);
            };
        }
 /// <summary>
 /// Handles <see cref="IWebSocket.Opened"/> event.
 /// </summary>
 protected virtual void OnOpened() => SocketOpened?.Invoke();
Esempio n. 8
0
 private void WebSocket_OnOpen(object sender, EventArgs e)
 {
     IsOpen = true;
     SocketOpened?.Invoke(this, e);
 }
Esempio n. 9
0
 private void WebSocket_OnOpen(object sender, EventArgs e)
 {
     SocketOpened?.Invoke(sender,
                          new WebSocketOpenEventArgs());
 }
Esempio n. 10
0
 /// <summary>
 /// Handles <see cref="IWebSocket.Open"/> event.
 /// </summary>
 protected virtual void OnOpened(object sender, EventArgs e) => SocketOpened?.Invoke();
Esempio n. 11
0
 private void WebSocket_Opened(object sender, EventArgs e)
 => SocketOpened?.Invoke(this, EventArgs.Empty);