/// <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
            //

            try
            {
                NetworkUsageStates.Roaming = ParseTriStates(((ComboBoxItem)RoamingComboBox.SelectedItem).Content.ToString());
                NetworkUsageStates.Shared  = ParseTriStates(((ComboBoxItem)SharedComboBox.SelectedItem).Content.ToString());
                StartTime = (StartDatePicker.Date.Date + StartTimePicker.Time);
                EndTime   = (EndDatePicker.Date.Date + EndTimePicker.Time);

                if (InternetConnectionProfile == null)
                {
                    rootPage.NotifyUser("Not connected to Internet\n", NotifyType.StatusMessage);
                }
                else
                {
                    if (!InternetConnectionProfile.IsWlanConnectionProfile && !InternetConnectionProfile.IsWwanConnectionProfile)
                    {
                        rootPage.NotifyUser("GetAttributedNetworkUsageAsync is not supported on the emulator.", NotifyType.ErrorMessage);
                    }
                    else
                    {
                        InternetConnectionProfile.GetAttributedNetworkUsageAsync(StartTime, EndTime, NetworkUsageStates).Completed = GetNetworkUsageAsyncHandler;
                    }
                }
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser("Unexpected exception occurred: " + ex.ToString(), NotifyType.ErrorMessage);
            }
        }
コード例 #2
0
 private static async Task <IReadOnlyList <Windows.Networking.Connectivity.AttributedNetworkUsage> > GetAttributedNetworkUsageAsync(ConnectionProfile connectionProfile, DateTime startTime, DateTime endTime, NetworkUsageStates networkUsageStates)
 {
     try
     {
         DateTimeOffset StartTimeOffset = new DateTimeOffset(startTime);
         DateTimeOffset EndTimeOffset   = new DateTimeOffset(endTime);
         return(await connectionProfile.GetAttributedNetworkUsageAsync(StartTimeOffset, EndTimeOffset, networkUsageStates));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }