public void AddData(DateTime time, long ping) { PingTimes.Add(time, ping); xAxis.Add(time.ToOADate()); if (ping > 0) { yAxis.Add(ping); } else { yAxis.Add(999); } //pingPlot.Render(); }
public override void draw() { base.draw(); lastFPS.Add((int)(1000f / (timer == 0 ? 1000 : timer))); fpsText.Text = (lastFPS.Sum() / lastFPS.Count).ToString("0.00"); timer = 0; }
public void GetExceptionTest() { FixedList <int> lst = new FixedList <int>(5); Assert.Throws <IndexOutOfRangeException>(() => lst[0]); lst.Add(0); Assert.Equal(0, lst[0]); Assert.Throws <IndexOutOfRangeException>(() => lst[1]); }
public void AddTest() { FixedList <int> lst = new FixedList <int>(Size); Assert.Equal(0, lst.Count); for (int i = 1; i <= Size; i++) { lst.Add(i); } var expected = Enumerable.Range(1, 3 * Size); for (int i = Size; i <= 2 * Size; i++) { Assert.True(lst.SequenceEqual(expected.Skip(i - Size).Take(Size))); lst.Add(i + 1); } }
public void ClearTest() { FixedList <int> lst = new FixedList <int>(Size); Assert.Equal(0, lst.Count); for (int i = 1; i <= Size; i++) { lst.Add(i); } var expected = Enumerable.Range(1, 3 * Size); Assert.True(lst.SequenceEqual(expected.Skip(0).Take(Size))); lst.Clear(); Assert.True(lst.SequenceEqual(new int[0])); Assert.Equal(0, lst.Count); Assert.Throws <IndexOutOfRangeException>(() => lst[0]); }
private void Timer_Tick(object sender, EventArgs e) { if (_pinger is not null && _pinger.Running) { StopButtonEnabled = true; StartButtonEnabled = false; StringBuilder sb = new StringBuilder(); for (int i = 0; i < _pinger.Replies.Count - 1; i++) { _totalPings++; var success = _pinger.Replies.TryTake(out Reply reply); if (success) { if (Config.WindowExpanded) { var s = (LineSeries)GraphModel.Series[0]; var maxPoints = (Host.Interval * 30) / 1000; if (s.Points.Count > maxPoints) { s.Points.RemoveAt(0); } s.Points.Add(new DataPoint(reply.DateTime.ToOADate(), reply.RoundTrip)); Dispatcher.UIThread.InvokeAsync(() => GraphModel.InvalidatePlot(true), DispatcherPriority.Background); var p = (PieSeries)StatusModel.Series[0]; if (reply.Succeeded.Value) { if (reply.RoundTrip > Host.Threshold) { var oldValue = p.Slices[1].Value; p.Slices[1] = new PieSlice("Warning", oldValue + 1) { Fill = OxyColor.FromRgb(235, 224, 19) }; } else { var oldValue = p.Slices[0].Value; p.Slices[0] = new PieSlice("Success", oldValue + 1) { Fill = OxyColor.FromRgb(51, 204, 0) }; } } else { var oldValue = p.Slices[2].Value; p.Slices[2] = new PieSlice("Failure", oldValue + 1) { Fill = OxyColor.FromRgb(194, 16, 16) }; } Dispatcher.UIThread.InvokeAsync(() => StatusModel.InvalidatePlot(true), DispatcherPriority.Background); } Log.Debug("Ping Success"); sb.Append($"[{reply.DateTime:T}] "); if (reply.RoundTrip > 0) { _pingTimes.Add(reply.RoundTrip); Log.Debug($"{HostName} RoundTrip Time > 0: {reply.RoundTrip}"); } if (reply.TimedOut) { TimeoutCount++; Log.Debug($"{HostName} Reply timed out. Number of Timeouts: {TimeoutCount}"); sb.Append($"Timed out to host"); } else { sb.Append($"Ping round trip: {reply.RoundTrip}ms"); if (reply.RoundTrip >= WarningThreshold) { WarningCount++; sb.Append(" [Warning]"); } } sb.Append(Environment.NewLine); } } PingStatusText += sb.ToString(); var lines = PingStatusText.Split(Environment.NewLine).ToList(); if (lines.Count > _pingTimes.MaxSize) { lines.RemoveAt(0); PingStatusText = string.Join(Environment.NewLine, lines); } if (_pingTimes.Count > 0) { AveragePing = Math.Ceiling(_pingTimes.Average()).ToString() + "ms"; } PacketLoss = $"{Math.Round(TimeoutCount / (double)_totalPings * 100, 2)}%"; }
void Timer_Tick(object sender, EventArgs e) { if (Pinger != null && Pinger.Running) { if (Config.WindowExpanded) { switch (rightTabs.SelectedIndex) { case 1: pingGraphControl.UpdatePlot(); break; case 2: statusGraphControl.UpdatePieChart(PingHost.Threshold, PingHost.Timeout); break; } } StartBtn.Visibility = Visibility.Hidden; StopBtn.Visibility = Visibility.Visible; doTraceRteBtn.Visibility = Visibility.Hidden; StringBuilder sb = new StringBuilder(); for (int i = 0; i < Pinger.Replies.Count - 1; i++) { TotalPings++; // Logger.Info($"{PingHost.HostName} TotalPings: {TotalPings}"); var success = Pinger.Replies.TryTake(out Reply reply); pingGraphControl.AddData(reply.DateTime, reply.RoundTrip); statusGraphControl.AddData(reply.DateTime, reply.RoundTrip); if (success) { Logger.Debug("Ping Success"); var line = $"[{reply.DateTime:T}] "; if (reply.RoundTrip > 0) { PingTimes.Add(reply.RoundTrip); Logger.Debug($"{PingHost.HostName} RoundTrip Time > 0: {reply.RoundTrip}"); } if (reply.TimedOut) { Timeouts++; Logger.Debug($"{PingHost.HostName} Reply timed out. Number of Timeouts: {Timeouts}"); line += $"Timed out to host"; } else { line += $"Ping round trip: {reply.RoundTrip}ms"; if (reply.RoundTrip >= PingHost.Threshold) { Warnings++; line += " [Warning]"; } } sb.Append(line); sb.Append(Environment.NewLine); } } PingStatusBox.Text += sb.ToString(); var lines = PingStatusBox.Text.Split(Environment.NewLine).ToList(); if (lines.Count > PingTimes.MaxSize) { Logger.Debug($"{PingHost.HostName} Lines in text box greater than {PingTimes.MaxSize}, removing a line."); lines.RemoveAt(0); PingStatusBox.Text = string.Join(Environment.NewLine, lines); } if (PingTimes.Count > 0) { avgPingLbl.Content = Math.Ceiling(PingTimes.Average()).ToString() + "ms"; } timeoutLbl.Content = Timeouts.ToString(); warningLbl.Content = Warnings.ToString(); PacketLoss = ((double)Timeouts / (double)TotalPings) * 100; packetLossLabel.Content = $"{Math.Round(PacketLoss, 2)}%"; } else { StartBtn.Visibility = Visibility.Visible; StopBtn.Visibility = Visibility.Hidden; doTraceRteBtn.Visibility = Visibility.Visible; if (IPAddressBox.Text == "Invalid Host Name") { StartBtn.IsEnabled = false; doTraceRteBtn.IsEnabled = false; } else { StartBtn.IsEnabled = true; doTraceRteBtn.IsEnabled = true; } } CheckForFolder(); }
/// <summary> /// Initializes the audio controller. /// </summary> public void Initialize(AudioControllerConfig config) { // AudioSource allocation. { int maxCount = Mathf.Max (1, config.AudioSourceMaxCount); _availableSources = new FixedList<AudioSource> (maxCount); _availableSourceInfoIndices = new FixedList<int> (maxCount); _activeSourceInfoIndices = new FixedList<int> (maxCount); _sourceInfos = new FixedList<AudioSourceInfo> (maxCount); for (int i = 0; i < maxCount; i++) { GameObject go = new GameObject ("AudioSource_" + i); Transform xform = go.transform; xform.parent = this.transform; AudioSource audioSource = go.AddComponent<AudioSource> (); ReturnSourceToPool (audioSource); _availableSourceInfoIndices.Add (i); _sourceInfos.Add (new AudioSourceInfo ()); } } _audioLoader = config.AudioLoader; if (_audioLoader == null) { Debug.LogError ("AudioLoader not set!"); } }