コード例 #1
0
 static public bool?IsMeteredConnection()
 {
     try
     {
         ConnectionProfile internetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
         if (internetConnectionProfile == null)
         {
             return(null);
         }
         if (internetConnectionProfile.GetConnectionCost().NetworkCostType == NetworkCostType.Unknown ||
             internetConnectionProfile.GetConnectionCost().NetworkCostType == NetworkCostType.Unrestricted)
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }
     catch (Exception ee)
     {
         Debug.WriteLine(ee.ToString());
         return(false);
     }
 }
コード例 #2
0
        private NetworkType GetNetworkType(ConnectionProfile profile)
        {
            if (profile == null)
            {
                return(new NetworkTypeNone());
            }

            var level = profile.GetNetworkConnectivityLevel();

            if (level == NetworkConnectivityLevel.LocalAccess || level == NetworkConnectivityLevel.None)
            {
                return(new NetworkTypeNone());
            }

            var cost = profile.GetConnectionCost();

            if (cost != null && cost.Roaming)
            {
                return(new NetworkTypeMobileRoaming());
            }
            else if (profile.IsWlanConnectionProfile)
            {
                return(new NetworkTypeWiFi());
            }
            else if (profile.IsWwanConnectionProfile)
            {
                return(new NetworkTypeMobile());
            }

            // This is most likely cable connection.
            //return new NetworkTypeOther();
            return(new NetworkTypeWiFi());
        }
