Added solution files
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{66E8542C-6814-4845-A5E9-4B09A8C11B56}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>DataCore</RootNamespace>
|
||||
<AssemblyName>DataCore</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="GetAdapterStats.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -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];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the rate of input data flow from the host computer
|
||||
/// </summary>
|
||||
/// <param name="sum">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</param>
|
||||
/// <returns>The number of bytes received since the last run</returns>
|
||||
public static long InputRate(bool sum = true)
|
||||
{
|
||||
long returnRate = 0;
|
||||
|
||||
//foreach (NetworkInterface adapter in systemAdapters)
|
||||
for(int i=0; i<systemAdapters.Length; i++)
|
||||
{
|
||||
if (sum)
|
||||
{
|
||||
long totalRate = systemAdapters[i].GetIPStatistics().BytesReceived;
|
||||
Thread.Sleep(100);
|
||||
returnRate = returnRate + ((systemAdapters[i].GetIPStatistics().BytesReceived - totalRate) * 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
long totalRate = systemAdapters[i].GetIPStatistics().BytesReceived;
|
||||
Thread.Sleep(10);
|
||||
currentAdapterTransfers[i] = ((systemAdapters[i].GetIPStatistics().BytesReceived - totalRate) * 100);
|
||||
}
|
||||
}
|
||||
if(!sum)
|
||||
{
|
||||
returnRate = currentAdapterTransfers.Max();
|
||||
}
|
||||
|
||||
return returnRate;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the rate of output data flow from the host computer
|
||||
/// </summary>
|
||||
/// <param name="sum">Declares that the output rates of multiple adapters should be summed. If false, returns the value of the highest transfer</param>
|
||||
/// <returns>The number of bytes sent since the last run</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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")]
|
||||
Reference in New Issue
Block a user