/// <summary>
 /// Gets the "total amount" text for a given statistic type.
 /// The unit type of the text depends on the unit type used for graph painting.
 /// </summary>
 private string TotalText(Stat stat)
 {
     float[] totals = TrafficStat.Total(stat, TotalsAverageCount);
     if (totals.Length > 0)
     {
         bool  bits    = GraphPaint.Scale.InBits;             // TODO bad programming practice, code smell.
         float average = totals.Average();
         if (bits)
         {
             average *= 8.0f;
         }
         var trafficValue = new TrafficUnitValue(average, bits);
         return(TrafficUnit.Humanize(trafficValue) + "/s");
     }
     return("N/A");
 }
Beispiel #2
0
 private void setScaleMenuItem_Click(object sender, EventArgs e)
 {
     while (true)
     {
         string   scale          = TrafficUnit.Humanize(TrafficMonitor.GraphPaint.Scale);
         AskValue askValueDialog = new AskValue()
         {
             Text       = "Set Scale",
             ValueTitle = "Set graph scale (allowed units: GB, MB, KB, Gb, Mb, Kb):",
             Value      = scale
         };
         askValueDialog.StartPosition = FormStartPosition.CenterParent;
         if (askValueDialog.ShowDialog(this) == DialogResult.OK)
         {
             TrafficUnitValue trafficScale;
             try
             {
                 trafficScale = TrafficUnit.Dehumanize(askValueDialog.Value);
                 if (trafficScale.Value <= 0)
                 {
                     throw new ArgumentException("must be greater than zero");
                 }
             }
             catch (ArgumentException ex)
             {
                 MessageBox.Show("Bad scale: " + ex.Message,
                                 Application.ProductName + " - Bad Input",
                                 MessageBoxButtons.OK,
                                 MessageBoxIcon.Exclamation);
                 continue;
             }
             TrafficMonitor.GraphPaint.Scale = trafficScale;
         }
         break;
     }
     Repaint();
 }