예제 #1
0
        public static async Task <AppConstants.NetworkConnectionType> DetermineInternetConnection()
        {
            ConnectionProfile        connectionProfile = NetworkInformation.GetInternetConnectionProfile();
            NetworkConnectivityLevel level             = connectionProfile.GetNetworkConnectivityLevel();

            if (level != NetworkConnectivityLevel.InternetAccess)
            {
                await ShowMessageDialog("You are not connected to the internet. Check your connection settings.", "No Internet Connection");

                throw new Exception("No internet connection");
            }

            if (connectionProfile.IsWwanConnectionProfile)
            {
                return(AppConstants.NetworkConnectionType.Cellular);
            }
            else if (connectionProfile.IsWlanConnectionProfile)
            {
                return(AppConstants.NetworkConnectionType.WiFi);
            }
            else
            {
                return(AppConstants.NetworkConnectionType.WiFi);
            }
        }
예제 #2
0
        private static bool CheckNetworkAvailability(NetworkConnectivityLevel minimumLevelRequired = NetworkConnectivityLevel.InternetAccess)
        {
            var profile = NetworkInformation.GetInternetConnectionProfile();

            IsNetworkConnectionAvaliable = (profile != null && profile.GetNetworkConnectivityLevel() >= minimumLevelRequired);
            return(IsNetworkConnectionAvaliable);
        }
예제 #3
0
        public static string GetNetWorkName()
        {
            bool isConnected = false;

            string            InternetType = null;
            ConnectionProfile profile      = NetworkInformation.GetInternetConnectionProfile();

            if (profile == null)
            {
                InternetType = InternetStatus.None;
            }
            else
            {
                NetworkConnectivityLevel cl = profile.GetNetworkConnectivityLevel();
                isConnected = (cl != NetworkConnectivityLevel.None);
            }
            if (!isConnected)
            {
                return(InternetStatus.None);
            }
            else if (profile.IsWlanConnectionProfile)
            {
                profile.GetNetworkNames();
                InternetType = profile.ProfileName.ToString();
            }
            else
            {
                InternetType = InternetStatus.Lan;
            }
            return(InternetType);
        }
예제 #4
0
        private async void NetworkStatusChange(object sender)
        {
            ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile();

            if (profile != null)
            {
                NetworkConnectivityLevel connection = profile.GetNetworkConnectivityLevel();
                if (connection == NetworkConnectivityLevel.InternetAccess)
                {
                    await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        // There is an active connection
                        QueriesButton.IsEnabled = true;
                    });

                    return;
                }
            }

            await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                QueriesButton.IsEnabled = false;
                if (SubPage.Content.GetType() == typeof(QueriesPage))
                {
                    // TODO: Inapp toast feedback
                    NavigateSubPage(typeof(MyPage));
                }
            });
        }
