public override void NotifyAlertReceived(byte alertLevel, byte alertDescription) { string description = AlertDescription.GetText(alertDescription); AlertLevelsEnum level = AlertLevelsEnum.Warning; AlertTypesEnum alertType = AlertTypesEnum.unknown; if (Enum.IsDefined(typeof(AlertLevelsEnum), alertLevel)) { level = (AlertLevelsEnum)alertLevel; } if (Enum.IsDefined(typeof(AlertTypesEnum), alertDescription)) { alertType = (AlertTypesEnum)alertDescription; } if (alertType == AlertTypesEnum.close_notify) { logger.LogDebug( $"DTLS client received close notification: {AlertLevel.GetText(alertLevel)}, {description}."); } else { logger.LogWarning( $"DTLS client received unexpected alert: {AlertLevel.GetText(alertLevel)}, {description}."); } OnAlert?.Invoke(level, alertType, description); }
public override void NotifyAlertReceived(byte alertLevel, byte alertDescription) { string description = AlertDescription.GetText(alertDescription); AlertLevelsEnum level = AlertLevelsEnum.Warning; AlertTypesEnum alertType = AlertTypesEnum.unknown; if (Enum.IsDefined(typeof(AlertLevelsEnum), alertLevel)) { level = (AlertLevelsEnum)alertLevel; } if (Enum.IsDefined(typeof(AlertTypesEnum), alertDescription)) { alertType = (AlertTypesEnum)alertDescription; } string alertMsg = $"{AlertLevel.GetText(alertLevel)}"; alertMsg += (!string.IsNullOrEmpty(description)) ? $", {description}." : "."; if (alertType == AlertTypesEnum.close_notify) { logger.LogDebug($"DTLS server received close notification: {alertMsg}"); } else { logger.LogWarning($"DTLS server received unexpected alert: {alertMsg}"); } OnAlert?.Invoke(level, alertType, description); }
public DtlsSrtpTransport(IDtlsSrtpPeer connection, int mtu = DEFAULT_MTU) { // Network properties this._mtu = mtu; this._receiveLimit = System.Math.Max(0, mtu - MIN_IP_OVERHEAD - UDP_OVERHEAD); this._sendLimit = System.Math.Max(0, mtu - MAX_IP_OVERHEAD - UDP_OVERHEAD); this.connection = connection; connection.OnAlert += (level, type, description) => OnAlert?.Invoke(level, type, description); }
protected void ShowAlert(string message, string title) { OnAlert?.Invoke(message, title); }
public void Clear(string id = DefaultId) { OnAlert?.Invoke(new Alert { Id = id }); }
public void Alert(Alert alert) { alert.Id ??= DefaultId; OnAlert?.Invoke(alert); }
public void AddAlert(string message, AlertType type) => OnAlert.Invoke(this, new Alert(message, type));
public void Update() { if ((DateTime.Now - lastCheck).TotalSeconds > refreshInterval) { lastCheck = DateTime.Now; List <Tweet> fresh = twitter.FetchTweets(); if (fresh != null && fresh.Count > 0) { foreach (Tweet t in fresh) { Alert newAlert = null; string tweetText = t.Text; Console.WriteLine(t.Text); Match match = Regex.Match(tweetText, @"([A-Za-z\s\-)]+) (\([A-Za-z\s]+\)): ([A-Za-z\t\s\']+) - ([0-9]+)m - ([0-9]+)cr[\t\s]?-?[\s]?([A-Za-z\t\s\(\)]+)?", RegexOptions.IgnoreCase); if (match.Success) { string location = match.Groups[1].Value + " " + match.Groups[2].Value; string title = match.Groups[3].Value; string duration = match.Groups[4].Value; string credits = match.Groups[5].Value; string reward = match.Groups[6].Value; Console.WriteLine(reward); newAlert = new Alert(location, title, duration, credits, reward, t.Created, GetEndTime(t.Created, duration)); } if (newAlert != null) { DateTime Expires = newAlert.Expires; DateTime Now = DateTime.Now; TimeSpan Remaining = Expires - Now; newAlert.Remaining = Remaining; if (!ProgramOptions.ShowAll && ProgramOptions.MinCredits > Int32.Parse(newAlert.Credits) && newAlert.Reward != null) { newAlert.Show = false; } if (Remaining.Minutes > 1 && newAlert.Show) { list.Add(newAlert); App.Current.Dispatcher.BeginInvoke((Action) delegate() { Balloon balloon = new Balloon(); balloon.DataContext = newAlert; taskbarIcon.ShowCustomBalloon(balloon, PopupAnimation.Slide, 99999999); viewList.Add(newAlert); if (ProgramOptions.PlaySound) { sp = new SoundPlayer(ProgramOptions.Sound); sp.Stream.Position = 0; sp.Play(); } }); } } } if (OnAlert != null) { OnAlert.Invoke(); } } } }
private void _alertEventHandler(object sender, DoWorkEventArgs e) { var timeout = TimeSpan.FromSeconds(0.5); var lastPost = DateTime.Now; var worker = sender as Worker.BackgroundWorker; while (!worker.CancellationPending) { if ((DateTime.Now - lastPost).TotalSeconds > 1) { _session.PostTorrentUpdates(); lastPost = DateTime.Now; } var foundAlerts = _session.Alerts.PeekWait(timeout); if (!foundAlerts) { continue; } var alerts = _session.Alerts.PopAll(); foreach (var alert in alerts) { Console.WriteLine(alert.GetType().ToString() + " :" + alert.Message); if (alert is TorrentAddedAlert) { OnTorrentAddedAlert?.Invoke(this, alert as TorrentAddedAlert); } else if (alert is StateUpdateAlert) { OnStateUpdateAlert?.Invoke(this, alert as StateUpdateAlert); } else if (alert is StateChangedAlert) { OnStateChangedAlert?.Invoke(this, alert as StateChangedAlert); } else if (alert is TorrentResumedAlert) { OnTorrentResumedAlert?.Invoke(this, alert as TorrentResumedAlert); } else if (alert is StatsAlert) { OnStatsAlert?.Invoke(this, alert as StatsAlert); } else if (alert is TorrentCheckedAlert) { OnTorrentCheckedAlert?.Invoke(this, alert as TorrentCheckedAlert); } else if (alert is SaveResumeDataAlert) { OnSaveResumeDataAlert?.Invoke(this, alert as SaveResumeDataAlert); } else { OnAlert?.Invoke(this, alert); } } } e.Cancel = true; }
public void ClearNotification(Guid id) { OnAlert?.Invoke(new NotificationModel { Id = id }); }
public void TriggerNotification(NotificationModel alert) { alert.Id = Guid.NewGuid(); OnAlert?.Invoke(alert); }
/// <summary> /// Alerts the player with a message for a set duration /// </summary> /// <param name="message">The message to alert with</param> /// <param name="duration">How long should the message stay on the screen</param> public static void Alert(string message, float duration) { UnityEngine.Debug.Log(message); OnAlert?.Invoke(message, duration); }
/// <summary> /// Alerts the player with a message /// </summary> public static void Alert(string message) { UnityEngine.Debug.Log(message); OnAlert?.Invoke(message, 0f); }
private async Task ReadStream() { while (!Closing) { try { //try to read a header var hdata = new byte[24]; await Stream.ReadAsyncExact(hdata, 0, hdata.Length); var h = new MessageHeader(); h.ReadFromPayload(hdata, 0); if (h != null) { //read the payload var pl = new byte[h.PayloadSize]; await Stream.ReadAsyncExact(pl, 0, pl.Length); bool checksumOk = false; //verify hash using (var sha = SHA256.Create()) { var h1 = sha.ComputeHash(pl); var h2 = sha.ComputeHash(h1); checksumOk = h2[0] == h.Checksum[0] && h2[1] == h.Checksum[1] && h2[2] == h.Checksum[2] && h2[3] == h.Checksum[3]; } if (checksumOk) { switch (h.Command) { case "addr\0\0\0\0\0\0\0\0": { if (OnAddr != null) { var a = new Addr(); a.ReadFromPayload(pl, 0); await OnAddr?.Invoke(this, a); } break; } case "alert\0\0\0\0\0\0\0": { if (OnAlert != null) { var a = new Alert(); a.ReadFromPayload(pl, 0); await OnAlert?.Invoke(this, a); } break; } case "feefilter\0\0\0": { if (OnFeeFilter != null) { var f = new FeeFilter(); f.ReadFromPayload(pl, 0); await OnFeeFilter?.Invoke(this, f); } break; } case "filteradd\0\0\0": { if (OnFilterAdd != null) { var f = new FilterAdd(); f.ReadFromPayload(pl, 0); await OnFilterAdd?.Invoke(this, f); } break; } case "filterclear\0": { if (OnFilterClear != null) { var f = new FilterClear(); f.ReadFromPayload(pl, 0); await OnFilterClear?.Invoke(this, f); } break; } case "filterload\0\0": { if (OnFilterLoad != null) { var f = new FilterLoad(); f.ReadFromPayload(pl, 0); await OnFilterLoad?.Invoke(this, f); } break; } case "getaddr\0\0\0\0\0": { if (OnGetAddr != null) { var ga = new GetAddr(); ga.ReadFromPayload(pl, 0); await OnGetAddr?.Invoke(this, ga); } break; } case "getblocks\0\0\0": { if (OnGetBlocks != null) { var gb = new GetBlocks(); gb.ReadFromPayload(pl, 0); await OnGetBlocks?.Invoke(this, gb); } break; } case "getdata\0\0\0\0\0": { if (OnGetData != null) { var gd = new GetData(); gd.ReadFromPayload(pl, 0); await OnGetData?.Invoke(this, gd); } break; } case "getheaders\0\0": { if (OnGetHeaders != null) { var gh = new GetHeaders(); gh.ReadFromPayload(pl, 0); await OnGetHeaders?.Invoke(this, gh); } break; } case "headers\0\0\0\0\0": { if (OnHeaders != null) { var hd = new Headers(); hd.ReadFromPayload(pl, 0); await OnHeaders?.Invoke(this, hd); } break; } case "inv\0\0\0\0\0\0\0\0\0": { if (OnInv != null) { var iv = new Inv(); iv.ReadFromPayload(pl, 0); await OnInv?.Invoke(this, iv); } break; } case "mempool\0\0\0\0\0": { if (OnMemPool != null) { var mp = new MemPool(); mp.ReadFromPayload(pl, 0); await OnMemPool?.Invoke(this, mp); } break; } case "notfound\0\0\0\0": { if (OnNotFound != null) { var nf = new NotFound(); nf.ReadFromPayload(pl, 0); await OnNotFound?.Invoke(this, nf); } break; } case "ping\0\0\0\0\0\0\0\0": { if (OnPing != null) { var ping = new Ping(); ping.ReadFromPayload(pl, 0); await OnPing?.Invoke(this, ping); } break; } case "pong\0\0\0\0\0\0\0\0": { if (OnPong != null) { var pong = new Pong(); pong.ReadFromPayload(pl, 0); await OnPong?.Invoke(this, pong); } break; } case "reject\0\0\0\0\0\0": { if (OnReject != null) { var re = new Reject(); re.ReadFromPayload(pl, 0); await OnReject?.Invoke(this, re); } break; } case "sendheaders\0": { if (OnSendHeaders != null) { var sh = new SendHeaders(); sh.ReadFromPayload(pl, 0); await OnSendHeaders?.Invoke(this, sh); } break; } case "verack\0\0\0\0\0\0": { if (OnVerAck != null) { var va = new VerAck(); va.ReadFromPayload(pl, 0); await OnVerAck.Invoke(this, va); } break; } case "version\0\0\0\0\0": { if (OnVersion != null) { var v = new bitcoin_lib.P2P.Version(""); v.ReadFromPayload(pl, 0); await OnVersion?.Invoke(this, v); } break; } default: { //Console.WriteLine($"Got cmd: {h.Command}"); break; } } } else { Closing = true; } } } catch (Exception ex) { Closing = true; } } }