/// <summary> /// Handles heartbeat packets. /// </summary> /// <param name="boxedMagicNumber">Boxed Byte.</param> private void HandleHeartbeat(object boxedMagicNumber) { var magicNumber = (byte)boxedMagicNumber; if (TriggerCount <= 0 && Triggered <= 0) { TriggerCount = 0; Triggered = 0; } OnHeartbeatReceived?.Invoke(); log.Info("Received heartbeat: " + boxedMagicNumber + "."); }
private void WebSocket_MessageReceived(object sender, MessageReceivedEventArgs e) { if (StopWebSocket) { WebSocketFeed.Close(); return; } var json = e.Message; var response = JsonConfig.DeserializeObject <BaseMessage>(json); switch (response.Type) { case ResponseType.Subscriptions: break; case ResponseType.Ticker: var ticker = JsonConfig.DeserializeObject <Ticker>(json); OnTickerReceived?.Invoke(sender, new WebfeedEventArgs <Ticker>(ticker)); break; case ResponseType.Snapshot: var snapshot = JsonConfig.DeserializeObject <Snapshot>(json); OnSnapShotReceived?.Invoke(sender, new WebfeedEventArgs <Snapshot>(snapshot)); break; case ResponseType.L2Update: var level2 = JsonConfig.DeserializeObject <Level2>(json); OnLevel2UpdateReceived?.Invoke(sender, new WebfeedEventArgs <Level2>(level2)); break; case ResponseType.Heartbeat: var heartbeat = JsonConfig.DeserializeObject <Heartbeat>(json); OnHeartbeatReceived?.Invoke(sender, new WebfeedEventArgs <Heartbeat>(heartbeat)); break; case ResponseType.Received: var received = JsonConfig.DeserializeObject <Received>(json); OnReceivedReceived?.Invoke(sender, new WebfeedEventArgs <Received>(received)); break; case ResponseType.Open: var open = JsonConfig.DeserializeObject <Open>(json); OnOpenReceived?.Invoke(sender, new WebfeedEventArgs <Open>(open)); break; case ResponseType.Done: var done = JsonConfig.DeserializeObject <Done>(json); OnDoneReceived?.Invoke(sender, new WebfeedEventArgs <Done>(done)); break; case ResponseType.Match: var match = JsonConfig.DeserializeObject <Match>(json); OnMatchReceived?.Invoke(sender, new WebfeedEventArgs <Match>(match)); break; case ResponseType.LastMatch: var lastMatch = JsonConfig.DeserializeObject <LastMatch>(json); OnLastMatchReceived?.Invoke(sender, new WebfeedEventArgs <LastMatch>(lastMatch)); break; case ResponseType.Error: var error = JsonConfig.DeserializeObject <Error>(json); OnErrorReceived?.Invoke(sender, new WebfeedEventArgs <Error>(error)); break; default: throw new ArgumentOutOfRangeException(); } }
void Pulse() { Interlocked.CompareExchange(ref lastHeartbeatTicks, DateTime.UtcNow.Ticks, lastHeartbeatTicks); OnHeartbeatReceived?.Invoke(); }