Example #1
0
        public static DataPlanInfo FromProfile(ConnectionProfile profile)
        {
            var planStatus = profile.GetDataPlanStatus();

            if (planStatus == null || (planStatus.DataLimitInMegabytes == null && planStatus.DataPlanUsage == null && planStatus.InboundBitsPerSecond == null &&
                                       planStatus.MaxTransferSizeInMegabytes == null && planStatus.NextBillingCycle == null && planStatus.OutboundBitsPerSecond == null))
            {
                return(null);
            }
            var dataPlan = new DataPlanInfo
            {
                DataLimitMegabytes    = planStatus.DataLimitInMegabytes ?? 0,
                InboundBitsPerSecond  = planStatus.InboundBitsPerSecond ?? 0,
                OutboundBitsPerSecond = planStatus.OutboundBitsPerSecond ?? 0,
                NextBillingCycle      = planStatus.NextBillingCycle
            };

            if (planStatus.DataPlanUsage != null)
            {
                dataPlan.MegabytesUsed = planStatus.DataPlanUsage.MegabytesUsed;
                dataPlan.LastSyncTime  = planStatus.DataPlanUsage.LastSyncTime;
            }
            else
            {
                dataPlan.LastSyncTime = null;
            }

            return(dataPlan);
        }
Example #2
0
    //
    //Get Connection Profile name and cost information
    //
    public string GetConnectionProfile(ConnectionProfile connectionProfile)
    {
        string connectionProfileInfo = string.Empty;

        if (connectionProfile != null)
        {
            connectionProfileInfo = "Profile Name : " + connectionProfile.ProfileName + "\n";

            //Get Dataplan Status information
            DataPlanStatus dataPlanStatus = connectionProfile.GetDataPlanStatus();
            connectionProfileInfo += GetDataPlanStatusInfo(dataPlanStatus);
        }

        return(connectionProfileInfo);
    }//end of method
        //
        //Get Connection Profile name and cost information
        //
        string GetConnectionProfile(ConnectionProfile connectionProfile)
        {
            string connectionProfileInfo = string.Empty;

            if (connectionProfile != null)
            {
                connectionProfileInfo = "Profile Name : " + connectionProfile.ProfileName + "\n";

                switch (connectionProfile.GetNetworkConnectivityLevel())
                {
                case NetworkConnectivityLevel.None:
                    connectionProfileInfo += "Connectivity Level : None\n";
                    break;

                case NetworkConnectivityLevel.LocalAccess:
                    connectionProfileInfo += "Connectivity Level : Local Access\n";
                    break;

                case NetworkConnectivityLevel.ConstrainedInternetAccess:
                    connectionProfileInfo += "Connectivity Level : Constrained Internet Access\n";
                    break;

                case NetworkConnectivityLevel.InternetAccess:
                    connectionProfileInfo += "Connectivity Level : Internet Access\n";
                    break;
                }

                //Get Connection Cost information
                ConnectionCost connectionCost = connectionProfile.GetConnectionCost();
                connectionProfileInfo += GetConnectionCostInfo(connectionCost);

                //Get Dataplan Status information
                DataPlanStatus dataPlanStatus = connectionProfile.GetDataPlanStatus();
                connectionProfileInfo += GetDataPlanStatusInfo(dataPlanStatus);

                //Get Network Security Settings
                NetworkSecuritySettings netSecuritySettings = connectionProfile.NetworkSecuritySettings;
                connectionProfileInfo += GetNetworkSecuritySettingsInfo(netSecuritySettings);
            }
            return(connectionProfileInfo);
        }
        private void UpdateNetworkUtilizationBehavior()
        {
            //https://docs.microsoft.com/en-us/previous-versions/windows/apps/jj835821(v=win.10)
            ConnectionProfile connections = NetworkInformation.GetInternetConnectionProfile();

            if (connections != null)
            {
                var cost     = connections.GetConnectionCost();
                var dataPlan = connections.GetDataPlanStatus();

                if ((bool)NepApp.Settings.GetSetting(AppSettings.AutomaticallyConserveDataWhenOnMeteredConnections))
                {
                    if (cost.NetworkCostType == NetworkCostType.Unrestricted || cost.NetworkCostType == NetworkCostType.Unknown)
                    {
                        NetworkUtilizationBehavior = NetworkDeterminedAppBehaviorStyle.Normal;
                    }
                    else if (cost.NetworkCostType == NetworkCostType.Fixed || cost.NetworkCostType == NetworkCostType.Variable)
                    {
                        if (!cost.Roaming && !cost.OverDataLimit)
                        {
                            NetworkUtilizationBehavior = NetworkDeterminedAppBehaviorStyle.Conservative;
                        }
                        else
                        {
                            NetworkUtilizationBehavior = NetworkDeterminedAppBehaviorStyle.OptIn;
                        }
                    }
                }
                else
                {
                    NetworkUtilizationBehavior = NetworkDeterminedAppBehaviorStyle.Normal;
                }

                RaisePropertyChanged(nameof(NetworkUtilizationBehavior));
            }
        }
