Пример #1
0
        private async void AddFile_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker Picker = new FileOpenPicker
            {
                SuggestedStartLocation = PickerLocationId.ComputerFolder,
                ViewMode = PickerViewMode.Thumbnail
            };

            Picker.FileTypeFilter.Add("*");

            IReadOnlyList <StorageFile> FileList = await Picker.PickMultipleFilesAsync();

            ActivateLoading(true, true);

            Cancellation = new CancellationTokenSource();

            try
            {
                foreach (StorageFile File in FileList)
                {
                    if ((await File.EncryptAsync(SecureFolder, FileEncryptionAesKey, AESKeySize, Cancellation.Token).ConfigureAwait(true)) is StorageFile EncryptedFile)
                    {
                        var Size = await EncryptedFile.GetSizeRawDataAsync().ConfigureAwait(true);

                        var Thumbnail    = new BitmapImage(new Uri("ms-appx:///Assets/LockFile.png"));
                        var ModifiedTime = await EncryptedFile.GetModifiedTimeAsync().ConfigureAwait(true);

                        SecureCollection.Add(new FileSystemStorageItemBase(EncryptedFile, Size, Thumbnail, ModifiedTime));
                    }
                    else
                    {
                        QueueContentDialog Dialog = new QueueContentDialog
                        {
                            Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                            Content         = Globalization.GetString("QueueDialog_EncryptError_Content"),
                            CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                        };
                        _ = await Dialog.ShowAsync().ConfigureAwait(true);

                        break;
                    }
                }
            }
            catch (TaskCanceledException)
            {
            }
            finally
            {
                Cancellation.Dispose();
                Cancellation = null;
            }

            await Task.Delay(1500).ConfigureAwait(true);

            ActivateLoading(false);
        }
Пример #2
0
        private async void Grid_Drop(object sender, DragEventArgs e)
        {
            IReadOnlyList <IStorageItem> Items = await e.DataView.GetStorageItemsAsync();

            if (Items.Any((Item) => Item.IsOfType(StorageItemTypes.Folder)))
            {
                QueueContentDialog Dialog = new QueueContentDialog
                {
                    Title           = Globalization.GetString("Common_Dialog_TipTitle"),
                    Content         = Globalization.GetString("QueueDialog_SecureAreaImportFiliter_Content"),
                    CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                };

                _ = await Dialog.ShowAsync().ConfigureAwait(true);
            }

            if (Items.Any((Item) => Item.IsOfType(StorageItemTypes.File)))
            {
                ActivateLoading(true, true);

                Cancellation = new CancellationTokenSource();

                try
                {
                    foreach (StorageFile Item in Items.OfType <StorageFile>())
                    {
                        if ((await Item.EncryptAsync(SecureFolder, FileEncryptionAesKey, AESKeySize, Cancellation.Token).ConfigureAwait(true)) is StorageFile EncryptedFile)
                        {
                            var Size = await EncryptedFile.GetSizeRawDataAsync().ConfigureAwait(true);

                            var Thumbnail    = new BitmapImage(new Uri("ms-appx:///Assets/LockFile.png"));
                            var ModifiedTime = await EncryptedFile.GetModifiedTimeAsync().ConfigureAwait(true);

                            SecureCollection.Add(new FileSystemStorageItemBase(EncryptedFile, Size, Thumbnail, ModifiedTime));
                        }
                        else
                        {
                            QueueContentDialog Dialog = new QueueContentDialog
                            {
                                Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                                Content         = Globalization.GetString("QueueDialog_EncryptError_Content"),
                                CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                            };
                            _ = await Dialog.ShowAsync().ConfigureAwait(true);

                            break;
                        }
                    }
                }
                catch (TaskCanceledException cancelException)
                {
                    LogTracer.Log(cancelException, "Import items to SecureArea have been cancelled");
                }
                catch (Exception ex)
                {
                    LogTracer.Log(ex, "An error was threw when importing file");
                }
                finally
                {
                    Cancellation.Dispose();
                    Cancellation = null;

                    await Task.Delay(1500).ConfigureAwait(true);

                    ActivateLoading(false);
                }
            }
        }
Пример #3
0
        private async void AddFile_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker Picker = new FileOpenPicker
            {
                SuggestedStartLocation = PickerLocationId.ComputerFolder,
                ViewMode = PickerViewMode.Thumbnail
            };

            Picker.FileTypeFilter.Add("*");

            IReadOnlyList <StorageFile> FileList = await Picker.PickMultipleFilesAsync();

            if (FileList.Count > 0)
            {
                ActivateLoading(true, true);

                Cancellation = new CancellationTokenSource();

                try
                {
                    foreach (StorageFile File in FileList)
                    {
                        if ((await File.EncryptAsync(SecureFolder, FileEncryptionAesKey, AESKeySize, Cancellation.Token).ConfigureAwait(true)) is StorageFile EncryptedFile)
                        {
                            SecureCollection.Add(new FileSystemStorageItemBase(EncryptedFile, await EncryptedFile.GetSizeRawDataAsync().ConfigureAwait(true), new BitmapImage(new Uri("ms-appx:///Assets/LockFile.png")), await EncryptedFile.GetModifiedTimeAsync().ConfigureAwait(true)));

                            try
                            {
                                await File.DeleteAsync(StorageDeleteOption.Default);
                            }
                            catch
                            {
                            }
                        }
                        else
                        {
                            QueueContentDialog Dialog = new QueueContentDialog
                            {
                                Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                                Content         = Globalization.GetString("QueueDialog_EncryptError_Content"),
                                CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                            };

                            _ = await Dialog.ShowAsync().ConfigureAwait(true);

                            break;
                        }
                    }
                }
                catch (TaskCanceledException cancelException)
                {
                    LogTracer.Log(cancelException, "Import items to SecureArea have been cancelled");
                }
                catch (Exception ex)
                {
                    LogTracer.Log(ex, "An error was threw when importing file");
                }
                finally
                {
                    Cancellation.Dispose();
                    Cancellation = null;

                    await Task.Delay(1500).ConfigureAwait(true);

                    ActivateLoading(false);
                }
            }
        }