/// <summary> /// Gets an averaged value for the passed in PerformanceCounter. /// </summary> /// <returns>Returns an averaged value for the passed in PerformanceCounter /// averaged over valueAvgCount readings.</returns> public int getValue() { int currentValue = 0; switch (curStatType) { case statType.CPU: currentValue = Convert.ToInt32(statCounter.NextValue()); break; case statType.RAM: currentValue = 100 - Convert.ToInt32(((float)compInfo.AvailablePhysicalMemory / (float)compInfo.TotalPhysicalMemory) * 100); break; case statType.FileCount: double fileCount = AGTools.getDirectorySize("Z:\\SCM\\2012.0.0\\ProductInstallers"); //System.IO.Directory.GetFiles("Z:\\SCM\\2012.0.0\\ProductInstallers", "*", System.IO.SearchOption.AllDirectories).Length; double maxSize = 4000000000.0; currentValue = Convert.ToInt32((fileCount / maxSize) * 100.0); break; case statType.DiskActivity: currentValue = Convert.ToInt32(statCounter.NextValue()); if (currentValue > 100) { currentValue = 100; } break; case statType.TimingTestLines: int currentLines = AGTools.getFileLineCount(@"Z:\SCM\PRIVATE\BuildInProgress\timingTest.log"); if (currentLines > 0) { currentValue = Convert.ToInt32((currentLines / 29.0) * 100); } break; default: currentValue = Convert.ToInt32(statCounter.NextValue()); break; } if (currentValue < 0 || currentValue > 100) { throw new Exception("Invalid currentValue: " + currentValue); } valueArray[curValueIndex++ % valueArray.Length] = currentValue; return(AGTools.averageArray(valueArray)); }
private void button3_Click(object sender, EventArgs e) { label2.Text = AGTools.getDirectorySize("Z:\\SCM\\2012.0.0\\ProductInstallers").ToString(); }