예제 #5
0
        public MainPage()
        {
            this.InitializeComponent();

            ranOnLaunchInternetTasks        = false;
            currentNetworkConnectivityLevel = NetworkInformation.GetInternetConnectionProfile().GetNetworkConnectivityLevel();
            Window.Current.Activated       += Current_Activated;

            NetworkInformation.NetworkStatusChanged += NetworkInformation_NetworkStatusChanged;

            string deviceFamily = AnalyticsInfo.VersionInfo.DeviceFamily;

            if (deviceFamily.Contains("Mobile"))
            {
                device = Device.Mobile;
            }
            else if (deviceFamily.Contains("Desktop"))
            {
                device = Device.Desktop;
            }
            else
            {
                device = Device.Other;
            }

            mediaPlayer              = new MediaPlayer();
            mediaPlayer.MediaEnded  += MediaPlayer_MediaEnded;
            mediaPlayer.MediaFailed += MediaPlayer_MediaFailed;
            mediaPlayerElement.SetMediaPlayer(mediaPlayer);
            ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;
            httpClient           = new HttpClient();
            appleMovieDownloader = new AppleMovieDownloader(httpClient);
            sunrise          = DateTime.MinValue;
            sunset           = DateTime.MinValue;
            lastPositions    = new Queue <TimeSpan>();
            SpotifyHelper    = new SpotifyHelper();
            HueHelper        = new HueHelper();
            AirQualityHelper = new AirQualityHelper();
            CalendarHelper   = new CalendarHelper();

            rotationBuffer = 0;
            lightMode      = LightMode.Brightness;

            if (device == Device.Desktop)
            {
                dial = RadialController.CreateForCurrentView();
                dial.RotationResolutionInDegrees = 5;
                dial.UseAutomaticHapticFeedback  = false;
                dialConfig            = RadialControllerConfiguration.GetForCurrentView();
                menuItems             = new List <RadialControllerMenuItem>();
                isWindowFocused       = true;
                dial.ButtonClicked   += Dial_ButtonClicked;
                dial.RotationChanged += Dial_RotationChanged;
                dial.ControlAcquired += Dial_ControlAcquired;
                dial.ControlLost     += Dial_ControlLost;
            }
        }
예제 #6
0
        public static bool IsNetworkAvailable(NetworkConnectivityLevel minimumLevelRequired = NetworkConnectivityLevel.InternetAccess)
        {
            ConnectionProfile profile =
                NetworkInformation.GetInternetConnectionProfile();

            NetworkConnectivityLevel level =
                profile.GetNetworkConnectivityLevel();

            return(level >= minimumLevelRequired);
        }
예제 #7
0
        /// <summary>
        ///     네트워크
        /// </summary>
        /// <returns></returns>
        public override bool GetAvaliableConnection()
        {
            ConnectionProfile internetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();

            if (internetConnectionProfile == null)
            {
                return(false);
            }
            NetworkConnectivityLevel ncl = internetConnectionProfile.GetNetworkConnectivityLevel();

            return(ncl == NetworkConnectivityLevel.InternetAccess);
        }
예제 #8
0
        private async void NetworkInformation_NetworkStatusChanged(object sender)
        {
            currentNetworkConnectivityLevel = NetworkInformation.GetInternetConnectionProfile().GetNetworkConnectivityLevel();

            if (currentNetworkConnectivityLevel == NetworkConnectivityLevel.InternetAccess)
            {
                if (!ranOnLaunchInternetTasks)
                {
                    await RunOnLaunchInternetTasks();
                }
            }
        }
예제 #9
0
        public SpotifyHelper()
        {
            httpClient               = new HttpClient();
            Available                = true;
            TokenExpireTime          = null;
            AutomaticallyRefreshInfo = false;
            cancellationTokenSource  = new CancellationTokenSource();

            currentNetworkConnectivityLevel = NetworkInformation.GetInternetConnectionProfile().GetNetworkConnectivityLevel();
            Available = currentNetworkConnectivityLevel == NetworkConnectivityLevel.InternetAccess;
            NetworkInformation.NetworkStatusChanged += NetworkInformation_NetworkStatusChanged;
        }
        public bool IsInternetAvailable()
        {
            bool isConnected = NetworkInterface.GetIsNetworkAvailable();

            if (isConnected)
            {
                ConnectionProfile        internetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
                NetworkConnectivityLevel connection = internetConnectionProfile.GetNetworkConnectivityLevel();
                return(connection != NetworkConnectivityLevel.None && connection != NetworkConnectivityLevel.LocalAccess);
            }
            return(false);
        }
예제 #11
0
        public static bool IsNetworkAvailable()
        {
            ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();

            if (InternetConnectionProfile == null)
            {
                return(false);
            }

            NetworkConnectivityLevel level = InternetConnectionProfile.GetNetworkConnectivityLevel();

            return(level == NetworkConnectivityLevel.InternetAccess);
        }
