예제 #1
0
        /// <summary>
        /// This is the click handler for the 'UpdateUsageButton' button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UpdateUsage_Click(object sender, RoutedEventArgs e)
        {
            if (profileNameText.Text == "")
            {
                rootPage.NotifyUser("Profile name cannot be empty", NotifyType.ErrorMessage);
                return;
            }

            int usageInMegabytesValue;

            if (!int.TryParse(usageInMegabytesText.Text, out usageInMegabytesValue))
            {
                rootPage.NotifyUser("Usage in megabytes should be a valid number", NotifyType.ErrorMessage);
                return;
            }

            string profileName = profileNameText.Text;

            try
            {
                // Get the network account ID.
                IReadOnlyList <string> networkAccIds = Windows.Networking.NetworkOperators.MobileBroadbandAccount.AvailableNetworkAccountIds;

                if (networkAccIds.Count == 0)
                {
                    rootPage.NotifyUser("No network account ID found", NotifyType.ErrorMessage);
                    return;
                }

                UpdateUsageButton.IsEnabled = false;

                // For the sake of simplicity, assume we want to use the first account.
                // Refer to the MobileBroadbandAccount API's how to select a specific account ID.
                string networkAccountId = networkAccIds[0];

                // Create provisioning agent for specified network account ID
                Windows.Networking.NetworkOperators.ProvisioningAgent provisioningAgent =
                    Windows.Networking.NetworkOperators.ProvisioningAgent.CreateFromNetworkAccountId(networkAccountId);

                // Retrieve associated provisioned profile
                ProvisionedProfile provisionedProfile = provisioningAgent.GetProvisionedProfile(profileMediaType, profileName);

                ProfileUsage profileUsage = new ProfileUsage {
                    UsageInMegabytes = (uint)usageInMegabytesValue, LastSyncTime = System.DateTimeOffset.UtcNow
                };

                // Update usage
                provisionedProfile.UpdateUsage(profileUsage);

                rootPage.NotifyUser("Usage of " + usageInMegabytesValue + "MB has been set for the profile " + profileName, NotifyType.StatusMessage);
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser("Unexpected exception occured: " + ex.ToString(), NotifyType.ErrorMessage);
            }

            UpdateUsageButton.IsEnabled = true;
        }
예제 #2
0
        /// <summary>
        /// This is the click handler for the 'UpdateCostButton' button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UpdateCost_Click(object sender, RoutedEventArgs e)
        {
            if (profileNameText.Text == "")
            {
                rootPage.NotifyUser("Profile name cannot be empty", NotifyType.ErrorMessage);
                return;
            }

            string profileName = profileNameText.Text;

            try
            {
                // Get the network account ID.
                IReadOnlyList <string> networkAccIds = Windows.Networking.NetworkOperators.MobileBroadbandAccount.AvailableNetworkAccountIds;

                if (networkAccIds.Count == 0)
                {
                    rootPage.NotifyUser("No network account ID found", NotifyType.ErrorMessage);
                    return;
                }

                UpdateCostButton.IsEnabled = false;

                // For the sake of simplicity, assume we want to use the first account.
                // Refer to the MobileBroadbandAccount API's how to select a specific account ID.
                string networkAccountId = networkAccIds[0];

                // Create provisioning agent for specified network account ID
                Windows.Networking.NetworkOperators.ProvisioningAgent provisioningAgent =
                    Windows.Networking.NetworkOperators.ProvisioningAgent.CreateFromNetworkAccountId(networkAccountId);

                // Retrieve associated provisioned profile
                ProvisionedProfile provisionedProfile = provisioningAgent.GetProvisionedProfile(profileMediaType, profileName);

                // Set the new cost
                provisionedProfile.UpdateCost(networkCostType);

                rootPage.NotifyUser("Profile " + profileName + " has been updated with the cost type as " + networkCostType, NotifyType.StatusMessage);
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser("Unexpected exception occured: " + ex.ToString(), NotifyType.ErrorMessage);
            }

            UpdateCostButton.IsEnabled = true;
        }