示例#1
0
        /// <summary>Gets a value indicating whether the data plan status values are default values, or provided by the MNO.</summary>
        /// <value><c>true</c> if this instance is available; otherwise, <c>false</c>.</value>
        public static bool IsDefined(this NLM_DATAPLAN_STATUS status)
        {
            const uint NLM_UNKNOWN_DATAPLAN_STATUS = 0xFFFFFFFF;

            // usage data is valid only if both planUsage and lastUpdatedTime are valid
            if (status.UsageData.UsageInMegabytes != NLM_UNKNOWN_DATAPLAN_STATUS && (status.UsageData.LastSyncTime.dwHighDateTime != 0 || status.UsageData.LastSyncTime.dwLowDateTime != 0))
            {
                return(true);
            }
            if (status.DataLimitInMegabytes != NLM_UNKNOWN_DATAPLAN_STATUS)
            {
                return(true);
            }
            if (status.InboundBandwidthInKbps != NLM_UNKNOWN_DATAPLAN_STATUS)
            {
                return(true);
            }
            if (status.OutboundBandwidthInKbps != NLM_UNKNOWN_DATAPLAN_STATUS)
            {
                return(true);
            }
            if (status.NextBillingCycle.dwHighDateTime != 0 || status.NextBillingCycle.dwLowDateTime != 0)
            {
                return(true);
            }
            if (status.MaxTransferSizeInMegabytes != NLM_UNKNOWN_DATAPLAN_STATUS)
            {
                return(true);
            }
            return(false);
        }
示例#2
0
        /// <summary>
        /// Gets the data plan status for either a machine-wide internet connection , or the first-hop of routing to a specific destination
        /// on a connection. If an IPv4/IPv6 address is not specified, this method returns the data plan status of the connection used for
        /// machine-wide Internet connectivity.
        /// </summary>
        /// <param name="destIPAddr">
        /// The destination IPv4/IPv6 address. If <see langword="null"/>, this method will instead return the data plan status of the
        /// connection used for machine-wide Internet connectivity.
        /// </param>
        /// <returns>
        /// An NLM_DATAPLAN_STATUS structure that describes the data plan status associated with a connection used to route to a destination.
        /// If destIPAddr specifies a tunnel address, the first available data plan status in the interface stack is returned.
        /// </returns>
        public static NLM_DATAPLAN_STATUS GetConnectionDataPlanStatus(IPAddress destIPAddr = null)
        {
            var ptr  = destIPAddr != null ? new SafeCoTaskMemHandle(destIPAddr.GetAddressBytes()) : SafeCoTaskMemHandle.Null;
            var cost = new NLM_DATAPLAN_STATUS();

            (costmgr ?? (costmgr = (INetworkCostManager)Manager))?.GetDataPlanStatus(out cost, (IntPtr)ptr);
            return(cost);
        }
示例#3
0
        /// <summary>
        /// Gets the data plan status for either a machine-wide internet connection , or the first-hop of routing to a specific destination
        /// on a connection. If an IPv4/IPv6 address is not specified, this method returns the data plan status of the connection used for
        /// machine-wide Internet connectivity.
        /// </summary>
        /// <param name="destIPAddr">
        /// The destination IPv4/IPv6 address. If <see langword="null"/>, this method will instead return the data plan status of the
        /// connection used for machine-wide Internet connectivity.
        /// </param>
        /// <returns>
        /// An NLM_DATAPLAN_STATUS structure that describes the data plan status associated with a connection used to route to a destination.
        /// If destIPAddr specifies a tunnel address, the first available data plan status in the interface stack is returned.
        /// </returns>
        public static NLM_DATAPLAN_STATUS GetConnectionDataPlanStatus(IPAddress destIPAddr = null)
        {
            var addr = NLM_SOCKADDR.FromIPAddress(destIPAddr);
            var cost = new NLM_DATAPLAN_STATUS();

            (costmgr ?? (costmgr = (INetworkCostManager)Manager))?.GetDataPlanStatus(out cost, addr);
            return(cost);
        }
示例#4
0
        public void GetCostTest()
        {
            NLM_CONNECTION_COST ret = 0;

            Assert.That(() => coster.GetCost(out ret), Throws.Nothing);
            TestContext.WriteLine($"Cost:{ret}");
            Assert.That((int)ret, Is.GreaterThan(0));
            var status = new NLM_DATAPLAN_STATUS();

            Assert.That(() => coster.GetDataPlanStatus(out status), Throws.Nothing);
            Assert.That(status.InterfaceGuid, Is.Not.EqualTo(Guid.Empty));
            TestContext.WriteLine($"Guid:{status.InterfaceGuid}; Limit:{status.DataLimitInMegabytes:X}; Xfer:{status.MaxTransferSizeInMegabytes:X}");
        }