Example #5
0
    public BandwidthMonitor()
    {
        ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();

        GetDataPlanStatusInfo(InternetConnectionProfile.GetDataPlanStatus());
    }
        //
        //Get Connection Profile name and cost information
        //
        string GetConnectionProfile(ConnectionProfile connectionProfile)
        {
            string connectionProfileInfo = string.Empty;

            if (connectionProfile != null)
            {
                connectionProfileInfo = "Profile Name : " + connectionProfile.ProfileName + "\n";

                switch (connectionProfile.GetNetworkConnectivityLevel())
                {
                case NetworkConnectivityLevel.None:
                    connectionProfileInfo += "Connectivity Level : None\n";
                    break;

                case NetworkConnectivityLevel.LocalAccess:
                    connectionProfileInfo += "Connectivity Level : Local Access\n";
                    break;

                case NetworkConnectivityLevel.ConstrainedInternetAccess:
                    connectionProfileInfo += "Connectivity Level : Constrained Internet Access\n";
                    break;

                case NetworkConnectivityLevel.InternetAccess:
                    connectionProfileInfo += "Connectivity Level : Internet Access\n";
                    break;
                }

                switch (connectionProfile.GetDomainConnectivityLevel())
                {
                case DomainConnectivityLevel.None:
                    connectionProfileInfo += "Domain Connectivity Level : None\n";
                    break;

                case DomainConnectivityLevel.Unauthenticated:
                    connectionProfileInfo += "Domain Connectivity Level : Unauthenticated\n";
                    break;

                case DomainConnectivityLevel.Authenticated:
                    connectionProfileInfo += "Domain Connectivity Level : Authenticated\n";
                    break;
                }

                //Get Connection Cost information
                ConnectionCost connectionCost = connectionProfile.GetConnectionCost();
                connectionProfileInfo += GetConnectionCostInfo(connectionCost);

                //Get Dataplan Status information
                DataPlanStatus dataPlanStatus = connectionProfile.GetDataPlanStatus();
                connectionProfileInfo += GetDataPlanStatusInfo(dataPlanStatus);

                //Get Network Security Settings
                NetworkSecuritySettings netSecuritySettings = connectionProfile.NetworkSecuritySettings;
                connectionProfileInfo += GetNetworkSecuritySettingsInfo(netSecuritySettings);

                //Get Wlan Connection Profile Details if this is a Wlan ConnectionProfile
                if (connectionProfile.IsWlanConnectionProfile)
                {
                    WlanConnectionProfileDetails wlanConnectionProfileDetails = connectionProfile.WlanConnectionProfileDetails;
                    connectionProfileInfo += GetWlanConnectionProfileDetailsInfo(wlanConnectionProfileDetails);
                }

                //Get Wwan Connection Profile Details if this is a Wwan ConnectionProfile
                if (connectionProfile.IsWwanConnectionProfile)
                {
                    WwanConnectionProfileDetails wwanConnectionProfileDetails = connectionProfile.WwanConnectionProfileDetails;
                    connectionProfileInfo += GetWwanConnectionProfileDetailsInfo(wwanConnectionProfileDetails);
                }

                //Get the Service Provider GUID
                if (connectionProfile.ServiceProviderGuid.HasValue)
                {
                    connectionProfileInfo += "====================\n";
                    connectionProfileInfo += "Service Provider GUID: " + connectionProfile.ServiceProviderGuid + "\n";
                }

                //Get the number of signal bars
                if (connectionProfile.GetSignalBars().HasValue)
                {
                    connectionProfileInfo += "====================\n";
                    connectionProfileInfo += "Signal Bars: " + connectionProfile.GetSignalBars() + "\n";
                }
            }
            return(connectionProfileInfo);
        }