예제 #12
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            loadingText.Text = "checking internet connection";
            ConnectionProfile        connectionProfile = NetworkInformation.GetInternetConnectionProfile();
            NetworkConnectivityLevel level             = connectionProfile.GetNetworkConnectivityLevel();

            if (level != NetworkConnectivityLevel.InternetAccess)
            {
                MessageDialog message = new MessageDialog("You are not connected to the internet. Check your connection setings then restart the app.");
                await message.ShowAsync();

                loadingText.Text = "no internet connection found";
                return;
            }

            loadingText.Text = "loading twitch emotes";
            string globalString = await AppConstants.GetWebData(new Uri("http://www.twitchemotes.com/global.json"));

            JObject globalEmotes = JObject.Parse(globalString);

            foreach (KeyValuePair <string, JToken> o in globalEmotes)
            {
                AppConstants.emotes.Add(new Emote((string)o.Key, (string)o.Value["url"], (string)o.Value["description"]));
            }

            string subscriberString = await AppConstants.GetWebData(new Uri("http://www.twitchemotes.com/subscriber.json"));

            JObject subscriberEmotes = JObject.Parse(subscriberString);

            foreach (KeyValuePair <string, JToken> o in subscriberEmotes)
            {
                AppConstants.subscriberEmotes.Add(new SubscriberEmote((string)o.Key, (JObject)o.Value["emotes"], (string)o.Value["_badge"], (long)o.Value["_set"]));
            }

            string setString = await AppConstants.GetWebData(new Uri("http://twitchemotes.com/api/sets"));

            JObject setMap = JObject.Parse(setString);

            foreach (KeyValuePair <string, JToken> o in setMap)
            {
                AppConstants.sets.Add(long.Parse(o.Key), (string)o.Value);
            }

            StorageFolder roamingFolder = ApplicationData.Current.RoamingFolder;

            loadingText.Text = "looking for settings";
            await LoadQualitySettings(roamingFolder);

            loadingText.Text = "looking for users data";
            await LoadUserData(roamingFolder);
        }
예제 #13
0
        private String NetScans()
        {
            ConnectionProfile        connectionProfile = NetworkInformation.GetInternetConnectionProfile();
            NetworkConnectivityLevel concon            = new NetworkConnectivityLevel();

            try
            {
                concon = connectionProfile.GetNetworkConnectivityLevel();
            }
            catch
            {
            }
            return(concon.ToString());
        }
예제 #14
0
        public static bool IsNetConnected()
        {
            ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile();

            if (profile == null)
            {
                _isconnected = false;
            }
            else
            {
                NetworkConnectivityLevel networkConnectivityLevel = profile.GetNetworkConnectivityLevel();
                _isconnected = (networkConnectivityLevel != NetworkConnectivityLevel.None);
            }
            return(_isconnected);
        }
예제 #15
0
        //查看是否连接了网络
        public static Boolean IsConnectedToInternet()
        {
            bool connected = false;

            ConnectionProfile cp = NetworkInformation.GetInternetConnectionProfile();

            if (cp != null)
            {
                NetworkConnectivityLevel cl = cp.GetNetworkConnectivityLevel();

                connected = cl == NetworkConnectivityLevel.InternetAccess;
            }

            return(connected);
        }
        private static Boolean IsNetworkAvailable()
        {
            ConnectionProfile internetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();

            if (internetConnectionProfile == null)
            {
                return(false);
            }
            NetworkConnectivityLevel networkConnectivityLevel = internetConnectionProfile.GetNetworkConnectivityLevel();

            if (networkConnectivityLevel == NetworkConnectivityLevel.InternetAccess)
            {
                return(true);
            }
            return(networkConnectivityLevel == NetworkConnectivityLevel.ConstrainedInternetAccess);
        }
