コード例 #1
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)
        {
            if (profile == null)
            {
                Reset();

                return;
            }

            networkNames.Clear();

            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;
            }

            var names = profile.GetNetworkNames();

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

            ConnectivityLevel = profile.GetNetworkConnectivityLevel();

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

            default:
                IsInternetAvailable = true;
                break;
            }

            ConnectionCost = profile.GetConnectionCost();
            SignalStrength = profile.GetSignalBars();
        }
コード例 #2
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);
        }
コード例 #3
0
        public static bool IsInternet()
        {
#if DEBUG
            return(true);
#endif
            ConnectionProfile connections = NetworkInformation.GetInternetConnectionProfile();
            bool internet = connections != null &&
                            connections.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess;
            return(internet);
        }
コード例 #4
0
        private static bool IsThereInternet()
        {
            ConnectionProfile connections = NetworkInformation.GetInternetConnectionProfile();
            bool internet = connections != null && connections.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess;

            // clean up
            connections = null;

            return(internet);
        }
コード例 #5
0
        private void OnNetworkStatusChange(object sender)
        {
            // Get the ConnectionProfile that is currently used to connect to the Internet
            ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile();

            if (profile != null)
            {
                // NetworkInformation.NetworkStatusChanged fires multiple times for some reason, so we only want to get the first real reconnect
                if (profile.GetNetworkConnectivityLevel() < NetworkConnectivityLevel.InternetAccess)
                {
                    nextConnectIsFirst = true;
                }
                else if (profile.GetNetworkConnectivityLevel() >= NetworkConnectivityLevel.InternetAccess && nextConnectIsFirst)
                {
                    nextConnectIsFirst = false;
                    eventQueue.DumpQueue();
                }
            }
        }
コード例 #6
0
        public static bool IsNetworkAvailable(NetworkConnectivityLevel minimumLevelRequired = NetworkConnectivityLevel.InternetAccess)
        {
            ConnectionProfile profile =
                NetworkInformation.GetInternetConnectionProfile();

            NetworkConnectivityLevel level =
                profile.GetNetworkConnectivityLevel();

            return(level >= minimumLevelRequired);
        }
コード例 #7
0
 public void Synchronize(Action syncExecute)
 {
     _syncExecute       = syncExecute;
     _connectionProfile = NetworkInformation.GetInternetConnectionProfile();
     NetworkInformation.NetworkStatusChanged += NetworkInformation_NetworkStatusChanged;
     if (_connectionProfile != null && _connectionProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess)
     {
         System.Threading.Tasks.Task.Factory.StartNew(syncExecute);
     }
 }
コード例 #8
0
        private static bool IsInternetProfile(ConnectionProfile connectionProfile)
        {
            if (connectionProfile == null)
            {
                return(false);
            }

            var connectivityLevel = connectionProfile.GetNetworkConnectivityLevel();

            return(connectivityLevel != NetworkConnectivityLevel.None);
        }
コード例 #9
0
        void checkConnection()
        {
            ConnectionProfile connections = NetworkInformation.GetInternetConnectionProfile();
            bool isInternetConnected      = connections != null && connections.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess;

            if (!isInternetConnected)
            {
                MessageDialog md = new MessageDialog("Không có kết nối , hãy kiểm tra lại mạng");
                md.ShowAsync();
            }
        }
        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
        /// <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);
        }
コード例 #12
0
ファイル: LogicHelper.cs プロジェクト: RemSoftDev/GMP
        public async static Task <bool> IsInternet()
        {
            ConnectionProfile connections = NetworkInformation.GetInternetConnectionProfile();
            bool internet = connections != null && connections.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess;

            if (!internet)
            {
                var dialog = new MessageDialog("The app need accsess to the internet!", "No internet access!");
                await dialog.ShowAsync();
            }
            return(internet);
        }
コード例 #13
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();
            networkNames.AddRange(profile.GetNetworkNames());

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

            default:
                IsInternetAvailable = true;
                break;
            }
        }
コード例 #14
0
        public bool IsOnline()
        {
            ConnectionProfile connections = NetworkInformation.GetInternetConnectionProfile();

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

            bool internet = connections != null && connections.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess;

            return(internet);
        }
コード例 #15
0
        public MainPage()
        {
            this.InitializeComponent();

            ConnectionProfile connectionProfile = NetworkInformation.GetInternetConnectionProfile();
            bool isConnected = (
                (connectionProfile != null) &&
                (connectionProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess)
                );

            DataContext = new MainViewModel();
            UpdateConnectivityUI(isConnected);
        }
