Inheritance: IProvisioningAgent
Example #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;
        }
        /// <summary>
        /// This is the click handler for the 'ProvisionMnoButton' button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void ProvisionMno_Click(object sender, RoutedEventArgs e)
        {
            if (provXmlText.Text == "")
            {
                rootPage.NotifyUser("Provisioning XML cannot be empty", NotifyType.ErrorMessage);
                return;
            }

            string provisioningXML = provXmlText.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;
                }

                ProvisionMnoButton.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);

                // Provision using XML
                ProvisionFromXmlDocumentResults result = await provisioningAgent.ProvisionFromXmlDocumentAsync(provisioningXML);

                if (result.AllElementsProvisioned)
                {
                    // Provisioning is done successfully
                    rootPage.NotifyUser("Device was successfully configured", NotifyType.StatusMessage);
                }
                else
                {
                    // Error has occured during provisioning
                    // And hence displaying result XML containing
                    // errors
                    rootPage.NotifyUser(util.ParseResultXML(result.ProvisionResultsXml), NotifyType.StatusMessage);
                }
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser("Unexpected exception occured: " + ex.ToString(), NotifyType.ErrorMessage);
            }

            ProvisionMnoButton.IsEnabled = true;
        }
Example #3
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;
        }
Example #4
0
        /// <summary>
        /// This is the click handler for the 'Provision' button to provision the embedded XML file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void ProvisionButton_Click(object sender, RoutedEventArgs args)
        {
            ProvisionButton.IsEnabled = false;

            try
            {
                // Open the installation folder
                var installLocation = Windows.ApplicationModel.Package.Current.InstalledLocation;

                // Access the provisioning file
                var provisioningFile = await installLocation.GetFileAsync("ProvisioningData.xml");

                // Load with XML parser
                var xmlDocument = await XmlDocument.LoadFromFileAsync(provisioningFile);

                // Get raw XML
                var provisioningXml = xmlDocument.GetXml();

                // Create ProvisiongAgent Object
                var provisioningAgent = new ProvisioningAgent();

                // Create ProvisionFromXmlDocumentResults Object
                var result = await provisioningAgent.ProvisionFromXmlDocumentAsync(provisioningXml);

                if (result.AllElementsProvisioned)
                {
                    rootPage.NotifyUser("Provisioning was successful", NotifyType.StatusMessage);
                }
                else
                {
                    rootPage.NotifyUser("Provisioning result: " + result.ProvisionResultsXml, NotifyType.StatusMessage);
                }
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage);
            }

            ProvisionButton.IsEnabled = true;
        }
        /// <summary>
        /// This is the click handler for the 'ProvisionOtherOperatorButton' button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void ProvisionOtherOperator_Click(object sender, RoutedEventArgs e)
        {
            if (provXmlText.Text == "")
            {
                rootPage.NotifyUser("Provisioning XML cannot be empty", NotifyType.ErrorMessage);
                return;
            }

            string provisioningXML = provXmlText.Text;

            ProvisionOtherOperatorButton.IsEnabled = false;

            try
            {
                // Create provisioning agent
                Windows.Networking.NetworkOperators.ProvisioningAgent provisioningAgent = new Windows.Networking.NetworkOperators.ProvisioningAgent();

                // Provision using XML
                ProvisionFromXmlDocumentResults result = await provisioningAgent.ProvisionFromXmlDocumentAsync(provisioningXML);

                if (result.AllElementsProvisioned)
                {
                    // Provisioning is done successfully
                    rootPage.NotifyUser("Device was successfully configured", NotifyType.StatusMessage);
                }
                else
                {
                    // Error has occured during provisioning
                    // And hence displaying result XML containing
                    // errors
                    rootPage.NotifyUser(util.ParseResultXML(result.ProvisionResultsXml), NotifyType.StatusMessage);
                }
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser("Unexpected exception occured: " + ex.ToString(), NotifyType.ErrorMessage);
            }

            ProvisionOtherOperatorButton.IsEnabled = true;
        }
        /// <summary>
        /// This is the click handler for the 'ProvisionOtherOperatorButton' button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void ProvisionOtherOperator_Click(object sender, RoutedEventArgs e)
        {
            if (provXmlText.Text == "")
            {
                rootPage.NotifyUser("Provisioning XML cannot be empty", NotifyType.ErrorMessage);
                return;
            }

            string provisioningXML = provXmlText.Text;
            ProvisionOtherOperatorButton.IsEnabled = false;

            try
            {
                // Create provisioning agent
                Windows.Networking.NetworkOperators.ProvisioningAgent provisioningAgent = new Windows.Networking.NetworkOperators.ProvisioningAgent();

                // Provision using XML
                ProvisionFromXmlDocumentResults result = await provisioningAgent.ProvisionFromXmlDocumentAsync(provisioningXML);

                if (result.AllElementsProvisioned)
                {
                    // Provisioning is done successfully
                    rootPage.NotifyUser("Device was successfully configured", NotifyType.StatusMessage);
                }
                else
                {
                    // Error has occured during provisioning
                    // And hence displaying result XML containing
                    // errors
                    rootPage.NotifyUser(util.ParseResultXML(result.ProvisionResultsXml), NotifyType.StatusMessage);
                }
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser("Unexpected exception occured: " + ex.ToString(), NotifyType.ErrorMessage);
            }

            ProvisionOtherOperatorButton.IsEnabled = true;
        }