public static async Task <SafeWrapperResult> CopyFileAsync(IStorageFile source, IStorageFile destination, Action <float> progressReportDelegate, CancellationToken cancellationToken)
        {
            long fileSize = await StorageHelpers.GetFileSize(source);

            byte[]            buffer = new byte[Constants.FileSystem.COPY_FILE_BUFFER_SIZE];
            SafeWrapperResult result = SafeWrapperResult.S_SUCCESS;

            using (Stream sourceStream = (await source.OpenReadAsync()).AsStreamForRead())
            {
                using (Stream destinationStream = (await destination.OpenAsync(FileAccessMode.ReadWrite)).AsStreamForWrite())
                {
                    long bytesTransferred = 0L;
                    int  currentBlockSize = 0;

                    while ((currentBlockSize = await sourceStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
                    {
                        bytesTransferred += currentBlockSize;
                        float percentage = (float)bytesTransferred * 100.0f / (float)fileSize;

                        await destinationStream.WriteAsync(buffer, 0, currentBlockSize);

                        progressReportDelegate?.Invoke(percentage);

                        if (cancellationToken.IsCancellationRequested)
                        {
                            // TODO: Delete copied file there
                            result = SafeWrapperResult.S_CANCEL;
                            break;
                        }
                    }
                }
            }

            return(result);
        }
        public static async Task <SafeWrapperResult> DeleteItem(IStorageItem item, bool permanently = false)
        {
            if (item == null)
            {
                return(new SafeWrapperResult(OperationErrorCode.InvalidArgument, new ArgumentNullException(), "The provided storage item is null."));
            }

            SafeWrapperResult result = await SafeWrapperRoutines.SafeWrapAsync(
                () => item.DeleteAsync(permanently ? StorageDeleteOption.PermanentDelete : StorageDeleteOption.Default).AsTask());

            return(result);
        }
Ejemplo n.º 3
0
        public static async Task <SafeWrapperResult> DeleteCanvasFile(StorageFile file, bool hideConfirmation = false)
        {
            bool deletePermanently = false;

            if (App.AppSettings.UserSettings.ShowDeleteConfirmationDialog && !hideConfirmation)
            {
                DeleteConfirmationDialogViewModel deleteConfirmationDialogViewModel = new DeleteConfirmationDialogViewModel(Path.GetFileName(file.Path));
                DialogResult dialogOption = await App.DialogService.ShowDialog(deleteConfirmationDialogViewModel);

                if (dialogOption == DialogResult.Primary)
                {
                    deletePermanently = deleteConfirmationDialogViewModel.PermanentlyDelete;
                }
                else
                {
                    return(SafeWrapperResult.S_CANCEL);
                }
            }

            SafeWrapperResult result = await FilesystemOperations.DeleteItem(file, deletePermanently);

            return(result);
        }
        public static async Task <SafeWrapperResult> RenameItem(IStorageItem item, string newName, NameCollisionOption collision = NameCollisionOption.GenerateUniqueName)
        {
            SafeWrapperResult result = await SafeWrapperRoutines.SafeWrapAsync(async() => await item.RenameAsync(newName, collision).AsTask());

            return(result);
        }
 public ErrorOccurredEventArgs(SafeWrapperResult error, string errorMessage, bool showErrorImage = true)
 {
     this.error          = error;
     this.errorMessage   = errorMessage;
     this.showErrorImage = showErrorImage;
 }
 public InvalidContentTypeDataModel(SafeWrapperResult error, bool needsReinitialization)
 {
     this.error = error;
     this.needsReinitialization = needsReinitialization;
 }
Ejemplo n.º 7
0
 public CheckCanvasPageNavigationRequestedEventArgs(bool alsoRefreshActions = false, SafeWrapperResult error = null)
 {
     this.alsoRefreshActions = alsoRefreshActions;
     this.error = error;
 }
Ejemplo n.º 8
0
 public CollectionErrorRaisedEventArgs(SafeWrapperResult result)
 {
     this.result = result;
 }