Exemple #1
0
        /// <summary>
        /// This is the click handler for the 'ProfileLocalUsageDataButton' button.  You would replace this with your own handler
        /// if you have a button or buttons on this page.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ProfileLocalUsageData_Click(object sender, RoutedEventArgs e)
        {
            //
            //Get Internet Connection Profile and display local data usage for the profile for the past 1 hour
            //
            string   localDataUsage = string.Empty;
            DateTime CurrTime       = DateTime.Now;
            TimeSpan TimeDiff       = new TimeSpan(1, 0, 0);

            try
            {
                ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();

                if (InternetConnectionProfile == null)
                {
                    rootPage.NotifyUser("Not connected to Internet\n", NotifyType.StatusMessage);
                }
                else
                {
                    var LocalUsage = InternetConnectionProfile.GetLocalUsage(CurrTime.Subtract(TimeDiff), CurrTime);

                    localDataUsage  = "Local Data Usage:\n";
                    localDataUsage += " Bytes Sent     : " + LocalUsage.BytesSent + "\n";
                    localDataUsage += " Bytes Received : " + LocalUsage.BytesReceived + "\n";
                    rootPage.NotifyUser(localDataUsage, NotifyType.StatusMessage);
                }
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser("Unexpected exception occured: " + ex.ToString(), NotifyType.ErrorMessage);
            }
        }
        private void CNTPstrbtn_Click(object sender, RoutedEventArgs e)
        {
            CNTPstrbtn.IsEnabled = false;

            Uri sss = new Uri("https://www.google.com");

            asddd.Navigate(sss);

            asddd.NavigationCompleted += delegate
            {
                ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();

                if (InternetConnectionProfile != null)
                {
                    DateTime CurrTime = DateTime.Now;
                    TimeSpan TimeDiff = new TimeSpan(0, 1, 0);

                    var LocalUsage = InternetConnectionProfile.GetLocalUsage(CurrTime.Subtract(TimeDiff), CurrTime);

                    if (LocalUsage.BytesSent != null && LocalUsage.BytesReceived != null)
                    {
                        complitedtest = true;
                        showmsg(1);
                    }
                    else
                    {
                        complitedtest = false;
                        showmsg(2);
                    }
                }
            };


            asddd.NavigationFailed += delegate
            {
                ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();

                if (InternetConnectionProfile != null)
                {
                    DateTime CurrTime = DateTime.Now;
                    TimeSpan TimeDiff = new TimeSpan(0, 1, 0);

                    var LocalUsage = InternetConnectionProfile.GetLocalUsage(CurrTime.Subtract(TimeDiff), CurrTime);

                    if (LocalUsage.BytesSent != null && LocalUsage.BytesReceived != null)
                    {
                        complitedtest = true;
                        showmsg(1);
                    }
                    else
                    {
                        complitedtest = false;
                        showmsg(2);
                    }
                }
            };
        }
Exemple #3
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;
            }
        }