예제 #17
0
        private NetworkConnectivityLevel GetConnectivityFromManager()
        {
            NetworkConnectivityLevel bestConnectivityLevel = NetworkConnectivityLevel.None;

#pragma warning disable CS0618 // Type or member is obsolete
            foreach (var info in _connectivityManager.GetAllNetworkInfo())
#pragma warning restore CS0618 // Type or member is obsolete
            {
                var networkConnectivityLevel = GetConnectivityFromNetworkInfo(info);
                if (networkConnectivityLevel > bestConnectivityLevel)
                {
                    bestConnectivityLevel = networkConnectivityLevel;
                }
            }
            return(bestConnectivityLevel);
        }
예제 #18
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        ///



        //CHeck for Internet Access
        public async Task CheckInternet()
        {
            isConnected = NetworkInterface.GetIsNetworkAvailable();
            if (!isConnected)
            {
                await new MessageDialog("No internet connection avaliable.").ShowAsync();
            }
            else
            {
                ConnectionProfile        InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
                NetworkConnectivityLevel connection = InternetConnectionProfile.GetNetworkConnectivityLevel();
                if (connection == NetworkConnectivityLevel.None || connection == NetworkConnectivityLevel.LocalAccess)
                {
                    isConnected = false;
                }
            }
        }
예제 #19
0
        public bool IsConnectedToInternet()
        {
            NetworkInformation.NetworkStatusChanged += NetworkInformation_NetworkStatusChanged;

            bool connected = false;

            ConnectionProfile cp = NetworkInformation.GetInternetConnectionProfile();

            if (cp != null)
            {
                NetworkConnectivityLevel cl = cp.GetNetworkConnectivityLevel();

                connected = cl == NetworkConnectivityLevel.InternetAccess;
            }

            return(connected);
        }
예제 #20
0
        public bool GetIsInternetConnected()
        {
            ConnectionProfile internetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();

            if (internetConnectionProfile == null)
            {
                return(false);
            }

            NetworkConnectivityLevel networkConnectivityLevel = internetConnectionProfile.GetNetworkConnectivityLevel();

            if (networkConnectivityLevel == NetworkConnectivityLevel.InternetAccess)
            {
                return(true);
            }

            return(networkConnectivityLevel == NetworkConnectivityLevel.ConstrainedInternetAccess);
        }
예제 #21
0
 public NetworkAvailableHelper()
 {
     NetworkInformation.NetworkStatusChanged += (s) =>
     {
         ConnectionProfile internetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
         ConnectionTypes   conn = ConnectionTypes.None;
         if (internetConnectionProfile != null)
         {
             NetworkConnectivityLevel connectionLevel = internetConnectionProfile.GetNetworkConnectivityLevel();
             conn = (connectionLevel == NetworkConnectivityLevel.InternetAccess) ? ConnectionTypes.Internet : ConnectionTypes.LocalNetwork;
         }
         if (AvailabilityChanged != null)
         {
             try { AvailabilityChanged(conn); }
             catch { }
         }
     };
 }
예제 #22
0
        public static bool IsInternetConnected()
        {
            bool isConnected = NetworkInterface.GetIsNetworkAvailable();

            if (!isConnected)
            {
                return(false);
            }
            else
            {
                ConnectionProfile        internetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
                NetworkConnectivityLevel connection = internetConnectionProfile.GetNetworkConnectivityLevel();
                if (connection == NetworkConnectivityLevel.None || connection == NetworkConnectivityLevel.LocalAccess)
                {
                    return(false);
                }
                return(true);
            }
        }
예제 #23
0
        /* Explained problem with async and await
         * http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html
         * */


        private async void CheckInternet()
        {
            isConnected = NetworkInterface.GetIsNetworkAvailable();
            if (!isConnected)
            {
                await new MessageDialog("No internet connection is avaliable.").ShowAsync();
            }

            else
            {
                ConnectionProfile        InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
                NetworkConnectivityLevel connection = InternetConnectionProfile.GetNetworkConnectivityLevel();
                if (connection == NetworkConnectivityLevel.InternetAccess)
                {
                    isConnected = true;
                }
                else
                {
                    isConnected = false;
                    await new MessageDialog("No internet connection is avaliable.").ShowAsync();
                }
            }
        }
