Ejemplo n.º 1
0
        public void BytesTransmittedOverflowTest()
        {
            long expected = uint.MaxValue;

            RasLinkStatistics target = new RasLinkStatistics(expected, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TimeSpan.FromMilliseconds(0));
            long actual = target.BytesTransmitted;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 2
0
        public void BufferOverrunErrorTest()
        {
            long expected = 1;

            RasLinkStatistics target = new RasLinkStatistics(0, 0, 0, 0, 0, 0, 0, 0, 0, expected, 0, 0, 0, TimeSpan.FromMilliseconds(0));
            long actual = target.BufferOverrunError;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 3
0
        public void HardwareOverrunErrorOverflowTest()
        {
            long expected = uint.MaxValue;

            RasLinkStatistics target = new RasLinkStatistics(0, 0, 0, 0, 0, 0, 0, expected, 0, 0, 0, 0, 0, TimeSpan.FromMilliseconds(0));
            long actual = target.HardwareOverrunError;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 4
0
        public void CompressionRatioOutOverflowTest()
        {
            long expected = uint.MaxValue;

            RasLinkStatistics target = new RasLinkStatistics(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, expected, 0, TimeSpan.FromMilliseconds(0));
            long actual = target.CompressionRatioOut;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 5
0
        public void CompressionRatioInTest()
        {
            long expected = 1;

            RasLinkStatistics target = new RasLinkStatistics(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, expected, 0, 0, TimeSpan.FromMilliseconds(0));
            long actual = target.CompressionRatioIn;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 6
0
        public void BytesTransmittedTest()
        {
            long expected = 1;

            RasLinkStatistics target = new RasLinkStatistics(expected, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TimeSpan.FromMilliseconds(0));
            long actual = target.BytesTransmitted;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 7
0
        public void LinkSpeedTest()
        {
            long expected = 1;

            RasLinkStatistics target = new RasLinkStatistics(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, expected, TimeSpan.FromMilliseconds(0));
            long actual = target.LinkSpeed;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 8
0
        public void BytesReceivedTest()
        {
            long expected = 1;

            var target = new RasLinkStatistics(0, expected, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TimeSpan.FromMilliseconds(0));
            var actual = target.BytesReceived;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 9
0
        public void ConnectionDurationTest()
        {
            var expected = TimeSpan.FromMilliseconds(1);

            var target = new RasLinkStatistics(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, expected);
            var actual = target.ConnectionDuration;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 10
0
        public void BytesTransmittedOverflowTest()
        {
            long expected = uint.MaxValue;

            var target = new RasLinkStatistics(expected, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TimeSpan.FromMilliseconds(0));
            var actual = target.BytesTransmitted;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 11
0
        public void FramingErrorOverflowTest()
        {
            long expected = uint.MaxValue;

            var target = new RasLinkStatistics(0, 0, 0, 0, 0, 0, 0, 0, expected, 0, 0, 0, 0, TimeSpan.FromMilliseconds(0));
            var actual = target.FramingError;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 12
0
        public void HardwareOverrunErrorTest()
        {
            long expected = 1;

            var target = new RasLinkStatistics(0, 0, 0, 0, 0, 0, 0, expected, 0, 0, 0, 0, 0, TimeSpan.FromMilliseconds(0));
            var actual = target.HardwareOverrunError;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 13
0
        public void ConnectionDurationOverflowTest()
        {
            TimeSpan expected = TimeSpan.FromMilliseconds(uint.MaxValue);

            RasLinkStatistics target = new RasLinkStatistics(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, expected);
            TimeSpan          actual = target.ConnectionDuration;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 14
0
        public void BytesReceivedTest()
        {
            long expected = 1;

            RasLinkStatistics target = new RasLinkStatistics(0, expected, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TimeSpan.FromMilliseconds(0));
            long actual = target.BytesReceived;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 15
0
        public void BytesReceivedOverflowTest()
        {
            long expected = uint.MaxValue;

            RasLinkStatistics target = new RasLinkStatistics(0, expected, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TimeSpan.FromMilliseconds(0));
            long actual = target.BytesReceived;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 16
0
        public void GetLinkStatisticsTest()
        {
            var expected = new RasLinkStatistics(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TimeSpan.MinValue);

            var mock = new Mock <IRasHelper>();

            RasHelper.Instance = mock.Object;

            mock.Setup(o => o.GetLinkStatistics(It.IsAny <RasHandle>(), It.IsAny <int>())).Returns(expected);

            var target = new RasConnection();
            var actual = target.GetLinkStatistics();

            Assert.AreSame(expected, actual);
        }
Ejemplo n.º 17
0
        public void GetConnectionStatisticsTest()
        {
            RasLinkStatistics expected = new RasLinkStatistics(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TimeSpan.MinValue);

            Mock <IRasHelper> mock = new Mock <IRasHelper>();

            RasHelper.Default = mock.Object;

            mock.Setup(o => o.GetConnectionStatistics(It.IsAny <RasHandle>())).Returns(expected);

            RasConnection     target = new RasConnection();
            RasLinkStatistics actual = target.GetConnectionStatistics();

            Assert.AreSame(expected, actual);
        }
Ejemplo n.º 18
0
        public void CompressionRatioInTest()
        {
            long expected = 1;

            RasLinkStatistics target = new RasLinkStatistics(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, expected, 0, 0, TimeSpan.FromMilliseconds(0));
            long actual = target.CompressionRatioIn;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Retrieves accumulated statistics for the specified link in a RAS multilink connection.
        /// </summary>
        /// <param name="handle">The handle to the connection.</param>
        /// <param name="subEntryId">The one-based index that corresponds to the link for which to retrieve statistics.</param>
        /// <returns>A <see cref="DotRas.RasLinkStatistics"/> structure containing connection statistics.</returns>
        /// <exception cref="System.ArgumentException"><paramref name="subEntryId"/> must be greater than zero.</exception>
        /// <exception cref="DotRas.InvalidHandleException"><paramref name="handle"/> is a null reference (<b>Nothing</b> in Visual Basic) or an invalid handle.</exception>
        public RasLinkStatistics GetLinkStatistics(RasHandle handle, int subEntryId)
        {
            if (Utilities.IsHandleInvalidOrClosed(handle))
            {
                ThrowHelper.ThrowInvalidHandleException(handle, "handle", Resources.Argument_InvalidHandle);
            }

            if (subEntryId <= 0)
            {
                ThrowHelper.ThrowArgumentException("subEntryId", Resources.Argument_ValueCannotBeLessThanOrEqualToZero);
            }

            RasLinkStatistics retval = null;

            int size = Marshal.SizeOf(typeof(NativeMethods.RAS_STATS));

            NativeMethods.RAS_STATS stats = new NativeMethods.RAS_STATS();
            stats.size = size;

            IntPtr lpRasLinkStatistics = IntPtr.Zero;
            try
            {
                lpRasLinkStatistics = Marshal.AllocHGlobal(size);
                Marshal.StructureToPtr(stats, lpRasLinkStatistics, true);

                int ret = SafeNativeMethods.Instance.GetLinkStatistics(handle, subEntryId, lpRasLinkStatistics);
                if (ret == NativeMethods.SUCCESS)
                {
                    stats = Utilities.PtrToStructure<NativeMethods.RAS_STATS>(lpRasLinkStatistics);

                    retval = new RasLinkStatistics(
                        stats.bytesTransmitted,
                        stats.bytesReceived,
                        stats.framesTransmitted,
                        stats.framesReceived,
                        stats.crcError,
                        stats.timeoutError,
                        stats.alignmentError,
                        stats.hardwareOverrunError,
                        stats.framingError,
                        stats.bufferOverrunError,
                        stats.compressionRatioIn,
                        stats.compressionRatioOut,
                        stats.linkSpeed,
                        TimeSpan.FromMilliseconds(stats.connectionDuration));
                }
                else
                {
                    ThrowHelper.ThrowRasException(ret);
                }
            }
            catch (EntryPointNotFoundException)
            {
                ThrowHelper.ThrowNotSupportedException(Resources.Exception_NotSupportedOnPlatform);
            }
            finally
            {
                if (lpRasLinkStatistics != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(lpRasLinkStatistics);
                }
            }

            return retval;
        }
Ejemplo n.º 20
0
        public void GetLinkStatisticsTest()
        {
            RasLinkStatistics actual = target.GetLinkStatistics();

            Assert.IsNotNull(actual);
        }
Ejemplo n.º 21
0
        public void FramingErrorTest()
        {
            long expected = 1;

            RasLinkStatistics target = new RasLinkStatistics(0, 0, 0, 0, 0, 0, 0, 0, expected, 0, 0, 0, 0, TimeSpan.FromMilliseconds(0));
            long actual = target.FramingError;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 22
0
        public void BufferOverrunErrorOverflowTest()
        {
            long expected = uint.MaxValue;

            RasLinkStatistics target = new RasLinkStatistics(0, 0, 0, 0, 0, 0, 0, 0, 0, expected, 0, 0, 0, TimeSpan.FromMilliseconds(0));
            long actual = target.BufferOverrunError;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Handles timer for stats updates.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The event.</param>
        private void StatisticsTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (!_rasConnected)
            {
                return;
            }

            try
            {
                if (_currentConnection == null)
                {
                    return;
                }

                // Retrieve stats from the current connection
                RasLinkStatistics statistics = _currentConnection.GetConnectionStatistics();

                // Compare new values to old ones and get the current
                // data size been downloaded or uploaded
                var received = statistics.BytesReceived - _oldReceivedStat;
                var sent     = statistics.BytesTransmitted - _oldSentStat;

                // Add new data amount to the total
                _totalDownloaded += received;
                _totalUploaded   += sent;

                // Format the total stat. Adds units at the end of the string
                // 1.01 -> 1.01 KB/MB/GB/etc
                var totalDownloadedFormatted = SizeUtil.SizeSuffix(_totalDownloaded, 2);
                var totalUploadedFormatted   = SizeUtil.SizeSuffix(_totalUploaded, 2);

                // Format session stats
                var sessionDownloadedFormatted = SizeUtil.SizeSuffix(statistics.BytesReceived);
                var sessionUploadedFormatted   = SizeUtil.SizeSuffix(statistics.BytesTransmitted);

                // Calculate speed
                var downSpeed = Math.Round(received / 1024d, 2);
                var upSpeed   = Math.Round(sent / 1024d, 2);

                // Now the new data becomes the old data
                _oldReceivedStat = statistics.BytesReceived;
                _oldSentStat     = statistics.BytesTransmitted;

                // Format the duration of the connection
                var connDuration = $"{statistics.ConnectionDuration:hh\\:mm\\:ss}";

                // Update the UI
                _view.UpdateDownloadSpeed($"{downSpeed}");
                _view.UpdateUploadSpeed($"{upSpeed}");
                _view.UpdateSessionDownload($"{sessionDownloadedFormatted}");
                _view.UpdateSessionUpload($"{sessionUploadedFormatted}");
                _view.UpdateTotalDownloaded($"{totalDownloadedFormatted}");
                _view.UpdateTotalUploaded($"{totalUploadedFormatted}");
                _view.UpdateChart(downSpeed, upSpeed);
                _view.UpdateConnDuration(connDuration);
            }
            catch (Exception ex)
            {
                _view.UpdateToolStripStatus(ex.Message);
            }
        }
Ejemplo n.º 24
0
        public void CompressionRatioOutOverflowTest()
        {
            long expected = uint.MaxValue;

            RasLinkStatistics target = new RasLinkStatistics(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, expected, 0, TimeSpan.FromMilliseconds(0));
            long actual = target.CompressionRatioOut;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 25
0
        public void ConnectionDurationOverflowTest()
        {
            TimeSpan expected = TimeSpan.FromMilliseconds(uint.MaxValue);

            RasLinkStatistics target = new RasLinkStatistics(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, expected);
            TimeSpan actual = target.ConnectionDuration;

            Assert.AreEqual(expected, actual);
        }