コード例 #16
0
        public static bool InternetConnection()
        {
            ConnectionProfile connections = NetworkInformation.GetInternetConnectionProfile();

            if (connections != null && connections.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #17
0
 public static bool IsInternetAvailable()
 {
     try
     {
         ConnectionProfile connections = NetworkInformation.GetInternetConnectionProfile();
         return(connections != null && connections.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess);
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex);
         return(false);
     }
 }
コード例 #18
0
        public static bool IsNetworkAvailable()
        {
            ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();

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

            NetworkConnectivityLevel level = InternetConnectionProfile.GetNetworkConnectivityLevel();

            return(level == NetworkConnectivityLevel.InternetAccess);
        }
コード例 #19
0
        /// <summary>
        /// Er wordt gecontroleerd of er internet is
        /// </summary>
        /// <returns>Een boolean </returns>
        public static Boolean ControleerInternet()
        {
            ConnectionProfile profiel = NetworkInformation.GetInternetConnectionProfile();

            if (profiel != null && profiel.GetNetworkConnectivityLevel() >= NetworkConnectivityLevel.LocalAccess)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #20
0
 public static bool IsInternet()
 {
     try
     {
         ConnectionProfile connections = NetworkInformation.GetInternetConnectionProfile();
         bool internet = connections != null && connections.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess;
         return(internet);
     }
     catch (NotImplementedException)
     {
         return(false);
     }
 }
コード例 #21
0
ファイル: App.xaml.cs プロジェクト: threemind/windows8
        private bool ConnectedToInternet()
        {
            ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();

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

            var level = InternetConnectionProfile.GetNetworkConnectivityLevel();

            return(level == NetworkConnectivityLevel.InternetAccess);
        }
コード例 #22
0
        public static bool IsInternetConnectionAvailable()
        {
            bool isNetworkAvailable = false;

            ConnectionProfile internetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();

            if (internetConnectionProfile != null && internetConnectionProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess)
            {
                isNetworkAvailable = true;
            }

            return(isNetworkAvailable);
        }
コード例 #23
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);
        }
コード例 #24
0
        async private void OnConnectivityChanged(object sender)
        {
            ConnectionProfile connectionProfile = NetworkInformation.GetInternetConnectionProfile();
            bool isConnected = (
                (connectionProfile != null) &&
                (connectionProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess)
                );

            // need to come back to the main thread to update the UI
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                UpdateConnectivityUI(isConnected);
            });
        }
コード例 #25
0
        private static async Task WaitForInternet()
        {
            while (true)
            {
                ConnectionProfile connections = NetworkInformation.GetInternetConnectionProfile();
                bool internet = connections != null && connections.GetNetworkConnectivityLevel() != NetworkConnectivityLevel.None;
                if (internet)
                {
                    break;
                }

                await Task.Delay(5 * 1000);
            }
        }
コード例 #26
0
 public static bool isInternetOn()
 {
     try
     {
         ConnectionProfile internetConnectionProfile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();
         //if true, internet is accessible.
         return(internetConnectionProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess);
     }
     catch
     {
         Debug.WriteLine("Cant recieve internet on information");
     }
     return(false);
 }
コード例 #27
0
ファイル: PivotPage.xaml.cs プロジェクト: pabermod/APOD_WP8
        //Method to get the image URL
        void myRSS_DownloadStringCompleted(string RSS)
        {
            ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();

            //Check if the Network is available
            if (InternetConnectionProfile.GetNetworkConnectivityLevel() != NetworkConnectivityLevel.None)
            {
                // filter all images from rss

                //Title of the image
                imgTitle = XElement.Parse(RSS).Descendants("title")
                           .Select(m => m.Value).ToArray();

                //The description value is an HTML code, not XML....
                htmlArray = XElement.Parse(RSS).Descendants("description")
                            .Select(m => m.Value).ToArray();

                //Create array of preview images links
                imgarray = new string[htmlArray.Length - 2];
                for (int i = 1; i < htmlArray.Length - 1; i++)
                {
                    HtmlDocument htmldoc = new HtmlDocument();
                    htmldoc.LoadHtml(htmlArray[i]);
                    HtmlNode imgNode = htmldoc.DocumentNode.FirstChild.FirstChild.FirstChild;
                    imgarray[i - 1] = imgNode.GetAttributeValue("src", string.Empty);
                }

                //todayPanel.Children.Clear();
                //Show the titles and images of the RSS.
                for (int j = 0; j < imgarray.Length; j++)
                {
                    TextBlock title = new TextBlock();
                    title.Text         = imgTitle[j + 1];
                    title.Style        = (Style)Application.Current.Resources["BodyTextBlockStyle"];
                    title.TextWrapping = TextWrapping.Wrap;
                    todayPanel.Children.Add(title);

                    Image img = new Image();
                    img.Width = 100;
                    img.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
                    img.Stretch             = Stretch.Uniform;
                    img.Source = new BitmapImage(new Uri(imgarray[j]));
                    todayPanel.Children.Add(img);
                }
            }
            else
            {
                msgPop.Pop("No network is available.", "Error");
            }
        }
コード例 #28
0
 void NetworkInformation_NetworkStatusChanged(object sender)
 {
     try
     {
         if (_connectionProfile != null && _connectionProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess)
         {
             _syncExecute.Invoke();
         }
     }
     catch (Exception ex)
     {
         this.SendMessageToUIThread(ex.Message);
     }
 }
コード例 #29
0
ファイル: SSProxyHelper.cs プロジェクト: pithline/FMS
 void NetworkInformation_NetworkStatusChanged(object sender)
 {
     try
     {
         if (_connectionProfile != null && _connectionProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess)
         {
             _syncExecute.Invoke();
         }
     }
     catch (Exception ex)
     {
         AppSettings.Instance.ErrorMessage = ex.Message;
     }
 }
コード例 #30
0
        private String NetScans()
        {
            ConnectionProfile        connectionProfile = NetworkInformation.GetInternetConnectionProfile();
            NetworkConnectivityLevel concon            = new NetworkConnectivityLevel();

            try
            {
                concon = connectionProfile.GetNetworkConnectivityLevel();
            }
            catch
            {
            }
            return(concon.ToString());
        }