예제 #24
0
        public void TestIsInternetAvailable(NetworkConnectivityLevel networkConnectivity)
        {
            // Setup any objects and mocks.
            var           mockConnectionProfile  = new Mock <IKConnectionProfile>();
            var           mockNetworkInformation = new Mock <IKNetworkInformation>();
            NetworkStatus networkStatus          = new NetworkStatus(mockNetworkInformation.Object);

            mockConnectionProfile
            .Setup(obj => obj.GetNetworkConnectivityLevel())
            .Returns(networkConnectivity);
            mockNetworkInformation
            .Setup(obj => obj.GetInternetConnectionProfile())
            .Returns(mockConnectionProfile.Object);

            // Call the method under test.
            bool available = networkStatus.IsInternetAvailable();
            bool expected  = networkConnectivity == NetworkConnectivityLevel.InternetAccess;

            // Verify the results produced.
            Assert.AreEqual(
                expected, available,
                "Function is not reporting the correct status");
        }
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            var connectionProfile          = NetworkInformation.GetInternetConnectionProfile();
            NetworkConnectivityLevel level = connectionProfile.GetNetworkConnectivityLevel();
            var message = level == NetworkConnectivityLevel.InternetAccess ? "Connected to Internet" : "Not connected to Internet";

            string xml = $@"
            <toast activationType='foreground' launch='args'>
                <visual>
                    <binding template='ToastGeneric'>
                        <text>{message}</text>
                    </binding>
                </visual>
            </toast>";

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);

            ToastNotification notification = new ToastNotification(doc);
            ToastNotifier     notifier     = ToastNotificationManager.CreateToastNotifier();

            notifier.Show(notification);
        }
