diff --git a/DataCore.sln b/DataCore.sln new file mode 100644 index 0000000..41ba85c --- /dev/null +++ b/DataCore.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.24720.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataCore", "DataCore\DataCore.csproj", "{66E8542C-6814-4845-A5E9-4B09A8C11B56}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataCore_Console", "DataCore_Console\DataCore_Console.csproj", "{18E6D4B8-4E08-4ACB-B7A9-8AE8E2B68D21}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {66E8542C-6814-4845-A5E9-4B09A8C11B56}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {66E8542C-6814-4845-A5E9-4B09A8C11B56}.Debug|Any CPU.Build.0 = Debug|Any CPU + {66E8542C-6814-4845-A5E9-4B09A8C11B56}.Release|Any CPU.ActiveCfg = Release|Any CPU + {66E8542C-6814-4845-A5E9-4B09A8C11B56}.Release|Any CPU.Build.0 = Release|Any CPU + {18E6D4B8-4E08-4ACB-B7A9-8AE8E2B68D21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {18E6D4B8-4E08-4ACB-B7A9-8AE8E2B68D21}.Debug|Any CPU.Build.0 = Debug|Any CPU + {18E6D4B8-4E08-4ACB-B7A9-8AE8E2B68D21}.Release|Any CPU.ActiveCfg = Release|Any CPU + {18E6D4B8-4E08-4ACB-B7A9-8AE8E2B68D21}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/DataCore/DataCore.csproj b/DataCore/DataCore.csproj new file mode 100644 index 0000000..00c6708 --- /dev/null +++ b/DataCore/DataCore.csproj @@ -0,0 +1,54 @@ + + + + + Debug + AnyCPU + {66E8542C-6814-4845-A5E9-4B09A8C11B56} + Library + Properties + DataCore + DataCore + v4.5.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DataCore/GetAdapterStats.cs b/DataCore/GetAdapterStats.cs new file mode 100644 index 0000000..6e30dbe --- /dev/null +++ b/DataCore/GetAdapterStats.cs @@ -0,0 +1,133 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Net.NetworkInformation; +using System.Text; +using System.Timers; +using System.Threading; +using System.Threading.Tasks; + +namespace DataCore +{ + public static class GetAdapterStats + { + static NetworkInterface[] systemAdapters = NetworkInterface.GetAllNetworkInterfaces(); + + static long[] currentAdapterTransfers = new long[systemAdapters.Length]; + + static long uploadStart = 0; + static long dowloadStart = 0; + + // currentOverwriteStatus will equal zero on first pass, meaning no values should be read after the current value + // one means all values before should be read before the values following the current position + public static byte currentOverwriteStatus = 0; + public static int ratesIndex = 0; + static long[] UploadRateHistory = new long[1000]; + static long[] DownloadRateHistory = new long[1000]; + + /// + /// Gets the rate of input data flow from the host computer + /// + /// Declares that the input rates of multiple adapters should be summed. If false, returns the value of the highest transfer. Less accurate as a shorter response time is needed + /// The number of bytes received since the last run + public static long InputRate(bool sum = true) + { + long returnRate = 0; + + //foreach (NetworkInterface adapter in systemAdapters) + for(int i=0; i + /// Gets the rate of output data flow from the host computer + /// + /// Declares that the output rates of multiple adapters should be summed. If false, returns the value of the highest transfer + /// The number of bytes sent since the last run + public static long OutputRate(bool sum = true) + { + long returnRate = 0; + + for (int i = 0; i < systemAdapters.Length; i++) + { + if (sum) + { + long totalRate = systemAdapters[i].GetIPStatistics().BytesSent; + Thread.Sleep(100); + returnRate = returnRate + ((systemAdapters[i].GetIPStatistics().BytesSent - totalRate)* 10); + } + else + { + long totalRate = systemAdapters[i].GetIPStatistics().BytesSent; + Thread.Sleep(10); + currentAdapterTransfers[i] = ((systemAdapters[i].GetIPStatistics().BytesSent - totalRate) * 100); + } + } + if (!sum) + { + returnRate = currentAdapterTransfers.Max(); + } + + return returnRate; + } + public static void logRates() + { + for (int i = 0; i < systemAdapters.Length; i++) + { + uploadStart = uploadStart + systemAdapters[i].GetIPStatistics().BytesSent; + dowloadStart = dowloadStart + systemAdapters[i].GetIPStatistics().BytesReceived; + } + System.Timers.Timer logTime = new System.Timers.Timer(1000); + logTime.Elapsed += DoLog; + logTime.AutoReset = true; + logTime.Enabled = true; + logTime.Start(); + } + private static void DoLog(Object source, ElapsedEventArgs e) + { + if(ratesIndex == UploadRateHistory.Length) + { + ratesIndex = 0; + } + long currentUp = 0; + long currentDown = 0; + + + long tempUp = 0; + long tempDown = 0; + for (int i = 0; i < systemAdapters.Length; i++) + { + currentUp = systemAdapters[i].GetIPStatistics().BytesSent; + currentDown = systemAdapters[i].GetIPStatistics().BytesReceived; + + tempUp = tempUp + (currentUp - uploadStart); + tempDown = tempDown + (currentDown - dowloadStart); + } + uploadStart = tempUp; + dowloadStart = tempDown; + ratesIndex++; + return; + } + + } +} diff --git a/DataCore/Properties/AssemblyInfo.cs b/DataCore/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..0304861 --- /dev/null +++ b/DataCore/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("DataCore")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("DataCore")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("66e8542c-6814-4845-a5e9-4b09a8c11b56")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/DataCore_Console/App.config b/DataCore_Console/App.config new file mode 100644 index 0000000..88fa402 --- /dev/null +++ b/DataCore_Console/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DataCore_Console/DataCore_Console.csproj b/DataCore_Console/DataCore_Console.csproj new file mode 100644 index 0000000..4253b22 --- /dev/null +++ b/DataCore_Console/DataCore_Console.csproj @@ -0,0 +1,66 @@ + + + + + Debug + AnyCPU + {18E6D4B8-4E08-4ACB-B7A9-8AE8E2B68D21} + Exe + Properties + DataCore_Console + DataCore_Console + v4.5.2 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + {66e8542c-6814-4845-a5e9-4b09a8c11b56} + DataCore + + + + + \ No newline at end of file diff --git a/DataCore_Console/Program.cs b/DataCore_Console/Program.cs new file mode 100644 index 0000000..81d9e69 --- /dev/null +++ b/DataCore_Console/Program.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DataCore; +using System.Threading; + +namespace DataCore_Console +{ + class Program + { + static void Main(string[] args) + { + for(int i=0; i< 1000; i++) + { + Console.WriteLine("Download data rate: {0} kB/s;\t\t Upload: {1} kB/s", (double)GetAdapterStats.InputRate() /1024, (double)GetAdapterStats.OutputRate() / 1024); + Thread.Sleep(100); + } + + + Console.ReadKey(); + + } + } +} diff --git a/DataCore_Console/Properties/AssemblyInfo.cs b/DataCore_Console/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..0d04f02 --- /dev/null +++ b/DataCore_Console/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("DataCore_Console")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("DataCore_Console")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("18e6d4b8-4e08-4acb-b7a9-8ae8e2b68d21")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]