/// <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
            {
                Granularity = ParseDataUsageGranularity(((ComboBoxItem)GranularityComboBox.SelectedItem).Content.ToString());
                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
                {
                    InternetConnectionProfile.GetNetworkUsageAsync(StartTime,
                                                                   EndTime, Granularity, NetworkUsageStates).Completed = GetNetworkUsageAsyncHandler;
                }
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser("Unexpected exception occurred: " + ex.ToString(), NotifyType.ErrorMessage);
            }
        }
        // Returns the amount of time between each period of network usage for a given granularity
        TimeSpan GranularityToTimeSpan(DataUsageGranularity granularity)
        {
            switch (granularity)
            {
            case DataUsageGranularity.PerMinute:
                return(new TimeSpan(0, 1, 0));

            case DataUsageGranularity.PerHour:
                return(new TimeSpan(1, 0, 0));

            case DataUsageGranularity.PerDay:
                return(new TimeSpan(1, 0, 0, 0));

            default:
                return(new TimeSpan(0));
            }
        }
Esempio n. 3
0
 // Returns the amount of time between each period of network usage for a given granularity
 TimeSpan GranularityToTimeSpan(DataUsageGranularity granularity)
 {
     switch (granularity)
     {
         case DataUsageGranularity.PerMinute:
             return new TimeSpan(0, 1, 0);
         case DataUsageGranularity.PerHour:
             return new TimeSpan(1, 0, 0);
         case DataUsageGranularity.PerDay:
             return new TimeSpan(1, 0, 0, 0);
         default:
             return new TimeSpan(0);
     }
 }
Esempio n. 4
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
            //

            try
            {
                Granularity = ParseDataUsageGranularity(((ComboBoxItem)GranularityComboBox.SelectedItem).Content.ToString());
                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
                {
                    InternetConnectionProfile.GetNetworkUsageAsync(StartTime,
                        EndTime, Granularity, NetworkUsageStates).Completed = GetNetworkUsageAsyncHandler;
                }
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser("Unexpected exception occurred: " + ex.ToString(), NotifyType.ErrorMessage);
            }
        }
Esempio n. 5
0
		/// <summary>
		/// Gets a list of the estimated data traffic and connection duration over a specified period of time, for a specific network usage state.
		/// </summary>
		/// <param name="startTime">The start time over which to retrieve data.  Can be no more than 60 days prior to the current time.  If the specified granularity is PerMinute, the start time can be no more than 120 minutes prior to the current time.</param>
		/// <param name="endTime">The end time over which to retrieve data.</param>
		/// <param name="granularity">The desired granularity of the returned usage statistics.  Each elements in the list corresponds to the network usage per the specified granularity, e.g., usage per hour.</param>
		/// <param name="states">The state of the connection profile for which usage data should be returned.</param>
		/// <returns>When the method completes, it returns a list of NetworkUsage objects, which indicate the sent and received values, in bytes, and the total amount of time the profile was connected during the corresponding time interval.</returns>
		public IAsyncOperation<IReadOnlyList<NetworkUsage>> GetNetworkUsageAsync(DateTimeOffset startTime, DateTimeOffset endTime, DataUsageGranularity granularity, NetworkUsageStates states)
		{
			throw new NotImplementedException();
		}
 public static async Task <IReadOnlyList <NetworkUsage> > GetNetworkUsageSync(ConnectionProfile connectionProfile, DateTime startTime, DateTime endTime, DataUsageGranularity granularity, NetworkUsageStates networkUsageStates)
 {
     return(await GetNetworkUsageAsync(connectionProfile, startTime, endTime, granularity, networkUsageStates));
 }
        private static async Task <IReadOnlyList <NetworkUsage> > GetNetworkUsageAsync(ConnectionProfile connectionProfile, DateTime startTime, DateTime endTime, DataUsageGranularity granularity, NetworkUsageStates networkUsageStates)
        {
            try
            {
                DateTimeOffset StartTimeOffset = new DateTimeOffset(startTime);
                DateTimeOffset EndTimeOffset   = new DateTimeOffset(endTime);

                return(await connectionProfile.GetNetworkUsageAsync(StartTimeOffset, EndTimeOffset, granularity, networkUsageStates));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static IReadOnlyList <NetworkUsage> GetNetworkUsage(ConnectionProfile connectionProfile, DateTime startTime, DateTime endTime, DataUsageGranularity granularity, NetworkUsageStates networkUsageStates)
        {
            Task <IReadOnlyList <NetworkUsage> > task = Task.Run(() => GetNetworkUsageSync(connectionProfile, startTime, endTime, granularity, networkUsageStates));

            return(task.Result);
        }