예제 #26
0
        private bool GetInternetConnectstate()
        {
            bool isConnected          = false;
            ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile();

            if (profile == null)
            {
                return(false);
            }
            else
            {
                NetworkConnectivityLevel cl = profile.GetNetworkConnectivityLevel();
                isConnected = !((cl == NetworkConnectivityLevel.None) || (cl == NetworkConnectivityLevel.LocalAccess));
            }

            if (!isConnected)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
예제 #27
0
 private void NetworkInformation_NetworkStatusChanged(object sender)
 {
     currentNetworkConnectivityLevel = NetworkInformation.GetInternetConnectionProfile().GetNetworkConnectivityLevel();
     Available = currentNetworkConnectivityLevel == NetworkConnectivityLevel.InternetAccess;
 }
예제 #28
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session.  The state will be null the first time a page is visited.</param>
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            PPanel.Visibility = Visibility.Visible;
            DatabaseHelperClass db      = new DatabaseHelperClass();
            List <BitmapImage>  bmi     = new List <BitmapImage>();
            List <Results>      results = new List <Results>();

            BitmapImage bit = new BitmapImage();

            bit.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
            bit.UriSource     = new Uri("ms-appx:///Assets/back.jpg");

            for (int i = 0; i < 9; i++)
            {
                bmi.Add(bit);
            }

            //Checking Network
            bool isConnected = NetworkInterface.GetIsNetworkAvailable();

            if (isConnected)
            {
                // Do Nothing
            }
            else
            {
                ConnectionProfile        InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
                NetworkConnectivityLevel connection = InternetConnectionProfile.GetNetworkConnectivityLevel();
                if (connection == NetworkConnectivityLevel.None || connection == NetworkConnectivityLevel.LocalAccess)
                {
                    isConnected = false;
                }
            }
            var roamingSettings = ApplicationData.Current.RoamingSettings;

            //Nettwork availability checked

            if (roamingSettings.Values["First"].ToString() == "0")
            {
                if (!isConnected)
                {
                    if ((db.ReadEvents() as List <EventClass>).Count == 0)
                    {
                        ShowPopupAsync();
                    }
                    else
                    {
                        HidePopupAsync();
                    }
                }
                else
                {
                    //Checking Database
                    if ((db.ReadEvents() as List <EventClass>).Count == 0)
                    {
                        //Start Of EventsAPI call
                        db.DeleteAllEvents();
                        List <EventClass> listevents = new List <EventClass>();
                        listevents = await GetEventsAPIAsync();

                        db.Insert(listevents);
                        //End of Events API Call
                    }
                    else
                    {
                        RefInBack = true;
                    }

                    //Start Of Insta API Call
                    insta = await GetInstaAsync();

                    bmi.Clear();
                    foreach (Datum d in insta.data)
                    {
                        BitmapImage b = new BitmapImage();
                        b.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
                        b.UriSource     = new Uri(d.images.thumbnail.url);

                        bmi.Add(b);
                    }
                    //End Of Insta API call and formatting

                    results = await GetResultsAsync(); //Results API Call

                    roamingSettings.Values["First"] = "1";
                }
            }
            else
            {
                insta = await GetInstaAsync();

                bmi.Clear();
                foreach (Datum d in insta.data)
                {
                    BitmapImage b = new BitmapImage();
                    b.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
                    b.UriSource     = new Uri(d.images.thumbnail.url);

                    bmi.Add(b);
                }

                results = await GetResultsAsync();
            }

            List <EventClass> l = new List <EventClass>();

            l = db.ReadEvents();

            List <EventClass> Day1_Events = new List <EventClass>();
            List <EventClass> Day2_Events = new List <EventClass>();
            List <EventClass> Day3_Events = new List <EventClass>();
            List <EventClass> Day4_Events = new List <EventClass>();

            Day1_Events = (l.Where(p => p.Day == "1").ToList()).OrderBy(eve => eve.Name).ToList();
            Day2_Events = (l.Where(p => p.Day == "2").ToList()).OrderBy(eve => eve.Name).ToList();
            Day3_Events = (l.Where(p => p.Day == "3").ToList()).OrderBy(eve => eve.Name).ToList();
            Day4_Events = (l.Where(p => p.Day == "4").ToList()).OrderBy(eve => eve.Name).ToList();

            List <Day> list = new List <Day>();
            Day        day1 = new Day();

            day1.Events = Day1_Events;
            day1.day    = "day 1";

            Day day2 = new Day();

            day2.Events = Day2_Events;
            day2.day    = "day 2";

            Day day3 = new Day();

            day3.Events = Day3_Events;
            day3.day    = "day 3";

            Day day4 = new Day();

            day4.Events = Day4_Events;
            day4.day    = "day 4";


            list.Add(day1);
            list.Add(day2);
            list.Add(day3);
            list.Add(day4);



            this.defaultViewModel["Days"]    = list;
            this.defaultViewModel["Insta"]   = bmi;
            this.defaultViewModel["Results"] = results;

            PPanel.Visibility = Visibility.Collapsed;
        }
