示例#1
0
        /// <summary>
        /// Revoke the enterprise id that user entered
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Revoke_Click(object sender, RoutedEventArgs e)
        {
            if ("" == InputTextBox.Text)
            {
                RootPage.NotifyUser("Please enter an Enterpise ID that you want to use.", NotifyType.ErrorMessage);
                return;
            }

            try
            {
                FileRevocationManager.Revoke(InputTextBox.Text);
                RootPage.NotifyUser("The Enterprise ID " + InputTextBox.Text + " was revoked. The files protected by it will not be accessible anymore.", NotifyType.StatusMessage);
            }

            //
            // NOTE: Generally you should not rely on exception handling
            // to validate an Enterprise ID string. In real-world
            // applications, the domain name of the enterprise might be
            // parsed out of an email address or a URL, and may even be
            // entered by a user. Your app-specific code to extract the
            // Enterprise ID should validate the Enterprise ID string is an
            // internationalized domain name before passing it to
            // Revoke.
            //

            catch (ArgumentException)
            {
                RootPage.NotifyUser("Given Enterprise ID string is invalid.\n" +
                                    "Please try again using a properly formatted Internationalized Domain Name as the Enterprise ID string.",
                                    NotifyType.ErrorMessage);
            }
        }
示例#2
0
        /// <summary>
        /// Get status of the file and folder
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void GetStatus_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if ((null == RootPage.SampleFile) ||
                    (null == RootPage.TargetFile) ||
                    (null == RootPage.SampleFolder) ||
                    (null == RootPage.TargetFolder))
                {
                    RootPage.NotifyUser("You need to click the Setup button in the Protect a file or folder with an Enterprise Identity scenario.", NotifyType.ErrorMessage);
                    return;
                }

                FileProtectionStatus SampleFileProtectionStatus = await FileRevocationManager.GetStatusAsync(RootPage.SampleFile);

                FileProtectionStatus TargetFileProtectionStatus = await FileRevocationManager.GetStatusAsync(RootPage.TargetFile);

                FileProtectionStatus SampleFolderProtectionStatus = await FileRevocationManager.GetStatusAsync(RootPage.SampleFolder);

                FileProtectionStatus TargetFolderProtectionStatus = await FileRevocationManager.GetStatusAsync(RootPage.TargetFolder);

                RootPage.NotifyUser("The protection status of the file " + RootPage.SampleFile.Name + " is " + SampleFileProtectionStatus + ".\n" +
                                    "The protection status of the file " + RootPage.TargetFile.Name + " is " + TargetFileProtectionStatus + ".\n" +
                                    "The protection status of the folder " + RootPage.SampleFolder.Name + " is " + SampleFolderProtectionStatus + ".\n" +
                                    "The protection status of the folder " + RootPage.TargetFolder.Name + " is " + TargetFolderProtectionStatus + ".",
                                    NotifyType.StatusMessage);
            }
            catch (FileNotFoundException)
            {
                RootPage.NotifyUserFileNotExist();
            }
        }
示例#3
0
        /// <summary>
        /// Copy the protection from the source file to the target file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void CopyProtectionToFile_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if ((null == RootPage.SampleFile) || (null == RootPage.TargetFile))
                {
                    RootPage.NotifyUser("You need to click the Setup button in the Protect a file or folder with an Enterprise Identity scenario.", NotifyType.ErrorMessage);
                    return;
                }

                bool IsProtectionCopied = await FileRevocationManager.CopyProtectionAsync(RootPage.SampleFile, RootPage.TargetFile);

                // Get the target file protection status
                FileProtectionStatus TargetProtectionStatus = await FileRevocationManager.GetStatusAsync(RootPage.TargetFile);

                if (!IsProtectionCopied)
                {
                    // Make sure the source file is protected
                    FileProtectionStatus SourceProtectionStatus = await FileRevocationManager.GetStatusAsync(RootPage.SampleFile);

                    if (FileProtectionStatus.Protected != SourceProtectionStatus)
                    {
                        RootPage.NotifyUser("The protection cannot be copied since the status of the source file " + RootPage.SampleFile.Name + " is " + SourceProtectionStatus + ".\n" +
                                            "Please try again after clicking the Setup Button followed by the Protect File button in the Protect a file or folder with an Enterprise Identity scenario.",
                                            NotifyType.ErrorMessage);
                        return;
                    }

                    // Check the target file protection status
                    if (FileProtectionStatus.Protected == TargetProtectionStatus)
                    {
                        RootPage.NotifyUser("The protection cannot be copied since the target file " + RootPage.TargetFile.Name + " is already protected by another Enterprise Identity.\n" +
                                            "Please try again after clicking the Setup Button followed by the Protect File button in the Protect a file or folder with an Enterprise Identity scenario.",
                                            NotifyType.ErrorMessage);
                        return;
                    }
                    else
                    {
                        RootPage.NotifyUser("The protection cannot be copied since the status of the target file " + RootPage.TargetFile.Name + " is " + TargetProtectionStatus + ".\n" +
                                            "Please try again after clicking the Setup Button followed by the Protect File button in the Protect a file or folder with an Enterprise Identity scenario.",
                                            NotifyType.ErrorMessage);
                        return;
                    }
                }

                RootPage.NotifyUser("The protection was copied.\n" +
                                    "The protection status of the target file " + RootPage.TargetFile.Name + " is " + TargetProtectionStatus + ".\n",
                                    NotifyType.StatusMessage);
            }
            catch (FileNotFoundException)
            {
                RootPage.NotifyUserFileNotExist();
            }
        }
        /// <summary>
        /// Protect the folder with enterprise id that user entered
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void ProtectFolder_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (null == RootPage.SampleFolder)
                {
                    RootPage.NotifyUser("You need to click the Setup button first.", NotifyType.ErrorMessage);
                    return;
                }

                if ("" == InputTextBox.Text)
                {
                    RootPage.NotifyUser("Please enter an Enterpise ID that you want to use.", NotifyType.ErrorMessage);
                    return;
                }

                // Make sure the folder is empty before you protect it
                Windows.Storage.Search.StorageItemQueryResult StorageQuery = RootPage.SampleFolder.CreateItemQuery();
                uint Items = await StorageQuery.GetItemCountAsync();

                if (Items > 0)
                {
                    RootPage.NotifyUser("You need to empty the " + RootPage.SampleFolder.Name + " before you can protect it.", NotifyType.ErrorMessage);
                    return;
                }

                FileProtectionStatus ProtectionStatus = await FileRevocationManager.ProtectAsync(RootPage.SampleFolder, InputTextBox.Text);

                RootPage.NotifyUser("The protection status of the folder " + RootPage.SampleFolder.Name + " is " + ProtectionStatus + ".\n", NotifyType.StatusMessage);
            }
            catch (FileNotFoundException)
            {
                RootPage.NotifyUserFileNotExist();
            }

            //
            // NOTE: Generally you should not rely on exception handling
            // to validate an Enterprise ID string. In real-world
            // applications, the domain name of the enterprise might be
            // parsed out of an email address or a URL, and may even be
            // entered by a user. Your app-specific code to extract the
            // Enterprise ID should validate the Enterprise ID string is an
            // internationalized domain name before passing it to
            // ProtectAsync.
            //

            catch (ArgumentException)
            {
                RootPage.NotifyUser("Given Enterprise ID string is invalid.\n" +
                                    "Please try again using a properly formatted Internationalized Domain Name as the Enterprise ID string.",
                                    NotifyType.ErrorMessage);
            }
        }