Example #1
0
        public void UpdateTrafficList(Traffic traffic)
        {
            long maxSpeedValue = 0;

            inboundPoints.Clear();
            outboundPoints.Clear();

            lock (logList)
            {
                if (traffic != null)
                {
                    this.traffic = traffic;
                    #region Add to trafficLogList
                    TrafficLog previous = logList.Last.Value;
                    TrafficLog current  = new TrafficLog(
                        new Traffic(traffic),
                        new Traffic(traffic, previous.total)
                        );
                    logList.AddLast(current);

                    while (logList.Count > trafficLogSize)
                    {
                        logList.RemoveFirst();
                    }
                    while (logList.Count < trafficLogSize)
                    {
                        logList.AddFirst(new TrafficLog());
                    }
                    #endregion
                }

                lastLog = logList.Last.Value;
                foreach (TrafficLog item in logList)
                {
                    inboundPoints.Add(item.speed.inbound);
                    outboundPoints.Add(item.speed.outbound);

                    maxSpeedValue = Math.Max(maxSpeedValue,
                                             Math.Max(item.speed.inbound, item.speed.outbound)
                                             );
                }
            }

            maxSpeed = new FormattedSize(maxSpeedValue);

            for (int i = 0; i < inboundPoints.Count; i++)
            {
                inboundPoints[i]  /= maxSpeed.scale;
                outboundPoints[i] /= maxSpeed.scale;
            }

            if (TrafficChart.InvokeRequired)
            {
                TrafficChart.Invoke(new Action(UpdateTrafficChart));
            }
            else
            {
                UpdateTrafficChart();
            }
        }
        private void UpdateTrafficChart()
        {
            TrafficLog last;
            long       maxSpeedValue = 0;

            rawInboundPoints.Clear();
            rawOutboundPoints.Clear();
            lock (trafficLogList)
            {
                last = trafficLogList.Last.Value;
                foreach (TrafficLog item in trafficLogList)
                {
                    rawInboundPoints.Add(item.rawSpeed.inbound);
                    rawOutboundPoints.Add(item.rawSpeed.outbound);

                    maxSpeedValue = Math.Max(maxSpeedValue,
                                             Math.Max(item.rawSpeed.inbound, item.rawSpeed.outbound)
                                             );
                }
            }

            FormattedSize maxSpeed = new FormattedSize(maxSpeedValue);

            RawInboundSpeed.Text  = new FormattedSize(last.rawSpeed.inbound) + "/s";
            RawOutboundSpeed.Text = new FormattedSize(last.rawSpeed.outbound) + "/s";

            for (int i = 0; i < rawInboundPoints.Count; i++)
            {
                rawInboundPoints[i]  /= maxSpeed.scale;
                rawOutboundPoints[i] /= maxSpeed.scale;
            }

            TrafficChart.Series["Inbound"].Points.DataBindY(rawInboundPoints);
            TrafficChart.Series["Outbound"].Points.DataBindY(rawOutboundPoints);
            TrafficChart.Series["Inbound"].ToolTip             = "#SERIESNAME #VALY{F2} " + maxSpeed.unit + "/s";
            TrafficChart.Series["Outbound"].ToolTip            = "#SERIESNAME #VALY{F2} " + maxSpeed.unit + "/s";
            TrafficChart.ChartAreas[0].AxisY.LabelStyle.Format = "{0:0.##} " + maxSpeed.unit + "/s";
        }