예제 #29
0
        private NetworkType GetConnectionGeneration()
        {
            bool        isConnected = false;
            NetworkType nt          = NetworkType.Unknown;

            ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile();

            if (profile == null)
            {
                nt = NetworkType.NotConnected;
            }
            else
            {
                NetworkConnectivityLevel cl = profile.GetNetworkConnectivityLevel();
                isConnected = (cl != NetworkConnectivityLevel.None);
            }

            if (!isConnected)
            {
                nt = NetworkType.NotConnected;
                return(nt);
            }

            if (profile.IsWwanConnectionProfile)
            {
                if (null == profile.WwanConnectionProfileDetails)
                {
                    nt = NetworkType.Unknown;
                }
                WwanDataClass connectionClass = profile.WwanConnectionProfileDetails.GetCurrentDataClass();
                switch (connectionClass)
                {
                // 2G
                case WwanDataClass.Gprs:
                case WwanDataClass.Edge:
                    nt = NetworkType.Wwan2G;
                    break;

                // 3G
                case WwanDataClass.Cdma1xRtt:
                case WwanDataClass.Cdma1xEvdo:
                case WwanDataClass.Cdma1xEvdoRevA:
                case WwanDataClass.Cdma1xEvdv:
                case WwanDataClass.Cdma3xRtt:
                case WwanDataClass.Cdma1xEvdoRevB:
                case WwanDataClass.CdmaUmb:
                case WwanDataClass.Hsdpa:
                case WwanDataClass.Hsupa:
                case WwanDataClass.Umts:
                    nt = NetworkType.Wwan3G;
                    break;

                // 4G
                case WwanDataClass.LteAdvanced:
                    nt = NetworkType.Wwan4G;
                    break;

                // No Internet Connection
                case WwanDataClass.None:
                    nt = NetworkType.Unknown;
                    break;

                case WwanDataClass.Custom:
                default:
                    nt = NetworkType.Unknown;
                    break;
                }
            }
            else if (profile.IsWlanConnectionProfile)
            {
                nt = NetworkType.WLAN;
            }
            else
            {
                //不是Wifi也不是蜂窝数据判断为Lan
                nt = NetworkType.LAN;
            }

            return(nt);
        }
예제 #30
0
        public static string GetConnectionGeneration()
        {
            bool isConnected = false;

            string            InternetType = null;
            ConnectionProfile profile      = NetworkInformation.GetInternetConnectionProfile();

            if (profile == null)
            {
                InternetType = InternetStatus.None;
            }
            else
            {
                NetworkConnectivityLevel cl = profile.GetNetworkConnectivityLevel();
                isConnected = (cl != NetworkConnectivityLevel.None);
            }
            if (!isConnected)
            {
                return(InternetStatus.None);
            }
            if (profile.IsWwanConnectionProfile)
            {
                if (profile.WwanConnectionProfileDetails == null)
                {
                    InternetType = InternetStatus.Unknown;
                }
                WwanDataClass connectionClass = profile.WwanConnectionProfileDetails.GetCurrentDataClass();
                switch (connectionClass)
                {
                //2G
                case WwanDataClass.Edge:
                case WwanDataClass.Gprs:
                    InternetType = InternetStatus.IIG;
                    break;

                //3G
                case WwanDataClass.Cdma1xEvdo:
                case WwanDataClass.Cdma1xEvdoRevA:
                case WwanDataClass.Cdma1xEvdoRevB:
                case WwanDataClass.Cdma1xEvdv:
                case WwanDataClass.Cdma1xRtt:
                case WwanDataClass.Cdma3xRtt:
                case WwanDataClass.CdmaUmb:
                case WwanDataClass.Umts:
                case WwanDataClass.Hsdpa:
                case WwanDataClass.Hsupa:
                    InternetType = InternetStatus.IIIG;
                    break;

                //4G
                case WwanDataClass.LteAdvanced:
                    InternetType = InternetStatus.IVG;
                    break;

                //无网
                case WwanDataClass.None:
                    InternetType = InternetStatus.Unknown;
                    break;

                case WwanDataClass.Custom:
                default:
                    InternetType = InternetStatus.Unknown;
                    break;
                }
            }
            else if (profile.IsWlanConnectionProfile)
            {
                InternetType = InternetStatus.Wifi;
            }
            else
            {
                InternetType = InternetStatus.Lan;
            }
            return(InternetType);
        }
 private static bool CheckNetworkAvailability(NetworkConnectivityLevel minimumLevelRequired = NetworkConnectivityLevel.InternetAccess)
 {
     var profile = NetworkInformation.GetInternetConnectionProfile();
     IsNetworkConnectionAvaliable = (profile != null && profile.GetNetworkConnectivityLevel() >= minimumLevelRequired);
     return IsNetworkConnectionAvaliable;
 }