Permalink
Browse files

Source code, readme, and license files added.

  • Loading branch information...
keyvan committed Mar 26, 2012
1 parent a5368da commit 6ce9a84c2bf49c3583aee68bc7e571ee4f03c050
View
@@ -0,0 +1,49 @@
+#OS junk files
+[Tt]humbs.db
+*.DS_Store
+
+#Visual Studio files
+*.[Oo]bj
+*.exe
+*.pdb
+*.user
+*.aps
+*.pch
+*.vspscc
+*.vssscc
+*_i.c
+*_p.c
+*.ncb
+*.suo
+*.tlb
+*.tlh
+*.bak
+*.[Cc]ache
+*.ilk
+*.log
+*.lib
+*.sbr
+*.sdf
+ipch/
+obj/
+[Bb]in
+[Dd]ebug*/
+[Rr]elease*/
+[Nn][Dd]epend[Oo]ut*/
+Ankh.NoLoad
+
+#Tooling
+_ReSharper*/
+*.resharper
+[Tt]est[Rr]esult*
+
+#Project files
+[Bb]uild/
+
+#Subversion files
+.svn
+
+# Office Temp Files
+~$*
+
+visual-studio git
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{8994829D-5756-430E-AD78-94443AFCBF46}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>NetworkUtilization.Test</RootNamespace>
+ <AssemblyName>NetworkUtilization.Test</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <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|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <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.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Program.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\NetworkUtilization\NetworkUtilization.csproj">
+ <Project>{68C9E8B1-1553-4481-99A9-C1F06CA42380}</Project>
+ <Name>NetworkUtilization</Name>
+ </ProjectReference>
+ </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,20 @@
+using System;
+
+namespace NetworkUtilization.Test
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ Console.Title = "Network Utilization Counter for .NET";
+
+ string networkCard = "Realtek RTL8168B_8111B Family PCI-E Gigabit Ethernet NIC [NDIS 6.0]";
+
+ double utilization = UtilizationCounter.GetNetworkUtilization(networkCard);
+
+ Console.WriteLine(string.Format("Network Utilization = %{0}", utilization));
+
+ Console.ReadLine();
+ }
+ }
+}
@@ -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("NetworkUtilization.Test")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("NetworkUtilization.Test")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2012")]
+[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("466228dc-c4bc-45aa-bc26-a7727f127ec0")]
+
+// 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")]
@@ -0,0 +1,42 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetworkUtilization", "NetworkUtilization\NetworkUtilization.csproj", "{68C9E8B1-1553-4481-99A9-C1F06CA42380}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetworkUtilization.Test", "NetworkUtilization.Test\NetworkUtilization.Test.csproj", "{8994829D-5756-430E-AD78-94443AFCBF46}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Debug|Mixed Platforms = Debug|Mixed Platforms
+ Debug|x86 = Debug|x86
+ Release|Any CPU = Release|Any CPU
+ Release|Mixed Platforms = Release|Mixed Platforms
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {68C9E8B1-1553-4481-99A9-C1F06CA42380}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {68C9E8B1-1553-4481-99A9-C1F06CA42380}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {68C9E8B1-1553-4481-99A9-C1F06CA42380}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {68C9E8B1-1553-4481-99A9-C1F06CA42380}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {68C9E8B1-1553-4481-99A9-C1F06CA42380}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {68C9E8B1-1553-4481-99A9-C1F06CA42380}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {68C9E8B1-1553-4481-99A9-C1F06CA42380}.Release|Any CPU.Build.0 = Release|Any CPU
+ {68C9E8B1-1553-4481-99A9-C1F06CA42380}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {68C9E8B1-1553-4481-99A9-C1F06CA42380}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {68C9E8B1-1553-4481-99A9-C1F06CA42380}.Release|x86.ActiveCfg = Release|Any CPU
+ {8994829D-5756-430E-AD78-94443AFCBF46}.Debug|Any CPU.ActiveCfg = Debug|x86
+ {8994829D-5756-430E-AD78-94443AFCBF46}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
+ {8994829D-5756-430E-AD78-94443AFCBF46}.Debug|Mixed Platforms.Build.0 = Debug|x86
+ {8994829D-5756-430E-AD78-94443AFCBF46}.Debug|x86.ActiveCfg = Debug|x86
+ {8994829D-5756-430E-AD78-94443AFCBF46}.Debug|x86.Build.0 = Debug|x86
+ {8994829D-5756-430E-AD78-94443AFCBF46}.Release|Any CPU.ActiveCfg = Release|x86
+ {8994829D-5756-430E-AD78-94443AFCBF46}.Release|Mixed Platforms.ActiveCfg = Release|x86
+ {8994829D-5756-430E-AD78-94443AFCBF46}.Release|Mixed Platforms.Build.0 = Release|x86
+ {8994829D-5756-430E-AD78-94443AFCBF46}.Release|x86.ActiveCfg = Release|x86
+ {8994829D-5756-430E-AD78-94443AFCBF46}.Release|x86.Build.0 = Release|x86
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{68C9E8B1-1553-4481-99A9-C1F06CA42380}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>NetworkUtilization</RootNamespace>
+ <AssemblyName>NetworkUtilization</AssemblyName>
+ <TargetFrameworkVersion>v4.0</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.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="UtilizationCounter.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,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("NetworkUtilization")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("NetworkUtilization")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2012")]
+[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("ca11f1f0-498a-4229-a3e2-4d42d30996d6")]
+
+// 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")]
@@ -0,0 +1,38 @@
+using System.Diagnostics;
+
+namespace NetworkUtilization
+{
+ public static class UtilizationCounter
+ {
+ public static double GetNetworkUtilization(string networkCard)
+ {
+ const int numberOfIterations = 10;
+
+ PerformanceCounter bandwidthCounter =
+ new PerformanceCounter("Network Interface", "Current Bandwidth", networkCard);
+
+ float bandwidth = bandwidthCounter.NextValue();
+
+ PerformanceCounter dataSentCounter =
+ new PerformanceCounter("Network Interface", "Bytes Sent/sec", networkCard);
+ PerformanceCounter dataReceivedCounter =
+ new PerformanceCounter("Network Interface", "Bytes Received/sec", networkCard);
+
+ float sendSum = 0;
+ float receiveSum = 0;
+
+ for (int index = 0; index < numberOfIterations; index++)
+ {
+ sendSum += dataSentCounter.NextValue();
+ receiveSum += dataReceivedCounter.NextValue();
+ }
+
+ float dataSent = sendSum;
+ float dataReceived = receiveSum;
+
+ double utilization = (8 * (dataSent + dataReceived)) / (bandwidth * numberOfIterations) * 100;
+
+ return utilization;
+ }
+ }
+}
View
0 README
No changes.
Oops, something went wrong.

0 comments on commit 6ce9a84

Please sign in to comment.