コード例 #3
0
        public void RetrieveNetworkStatus()
        {
            try
            {
                ConnectionProfile connectionProfile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();
                if (connectionProfile != null)
                {
                    switch (connectionProfile.NetworkAdapter.IanaInterfaceType)
                    {
                    case 71:
                    case 6:
                        this.NetworkStatus = NetworkStatus.WiFi;
                        break;

                    default:
                        if (connectionProfile.GetConnectionCost().ApproachingDataLimit || connectionProfile.GetConnectionCost().OverDataLimit || connectionProfile.GetConnectionCost().Roaming)
                        {
                            this.NetworkStatus = NetworkStatus.MobileRestricted;
                            break;
                        }
                        this.NetworkStatus = NetworkStatus.MobileUnrestricted;
                        break;
                    }
                }
                else
                {
                    this.NetworkStatus = NetworkStatus.None;
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.Error("Cannot retrieve network status", ex);
            }
        }
コード例 #4
0
        private void NetworkInformation_NetworkStatusChanged(object sender)
        {
            ConnectionProfile internetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();

            if (internetConnectionProfile == null)
            {
                // No connection
                _internetConnected = false;
                _internetThrottled = false;
            }
            else
            {
                var connectionCost  = internetConnectionProfile.GetConnectionCost();
                var connectionLevel = internetConnectionProfile.GetNetworkConnectivityLevel();

                if (connectionLevel != NetworkConnectivityLevel.InternetAccess)
                {
                    // No connection
                    _internetConnected = false;
                    _internetThrottled = false;
                }
                else if (connectionCost.Roaming || connectionCost.OverDataLimit)
                {
                    // Connection but throttled
                    _internetConnected = true;
                    _internetThrottled = true;
                }
                else
                {
                    // Full connection
                    _internetConnected = true;
                    _internetThrottled = false;
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Updates  the current object based on profile passed.
        /// </summary>
        /// <param name="profile">instance of <see cref="ConnectionProfile"/></param>
        public virtual void UpdateConnectionInformation(ConnectionProfile profile)
        {
            networkNames.Clear();

            if (profile == null)
            {
                ConnectionType      = ConnectionType.Unknown;
                ConnectivityLevel   = NetworkConnectivityLevel.None;
                IsInternetAvailable = false;
                ConnectionCost      = null;
                SignalStrength      = null;

                return;
            }

            switch (profile.NetworkAdapter.IanaInterfaceType)
            {
            case 6:
                ConnectionType = ConnectionType.Ethernet;
                break;

            case 71:
                ConnectionType = ConnectionType.WiFi;
                break;

            case 243:
            case 244:
                ConnectionType = ConnectionType.Data;
                break;

            default:
                ConnectionType = ConnectionType.Unknown;
                break;
            }

            ConnectivityLevel = profile.GetNetworkConnectivityLevel();
            ConnectionCost    = profile.GetConnectionCost();
            SignalStrength    = profile.GetSignalBars();

            var names = profile.GetNetworkNames();

            if (names?.Count > 0)
            {
                networkNames.AddRange(names);
            }

            switch (ConnectivityLevel)
            {
            case NetworkConnectivityLevel.None:
            case NetworkConnectivityLevel.LocalAccess:
                IsInternetAvailable = false;
                break;

            default:
                IsInternetAvailable = true;
                break;
            }
        }
コード例 #6
0
        public static async Task <ConnectionInfo> FromConnectionProfile(ConnectionProfile profile)
        {
            var connectionInfo = new ConnectionInfo
            {
                Name              = profile.ProfileName,
                IsWlan            = profile.IsWlanConnectionProfile,
                IsWwan            = profile.IsWwanConnectionProfile,
                ConnectivityLevel =
                    profile.GetNetworkConnectivityLevel().ToString(),
                DomainConnectivityLevel =
                    profile.GetDomainConnectivityLevel().ToString()
            };

            var costType = profile.GetConnectionCost();

            connectionInfo.CostType = costType.NetworkCostType.ToString();
            connectionInfo.Flags    = string.Format(
                "{0} {1} {2}",
                costType.ApproachingDataLimit ? "Approaching Data Limit" : string.Empty,
                costType.OverDataLimit ? "Over Data Limit" : string.Empty,
                costType.Roaming ? "Roaming" : string.Empty).Trim();

            connectionInfo.NetworkAdapterId = profile.ServiceProviderGuid;

            if (profile.NetworkAdapter != null)
            {
                connectionInfo.IncomingBitsPerSecond = (long)profile.NetworkAdapter.InboundMaxBitsPerSecond;
                connectionInfo.OutgoingBitsPerSecond = (long)profile.NetworkAdapter.OutboundMaxBitsPerSecond;
                connectionInfo.NetworkType           = profile.NetworkAdapter.NetworkItem.GetNetworkTypes().ToString();
            }

            if (profile.NetworkSecuritySettings != null)
            {
                connectionInfo.AuthenticationType = profile.NetworkSecuritySettings.NetworkAuthenticationType.ToString();
                connectionInfo.EncryptionType     = profile.NetworkSecuritySettings.NetworkEncryptionType.ToString();
            }

            connectionInfo.SignalBars = profile.GetSignalBars();

            connectionInfo.DataPlan = DataPlanInfo.FromProfile(profile);

            var usage =
                await
                profile.GetNetworkUsageAsync(
                    DateTimeOffset.Now.AddDays(-1),
                    DateTimeOffset.Now,
                    DataUsageGranularity.Total,
                    new NetworkUsageStates { Roaming = TriStates.DoNotCare, Shared = TriStates.DoNotCare });

            if (usage != null && usage.Count > 0)
            {
                connectionInfo.BytesReceivedLastDay = usage[0].BytesReceived;
                connectionInfo.BytesSentLastDay     = usage[0].BytesSent;
            }

            return(connectionInfo);
        }
コード例 #7
0
        static public AppNetworkState GetCurrentNetworkState()
        {
            ConnectionProfile connectionProfile = NetworkInformation.GetInternetConnectionProfile();

            if (connectionProfile == null || connectionProfile.GetNetworkConnectivityLevel() != NetworkConnectivityLevel.InternetAccess)
            {
                return(AppNetworkState.Unconnected);
            }
            if (connectionProfile.GetConnectionCost().NetworkCostType == NetworkCostType.Unrestricted)
            {
                return(AppNetworkState.Unrestricted);
            }
            else
            {
                return(AppNetworkState.Metered);
            }
        }
コード例 #8
0
        public static bool isRoaming()
        {
            try
            {
                ConnectionProfile internetConnectionProfile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();

                if (internetConnectionProfile.NetworkAdapter.IanaInterfaceType != 71)// Connection is not a Wi-Fi connection.
                {
                    return(internetConnectionProfile.GetConnectionCost().Roaming);
                }
            }
            catch
            {
                Debug.WriteLine("Cant recieve roaming on information");
            }

            return(false);
        }
        //
        //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);
        }
コード例 #10
0
        private void UpdateIsInternetConnected()
        {
            ConnectionProfile connectionProfile = NetworkInformation.GetInternetConnectionProfile();

            if (connectionProfile != null)
            {
                ConnectionName = connectionProfile.ProfileName;
                ConnectionCost = connectionProfile.GetConnectionCost();
                DataUsage      = connectionProfile.GetLocalUsage(DateTimeOffset.Now - TimeSpan.FromHours(24), DateTimeOffset.Now);

                switch (connectionProfile.GetNetworkConnectivityLevel())
                {
                case NetworkConnectivityLevel.None:
                    ConnectionStatus = "None";
                    break;

                case NetworkConnectivityLevel.LocalAccess:
                    ConnectionStatus = "Local access";
                    break;

                case NetworkConnectivityLevel.ConstrainedInternetAccess:
                    ConnectionStatus = "Constrained internet access";
                    break;

                case NetworkConnectivityLevel.InternetAccess:
                    ConnectionStatus = "Internet access";
                    break;
                }
            }
            else
            {
                ConnectionName   = "None";
                ConnectionStatus = "None";
                ConnectionCost   = null;
                DataUsage        = null;
            }
        }
コード例 #11
0
        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));
            }
        }
        //
        //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);
        }
