From 37cdefa0833c0207c0e2fca7e7ace7074d0c2a68 Mon Sep 17 00:00:00 2001 From: SolarRose Date: Fri, 28 Oct 2016 02:18:31 +0300 Subject: [PATCH 1/6] + ping provider --- .../PingReporter/IPingReporterProvider.cs | 8 +++ .../Reporter/PingReporter/PingProvider.cs | 65 +++++++++++++++++++ .../Reporter/PingReporter/PingResult.cs | 12 ++++ Shtirlitz.Library/Shtirlitz.Library.csproj | 14 ++-- Shtirlitz.Library/packages.config | 2 +- .../Common/PingResultCompareer.cs | 22 +++++++ .../Intergration/TestPingProvider.cs | 39 +++++++++++ Shtirlitz.Tests/Shtirlitz.Tests.csproj | 7 ++ Shtirlitz.Tests/packages.config | 1 + 9 files changed, 164 insertions(+), 6 deletions(-) create mode 100644 Shtirlitz.Library/Reporter/PingReporter/IPingReporterProvider.cs create mode 100644 Shtirlitz.Library/Reporter/PingReporter/PingProvider.cs create mode 100644 Shtirlitz.Library/Reporter/PingReporter/PingResult.cs create mode 100644 Shtirlitz.Tests/Reporter/PingReporter/Common/PingResultCompareer.cs create mode 100644 Shtirlitz.Tests/Reporter/PingReporter/Intergration/TestPingProvider.cs diff --git a/Shtirlitz.Library/Reporter/PingReporter/IPingReporterProvider.cs b/Shtirlitz.Library/Reporter/PingReporter/IPingReporterProvider.cs new file mode 100644 index 0000000..38af5d3 --- /dev/null +++ b/Shtirlitz.Library/Reporter/PingReporter/IPingReporterProvider.cs @@ -0,0 +1,8 @@ +namespace Shtirlitz.Reporter.PingReporter +{ + public interface IPingReporterProvider + { + bool Next(); + PingResult Current { get; } + } +} \ No newline at end of file diff --git a/Shtirlitz.Library/Reporter/PingReporter/PingProvider.cs b/Shtirlitz.Library/Reporter/PingReporter/PingProvider.cs new file mode 100644 index 0000000..81bae2a --- /dev/null +++ b/Shtirlitz.Library/Reporter/PingReporter/PingProvider.cs @@ -0,0 +1,65 @@ +using System.Net.NetworkInformation; + +namespace Shtirlitz.Reporter.PingReporter +{ + public class PingProvider : IPingReporterProvider + { + public PingResult Current { get; private set; } + + public PingProvider(string host, int count) + { + _host = host; + _count = count; + } + + public bool Next() + { + var result = false; + + if (_count > 0) + { + result = SendPing(result); + _count--; + } + + return result; + } + + private bool SendPing(bool result) + { + using (var ping = new Ping()) + { + var pingResult = ping.Send(_host); + _send++; + if (pingResult != null) + { + if (pingResult.Status == IPStatus.Success) + _receive++; + + Current = new PingResult + { + Host = _host, + Send = _send, + Receive = _receive, + Lost = _lost, + RoundtripTime = pingResult.RoundtripTime + }; + + result = true; + } + else + { + _lost++; + } + } + return result; + } + + private readonly string _host; + private int _count; + + private int _send; + private int _receive; + private int _lost; + } +} \ No newline at end of file diff --git a/Shtirlitz.Library/Reporter/PingReporter/PingResult.cs b/Shtirlitz.Library/Reporter/PingReporter/PingResult.cs new file mode 100644 index 0000000..7f425f6 --- /dev/null +++ b/Shtirlitz.Library/Reporter/PingReporter/PingResult.cs @@ -0,0 +1,12 @@ + +namespace Shtirlitz.Reporter.PingReporter +{ + public class PingResult + { + public string Host { get; set; } + public int Send { get; set; } + public int Receive { get; set; } + public int Lost { get; set; } + public long RoundtripTime { get; set; } + } +} \ No newline at end of file diff --git a/Shtirlitz.Library/Shtirlitz.Library.csproj b/Shtirlitz.Library/Shtirlitz.Library.csproj index a876bfe..a59d075 100644 --- a/Shtirlitz.Library/Shtirlitz.Library.csproj +++ b/Shtirlitz.Library/Shtirlitz.Library.csproj @@ -33,8 +33,9 @@ 4 - - $(SolutionDir)packages\DotNetZip.1.9.1.8\lib\net20\Ionic.Zip.dll + + ..\packages\DotNetZip.1.10.1\lib\net20\DotNetZip.dll + True @@ -44,6 +45,9 @@ + + + @@ -53,15 +57,15 @@ - - - {813AEDD8-7C91-41F0-A060-F000530168F6} Shtirlitz + + +