Exemple #1
0
        private void initWatching()
        {
            // FilePcker
https:      //social.msdn.microsoft.com/Forums/windowsapps/en-US/8d92a991-a1d5-4d7a-8ca5-36ed15d86d95/uwphow-make-storagefile-from-a-given-string-filepath?forum=wpdevelop

            storageFolder = ApplicationData.Current.LocalFolder;

            queryOptions.FolderDepth = Windows.Storage.Search.FolderDepth.Deep;
            query = storageFolder.CreateItemQueryWithOptions(queryOptions);
        }
        /// <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);
            }
        }
Exemple #3
0
        /// <summary>
        /// Copy the protection from the source folder to the target folder
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void CopyProtectionToFolder_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if ((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;
                }

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

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

                bool IsProtectionCopied = await FileRevocationManager.CopyProtectionAsync(RootPage.SampleFolder, RootPage.TargetFolder);

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

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

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

                    // Check the target folder protection status
                    if (FileProtectionStatus.Protected == TargetProtectionStatus)
                    {
                        RootPage.NotifyUser("The protection cannot be copied since the target folder " + RootPage.TargetFolder.Name + " is already protected by another Enterprise Identity.\n" +
                                            "Please try again after clicking the Setup Button followed by the Protect Folder 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 folder " + RootPage.TargetFolder.Name + " is " + TargetProtectionStatus + ".\n" +
                                            "Please try again after clicking the Setup Button followed by the Protect Folder 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 folder " + RootPage.TargetFolder.Name + " is " + TargetProtectionStatus + ".\n",
                                    NotifyType.StatusMessage);
            }
            catch (FileNotFoundException)
            {
                RootPage.NotifyUserFileNotExist();
            }
        }
        /// <summary>
        /// Create files and folders
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Setup_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (null != RootPage.SampleFolder)
                {
                    Windows.Storage.Search.StorageItemQueryResult FolderStorageQuery = RootPage.SampleFolder.CreateItemQuery();
                    uint FolderItems = await FolderStorageQuery.GetItemCountAsync();

                    if (FolderItems > 0)
                    {
                        RootPage.NotifyUser("You need to delete the items inside the " + RootPage.SampleFolder.Name + " folder in order to regenerate the folder.", NotifyType.ErrorMessage);
                        return;
                    }

                    await RootPage.SampleFolder.DeleteAsync();

                    RootPage.SampleFolder = null;
                }

                if (null != RootPage.TargetFolder)
                {
                    Windows.Storage.Search.StorageItemQueryResult FolderStorageQuery = RootPage.TargetFolder.CreateItemQuery();
                    uint FolderItems = await FolderStorageQuery.GetItemCountAsync();

                    if (FolderItems > 0)
                    {
                        RootPage.NotifyUser("You need to delete the items inside the " + RootPage.TargetFolder.Name + " folder in order to regenerate the folder.", NotifyType.ErrorMessage);
                        return;
                    }

                    await RootPage.TargetFolder.DeleteAsync();

                    RootPage.TargetFolder = null;
                }

                if (null != RootPage.SampleFile)
                {
                    await RootPage.SampleFile.DeleteAsync();

                    RootPage.SampleFile = null;
                }

                if (null != RootPage.TargetFile)
                {
                    await RootPage.TargetFile.DeleteAsync();

                    RootPage.TargetFile = null;
                }

                if (null != RootPage.PickedFolder)
                {
                    RootPage.PickedFolder = null;
                }

                Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Clear();

                FolderPicker folderPicker = new FolderPicker();
                folderPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
                folderPicker.FileTypeFilter.Add(".docx");
                folderPicker.FileTypeFilter.Add(".xlsx");
                folderPicker.FileTypeFilter.Add(".pptx");
                folderPicker.FileTypeFilter.Add(".txt");
                RootPage.PickedFolder = await folderPicker.PickSingleFolderAsync();

                if (null == RootPage.PickedFolder)
                {
                    RootPage.NotifyUser("Please choose a base folder in which to create the SDK Sample related files and folders by clicking the Setup button.", NotifyType.ErrorMessage);
                    return;
                }

                StorageApplicationPermissions.FutureAccessList.AddOrReplace(MainPage.PickedFolderToken, RootPage.PickedFolder);

                RootPage.SampleFolder = await RootPage.PickedFolder.CreateFolderAsync(MainPage.SampleFoldername, CreationCollisionOption.ReplaceExisting);

                RootPage.TargetFolder = await RootPage.PickedFolder.CreateFolderAsync(MainPage.TargetFoldername, CreationCollisionOption.ReplaceExisting);

                RootPage.SampleFile = await RootPage.PickedFolder.CreateFileAsync(MainPage.SampleFilename, CreationCollisionOption.ReplaceExisting);

                RootPage.TargetFile = await RootPage.PickedFolder.CreateFileAsync(MainPage.TargetFilename, CreationCollisionOption.ReplaceExisting);

                RootPage.NotifyUser("The files " + RootPage.SampleFile.Name + " and " + RootPage.TargetFile.Name + " were created.\n" +
                                    "The folders " + RootPage.SampleFolder.Name + " and " + RootPage.TargetFolder.Name + " were created.",
                                    NotifyType.StatusMessage);
            }
            catch (FileNotFoundException)
            {
                RootPage.NotifyUserFileNotExist();
            }
        }
Exemple #5
0
        /// <summary>
        /// Delete the 'sample' file and folder
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Cleanup_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (null != RootPage.SampleFolder)
                {
                    Windows.Storage.Search.StorageItemQueryResult FolderStorageQuery = RootPage.SampleFolder.CreateItemQuery();
                    uint FolderItems = await FolderStorageQuery.GetItemCountAsync();

                    if (FolderItems > 0)
                    {
                        RootPage.NotifyUser("You need to delete the items inside the " + RootPage.SampleFolder.Name + " folder in order to delete the folder.", NotifyType.ErrorMessage);
                        return;
                    }
                    await RootPage.SampleFolder.DeleteAsync();

                    RootPage.SampleFolder = null;
                }

                if (null != RootPage.TargetFolder)
                {
                    Windows.Storage.Search.StorageItemQueryResult FolderStorageQuery = RootPage.TargetFolder.CreateItemQuery();
                    uint FolderItems = await FolderStorageQuery.GetItemCountAsync();

                    if (FolderItems > 0)
                    {
                        RootPage.NotifyUser("You need to delete the items inside the " + RootPage.TargetFolder.Name + " folder in order to delete the folder.", NotifyType.ErrorMessage);
                        return;
                    }
                    await RootPage.TargetFolder.DeleteAsync();

                    RootPage.TargetFolder = null;
                }

                if (null != RootPage.SampleFile)
                {
                    await RootPage.SampleFile.DeleteAsync();

                    RootPage.SampleFile = null;
                }

                if (null != RootPage.TargetFile)
                {
                    await RootPage.TargetFile.DeleteAsync();

                    RootPage.TargetFile = null;
                }

                if (null != RootPage.PickedFolder)
                {
                    RootPage.PickedFolder = null;
                }

                Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Clear();


                RootPage.NotifyUser("The files " + MainPage.SampleFilename + " and " + MainPage.TargetFilename + " were deleted.\n" +
                                    "The folders " + MainPage.SampleFoldername + " and " + MainPage.TargetFoldername + " were deleted.",
                                    NotifyType.StatusMessage);
            }
            catch (FileNotFoundException)
            {
                RootPage.NotifyUserFileNotExist();
            }
        }