コード例 #13
0
        private async Task LoadFilmDetails()
        {
            this.gFilmInfo.Visibility = Windows.UI.Xaml.Visibility.Visible;

            ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();

            ConnectionCost InternetConnectionCost = (InternetConnectionProfile == null ? null : InternetConnectionProfile.GetConnectionCost());

            Task <YouTubeUri> tYouTube = null;

            if (!String.IsNullOrEmpty(SelectedFilm.YoutubeTrailer) &&
                InternetConnectionProfile != null &&
                InternetConnectionProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess &&
                InternetConnectionCost != null &&
                InternetConnectionCost.NetworkCostType == NetworkCostType.Unrestricted)
            {
                tYouTube = MyToolkit.Multimedia.YouTube.GetVideoUriAsync(SelectedFilm.YoutubeTrailer, Config.TrailerQuality);
            }

            if (tYouTube != null)
            {
                try
                {
                    this.trailerUrl = await tYouTube;
                }
                catch { }
            }

            this.spFilmButtons.Visibility = this.btnTrailer.Visibility = btnPlay.Visibility = (trailerUrl != null ? Windows.UI.Xaml.Visibility.Visible : Windows.UI.Xaml.Visibility.Collapsed);
            this.mpTrailer.Visibility     = Windows.UI.Xaml.Visibility.Collapsed;
        }
コード例 #14
0
        /// <summary>
        /// Updates  the current object based on profile passed.
        /// </summary>
        /// <param name="profile">instance of <see cref="ConnectionProfile"/></param>
        public void UpdateConnectionInformation(ConnectionProfile profile)
        {
            LogService.Log(MLogLevel.LOG_LEVEL_INFO, "Updating connection info...");

            if (profile == null)
            {
                LogService.Log(MLogLevel.LOG_LEVEL_WARNING, "There is no connection profile");
                Reset();
                return;
            }

            LogService.Log(MLogLevel.LOG_LEVEL_INFO, "Getting interface type...");
            uint ianaInterfaceType = profile.NetworkAdapter?.IanaInterfaceType ?? 0;

            switch (ianaInterfaceType)
            {
            case 6:
                ConnectionType = ConnectionType.Ethernet;
                break;

            case 71:
                ConnectionType = ConnectionType.WiFi;
                break;

            case 243:
            case 244:
                ConnectionType = ConnectionType.Data;
                break;

            default:
                ConnectionType = ConnectionType.Unknown;
                break;
            }

            LogService.Log(MLogLevel.LOG_LEVEL_INFO, "Getting netework name...");
            NetworkName = profile.ProfileName;

            // Update the IP address
            LogService.Log(MLogLevel.LOG_LEVEL_INFO, "Getting IP address...");
            if (profile?.NetworkAdapter != null)
            {
                var hostname = NetworkInformation.GetHostNames().FirstOrDefault(hn =>
                                                                                hn?.IPInformation?.NetworkAdapter?.NetworkAdapterId == profile.NetworkAdapter.NetworkAdapterId);

                if (hostname != null)
                {
                    IpAddress = hostname.CanonicalName;
                }
            }

            LogService.Log(MLogLevel.LOG_LEVEL_INFO, "Getting connectivity level...");
            ConnectivityLevel = profile.GetNetworkConnectivityLevel();
            switch (ConnectivityLevel)
            {
            case NetworkConnectivityLevel.None:
            case NetworkConnectivityLevel.LocalAccess:
                IsInternetAvailable = false;
                break;

            case NetworkConnectivityLevel.InternetAccess:
            case NetworkConnectivityLevel.ConstrainedInternetAccess:
            default:
                IsInternetAvailable = true;
                break;
            }

            ConnectionCost = profile.GetConnectionCost();
            SignalStrength = profile.GetSignalBars();

            NetworkHelper.LogConnectivityInfo();
        }
