Beispiel #1
0
        /// <summary>Method which is invoked when new <see cref="SubscriptionDataEvent"/> arrives.</summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="SubscriptionDataEvent"/> instance containing the event data.</param>
        private static void Connection_DataReceived(object sender, SubscriptionDataEvent e)
        {
            // Ignore any data that isn't a Console style response message.
            if (e.rootObject.GetType() != typeof(ConsoleResponse))
            {
                return;
            }

            ConsoleResponse consoleRoot = (ConsoleResponse)e.rootObject;

            Console.WriteLine(consoleRoot.Message);
        }
Beispiel #2
0
        /// <summary>Method which is invoked when new <see cref="SubscriptionDataEvent"/> arrives.</summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="SubscriptionDataEvent"/> instance containing the event data.</param>
        private void Connection_DataReceived(object sender, SubscriptionDataEvent e)
        {
            // Ignore any data that isn't an Interfaces response message.
            if (e.rootObject.GetType() != typeof(InterfacesResponse))
            {
                return;
            }

            InterfacesResponse interfacesRoot = (InterfacesResponse)e.rootObject;

            if (interfacesRoot.Interfaces != null)
            {
                byte manuallyAddedSeriesCount = 0;
                foreach (KeyValuePair <string, Interface> currentInterface in interfacesRoot.Interfaces)
                {
                    // We only care about "eth" devices.
                    if (!currentInterface.Key.StartsWith("eth"))
                    {
                        continue;
                    }

                    string currentRx = currentInterface.Key + "Rx";
                    string currentTx = currentInterface.Key + "Tx";

                    // If the bandwidthChart does not have this series already addded then we will need to add it.
                    if (bandwidthChart.Series.IndexOf(currentRx) == -1)
                    {
                        Series currentRxSeries = new Series(currentRx)
                        {
                            ChartArea = "ChartAreaRx", ChartType = SeriesChartType.StackedColumn
                        };
                        if (manuallyAddedSeriesCount < paletteColors.Length)
                        {
                            currentRxSeries.Color = paletteColors[manuallyAddedSeriesCount];
                        }
                        bandwidthChart.Series.Add(currentRxSeries);

                        Series currentTxSeries = new Series(currentTx)
                        {
                            ChartArea = "ChartAreaTx", ChartType = SeriesChartType.StackedColumn
                        };
                        if (manuallyAddedSeriesCount < paletteColors.Length)
                        {
                            currentTxSeries.Color = paletteColors[manuallyAddedSeriesCount++];
                        }
                        bandwidthChart.Series.Add(new Series(currentTx));
                    }

                    bandwidthChart.Series[currentRx].Points.AddY(interfacesRoot.Interfaces[currentInterface.Key].stats.rx_bps);
                    bandwidthChart.Series[currentTx].Points.AddY(interfacesRoot.Interfaces[currentInterface.Key].stats.tx_bps);
                }

                // Adjust Y & X axis scale
                bandwidthChart.ResetAutoValues();

                // We set a limit for the maximum number of points we want to see in the chart.
                const byte numberOfPointsInChart = 50;

                // Check each of the series.
                foreach (Series currentSeries in bandwidthChart.Series)
                {
                    // Keep a constant number of points by removing them from the left
                    while (currentSeries.Points.Count > numberOfPointsInChart)
                    {
                        // Remove data points on the left side
                        while (currentSeries.Points.Count > numberOfPointsInChart)
                        {
                            currentSeries.Points.RemoveAt(0);
                        }
                    }
                }

                // Invalidate chart
                bandwidthChart.Invalidate();
            }
        }