private async void PostEventAsync(EventFiredArgs args) { try { if (args.EventType == (byte)EventType.SystemChangeNotification) { await PostSystemChangeNotificationAsync(args);//this special event turns into reported boards serial info + still an event with a shorter description } else { await Post(args); } } catch (Exception ex) { lock (_badPackages) { _badPackages.Add(DateTime.UtcNow); } OnError($"failed posting event: {args.EventType} - {args.Data} - {args.TimeSpan}", ex); } Task Post(EventFiredArgs args) => _plot.PostEventAsync(GetSignedEvent(args)); Task PostBoardsSerialInfo(SystemChangeNotificationData data, DateTime timeSpan) => _plot.PostBoardsSerialInfo(SignAndCompress(data.ToBoardsSerialInfoJsonUtf8Bytes(timeSpan))); Task PostSystemChangeNotificationAsync(EventFiredArgs args) { var data = SystemChangeNotificationData.ParseJson(args.Data); return(Task.WhenAll( PostBoardsSerialInfo(data, args.TimeSpan), Post(new EventFiredArgs(ToShortEventData(data), args.EventType, args.TimeSpan)))); }
private void SendEvent(object sender, EventFiredArgs e) { lock (_eventsQueue) if (_eventsQueue.Count < 10000) // if sending thread can't catch up, then drop packages. { _eventsQueue.Enqueue(e); } }
private byte[] GetSignedEvent(EventFiredArgs @event) { //this can be made more efficient to avoid extra allocations and/or use a memory pool, but these are for low frequency events so postponing looking at that. var bytes = @event.ToByteArray(); return(_signing.GetSignature(bytes).Concat(bytes).ToArray()); }