コード例 #15
0
        private async Task LoadFilmDetails()
        {
            ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();

            ConnectionCost InternetConnectionCost = (InternetConnectionProfile == null ? null : InternetConnectionProfile.GetConnectionCost());

            Task <YouTubeUri> tYouTube = null;

            if (InternetConnectionProfile != null &&
                InternetConnectionProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess)
            {
                if (!String.IsNullOrEmpty(SelectedFilm.YoutubeTrailer) &&
                    InternetConnectionCost != null &&
                    InternetConnectionCost.NetworkCostType == NetworkCostType.Unrestricted)
                {
                    tYouTube = MyToolkit.Multimedia.YouTube.GetVideoUriAsync(SelectedFilm.YoutubeTrailer, Config.TrailerQuality);
                }
            }

            this.DataContext = this;

            CinemaData cd = new CinemaData(App.FilmCinemas[SelectedFilm.EDI]);

            dataLetter        = cd.GroupsByLetter;
            cvsCinemas.Source = dataLetter;

            gvZoomedInCinemas.SelectionChanged -= gvZoomedIn_SelectionChanged;
            gvZoomedInCinemas.SelectedItem      = null;
            (semanticZoom.ZoomedOutView as ListViewBase).ItemsSource = cd.CinemaHeaders;
            gvZoomedInCinemas.SelectionChanged += gvZoomedIn_SelectionChanged;

            semanticZoom.ViewChangeStarted -= semanticZoom_ViewChangeStarted;
            semanticZoom.ViewChangeStarted += semanticZoom_ViewChangeStarted;

            if (tYouTube != null)
            {
                try
                {
                    this.trailerUrl = await tYouTube;
                }
                catch { }
            }

            this.btnPlayTrailer.Visibility = btnPlay.Visibility = (trailerUrl != null ? Windows.UI.Xaml.Visibility.Visible : Windows.UI.Xaml.Visibility.Collapsed);
            this.mpTrailer.Visibility      = Windows.UI.Xaml.Visibility.Collapsed;
        }
コード例 #16
0
ファイル: ConnectionInformation.cs プロジェクト: eckeman/uwp
        /// <summary>
        /// Updates  the current object based on profile passed.
        /// </summary>
        /// <param name="profile">instance of <see cref="ConnectionProfile"/></param>
        public void UpdateConnectionInformation(ConnectionProfile profile)
        {
            if (profile == null)
            {
                Reset();

                return;
            }

            uint ianaInterfaceType = profile.NetworkAdapter?.IanaInterfaceType ?? 0;

            switch (ianaInterfaceType)
            {
            case 6:
                ConnectionType = ConnectionType.Ethernet;
                break;

            case 71:
                ConnectionType = ConnectionType.WiFi;
                break;

            case 243:
            case 244:
                ConnectionType = ConnectionType.Data;
                break;

            default:
                ConnectionType = ConnectionType.Unknown;
                break;
            }

            NetworkName = profile.ProfileName;

            // Update the IP address
            if (profile?.NetworkAdapter != null)
            {
                var hostname = NetworkInformation.GetHostNames().SingleOrDefault(hn =>
                                                                                 hn?.IPInformation?.NetworkAdapter?.NetworkAdapterId == profile.NetworkAdapter.NetworkAdapterId);

                if (hostname != null)
                {
                    IpAddress = hostname.CanonicalName;
                }
            }

            ConnectivityLevel = profile.GetNetworkConnectivityLevel();

            switch (ConnectivityLevel)
            {
            case NetworkConnectivityLevel.None:
            case NetworkConnectivityLevel.LocalAccess:
                IsInternetAvailable = false;
                break;

            case NetworkConnectivityLevel.InternetAccess:
            case NetworkConnectivityLevel.ConstrainedInternetAccess:
            default:
                IsInternetAvailable = true;
                break;
            }

            ConnectionCost = profile.GetConnectionCost();
            SignalStrength = profile.GetSignalBars();
        }