Exemple #1
0
        private static void ExecuteSubTaskCore(OperationListBaseModel Model)
        {
            Interlocked.Increment(ref RunningTaskCounter);

            try
            {
                CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                {
                    Model.UpdateStatus(OperationStatus.Preparing);
                }).AsTask().Wait();

                Model.PrepareSizeDataAsync().Wait();

                CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                {
                    Model.UpdateStatus(OperationStatus.Processing);
                    Model.UpdateProgress(0);
                }).AsTask().Wait();

                switch (Model)
                {
                case OperationListRemoteModel:
                {
                    using (FullTrustProcessController.ExclusiveUsage Exclusive = FullTrustProcessController.GetAvailableController().Result)
                    {
                        if (!Exclusive.Controller.PasteRemoteFile(Model.ToPath).Result)
                        {
                            CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                {
                                    Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_CopyFailUnexpectError_Content"));
                                }).AsTask().Wait();
                        }
                    }

                    break;
                }

                case OperationListCopyModel:
                {
                    try
                    {
                        CollisionOptions Option = CollisionOptions.None;

                        if (Model.FromPath.All((Item) => Path.GetDirectoryName(Item).Equals(Model.ToPath, StringComparison.OrdinalIgnoreCase)))
                        {
                            Option = CollisionOptions.RenameOnCollision;
                        }
                        else if (Model.FromPath.Select((SourcePath) => Path.Combine(Model.ToPath, Path.GetFileName(SourcePath)))
                                 .Any((DestPath) => FileSystemStorageItemBase.CheckExistAsync(DestPath).Result))
                        {
                            CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                {
                                    Model.UpdateStatus(OperationStatus.NeedAttention, Globalization.GetString("NameCollision"));
                                }).AsTask().Wait();

                            switch (Model.WaitForButtonAction())
                            {
                            case 0:
                            {
                                Option = CollisionOptions.OverrideOnCollision;
                                break;
                            }

                            case 1:
                            {
                                Option = CollisionOptions.RenameOnCollision;
                                break;
                            }
                            }
                        }

                        if (Model.Status == OperationStatus.Cancelled)
                        {
                            return;
                        }

                        using (FullTrustProcessController.ExclusiveUsage Exclusive = FullTrustProcessController.GetAvailableController().Result)
                        {
                            Exclusive.Controller.CopyAsync(Model.FromPath, Model.ToPath, Option, ProgressHandler: (s, e) =>
                                {
                                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                    {
                                        Model.UpdateProgress(e.ProgressPercentage);
                                    }).AsTask().Wait();
                                }).Wait();
                        }
                    }
                    catch (AggregateException Ae) when(Ae.InnerException is FileNotFoundException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_CopyFailForNotExist_Content"));
                            }).AsTask().Wait();
                    }
                    catch (AggregateException Ae) when(Ae.InnerException is InvalidOperationException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UnauthorizedPaste_Content"));
                            }).AsTask().Wait();
                    }
                    catch (Exception ex)
                    {
                        LogTracer.Log(ex, "Copy failed for unexpected error");

                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_CopyFailUnexpectError_Content"));
                            }).AsTask().Wait();
                    }

                    break;
                }

                case OperationListMoveModel:
                {
                    try
                    {
                        CollisionOptions Option = CollisionOptions.None;

                        if (Model.FromPath.Select((SourcePath) => Path.Combine(Model.ToPath, Path.GetFileName(SourcePath)))
                            .Any((DestPath) => FileSystemStorageItemBase.CheckExistAsync(DestPath).Result))
                        {
                            CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                {
                                    Model.UpdateStatus(OperationStatus.NeedAttention, Globalization.GetString("NameCollision"));
                                }).AsTask().Wait();

                            switch (Model.WaitForButtonAction())
                            {
                            case 0:
                            {
                                Option = CollisionOptions.OverrideOnCollision;
                                break;
                            }

                            case 1:
                            {
                                Option = CollisionOptions.RenameOnCollision;
                                break;
                            }
                            }
                        }

                        if (Model.Status == OperationStatus.Cancelled)
                        {
                            return;
                        }

                        using (FullTrustProcessController.ExclusiveUsage Exclusive = FullTrustProcessController.GetAvailableController().Result)
                        {
                            Exclusive.Controller.MoveAsync(Model.FromPath, Model.ToPath, Option, ProgressHandler: (s, e) =>
                                {
                                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                    {
                                        Model.UpdateProgress(e.ProgressPercentage);
                                    }).AsTask().Wait();
                                }).Wait();
                        }
                    }
                    catch (AggregateException Ae) when(Ae.InnerException is FileNotFoundException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_MoveFailForNotExist_Content"));
                            }).AsTask().Wait();
                    }
                    catch (AggregateException Ae) when(Ae.InnerException is FileCaputureException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_Item_Captured_Content"));
                            }).AsTask().Wait();
                    }
                    catch (AggregateException Ae) when(Ae.InnerException is InvalidOperationException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UnauthorizedPaste_Content"));
                            }).AsTask().Wait();
                    }
                    catch (Exception ex)
                    {
                        LogTracer.Log(ex, "Move failed for unexpected error");

                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_MoveFailUnexpectError_Content"));
                            }).AsTask().Wait();
                    }

                    break;
                }

                case OperationListDeleteModel DeleteModel:
                {
                    try
                    {
                        using (FullTrustProcessController.ExclusiveUsage Exclusive = FullTrustProcessController.GetAvailableController().Result)
                        {
                            Exclusive.Controller.DeleteAsync(DeleteModel.FromPath, DeleteModel.IsPermanentDelete, (s, e) =>
                                {
                                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                    {
                                        Model.UpdateProgress(e.ProgressPercentage);
                                    }).AsTask().Wait();
                                }).Wait();
                        }
                    }
                    catch (AggregateException Ae) when(Ae.InnerException is FileNotFoundException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_DeleteItemError_Content"));
                            }).AsTask().Wait();
                    }
                    catch (AggregateException Ae) when(Ae.InnerException is FileCaputureException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_Item_Captured_Content"));
                            }).AsTask().Wait();
                    }
                    catch (AggregateException Ae) when(Ae.InnerException is InvalidOperationException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UnauthorizedDelete_Content"));
                            }).AsTask().Wait();
                    }
                    catch (Exception ex)
                    {
                        LogTracer.Log(ex, "Delete failed for unexpected error");

                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_DeleteFailUnexpectError_Content"));
                            }).AsTask().Wait();
                    }

                    break;
                }

                case OperationListUndoModel UndoModel:
                {
                    try
                    {
                        using (FullTrustProcessController.ExclusiveUsage Exclusive = FullTrustProcessController.GetAvailableController().Result)
                        {
                            switch (UndoModel.UndoOperationKind)
                            {
                            case OperationKind.Copy:
                            {
                                Exclusive.Controller.DeleteAsync(Model.FromPath, true, (s, e) =>
                                        {
                                            CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                            {
                                                Model.UpdateProgress(e.ProgressPercentage);
                                            }).AsTask().Wait();
                                        }).Wait();

                                break;
                            }

                            case OperationKind.Move:
                            {
                                Exclusive.Controller.MoveAsync(Model.FromPath, Model.ToPath, IsUndoOperation: true, ProgressHandler: (s, e) =>
                                        {
                                            CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                            {
                                                Model.UpdateProgress(e.ProgressPercentage);
                                            }).AsTask().Wait();
                                        }).Wait();

                                break;
                            }

                            case OperationKind.Delete:
                            {
                                if (!Exclusive.Controller.RestoreItemInRecycleBinAsync(Model.FromPath).Result)
                                {
                                    throw new Exception();
                                }

                                break;
                            }
                            }
                        }
                    }
                    catch (AggregateException Ae) when(Ae.InnerException is FileNotFoundException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UndoFailForNotExist_Content"));
                            }).AsTask().Wait();
                    }
                    catch (AggregateException Ae) when(Ae.InnerException is FileCaputureException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_Item_Captured_Content"));
                            }).AsTask().Wait();
                    }
                    catch (AggregateException Ae) when(Ae.InnerException is InvalidOperationException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UnauthorizedUndo_Content"));
                            }).AsTask().Wait();
                    }
                    catch (Exception ex)
                    {
                        LogTracer.Log(ex, "Undo failed for unexpected error");

                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UndoFailure_Content"));
                            }).AsTask().Wait();
                    }

                    break;
                }

                case OperationListCompressionModel CModel:
                {
                    try
                    {
                        CompressionUtil.SetEncoding(Encoding.Default);

                        switch (CModel.Type)
                        {
                        case CompressionType.Zip:
                        {
                            CompressionUtil.CreateZipAsync(CModel.FromPath, CModel.ToPath, CModel.Level, CModel.Algorithm, (s, e) =>
                                    {
                                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                        {
                                            Model.UpdateProgress(e.ProgressPercentage);
                                        }).AsTask().Wait();
                                    }).Wait();

                            break;
                        }

                        case CompressionType.Tar:
                        {
                            CompressionUtil.CreateTarAsync(CModel.FromPath, CModel.ToPath, CModel.Level, CModel.Algorithm, (s, e) =>
                                    {
                                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                        {
                                            Model.UpdateProgress(e.ProgressPercentage);
                                        }).AsTask().Wait();
                                    }).Wait();

                            break;
                        }

                        case CompressionType.Gzip:
                        {
                            if (CModel.FromPath.Length == 1)
                            {
                                CompressionUtil.CreateGzipAsync(CModel.FromPath.First(), CModel.ToPath, CModel.Level, (s, e) =>
                                        {
                                            CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                            {
                                                Model.UpdateProgress(e.ProgressPercentage);
                                            }).AsTask().Wait();
                                        }).Wait();
                            }
                            else
                            {
                                throw new ArgumentException("Gzip could not contains more than one item");
                            }

                            break;
                        }

                        case CompressionType.BZip2:
                        {
                            if (CModel.FromPath.Length == 1)
                            {
                                CompressionUtil.CreateBZip2Async(CModel.FromPath.First(), CModel.ToPath, (s, e) =>
                                        {
                                            CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                            {
                                                Model.UpdateProgress(e.ProgressPercentage);
                                            }).AsTask().Wait();
                                        }).Wait();
                            }
                            else
                            {
                                throw new ArgumentException("Gzip could not contains more than one item");
                            }

                            break;
                        }
                        }
                    }
                    catch (AggregateException Ae) when(Ae.InnerException is UnauthorizedAccessException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UnauthorizedCompression_Content"));
                            }).AsTask().Wait();
                    }
                    catch (AggregateException Ae) when(Ae.InnerException is FileNotFoundException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_LocateFileFailure_Content"));
                            }).AsTask().Wait();
                    }
                    catch (Exception ex)
                    {
                        LogTracer.Log(ex, "Compression error");

                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_CompressionError_Content"));
                            }).AsTask().Wait();
                    }

                    break;
                }

                case OperationListDecompressionModel DModel:
                {
                    try
                    {
                        CompressionUtil.SetEncoding(DModel.Encoding);

                        if (Model.FromPath.All((Item) => Item.EndsWith(".zip", StringComparison.OrdinalIgnoreCase) ||
                                               Item.EndsWith(".tar", StringComparison.OrdinalIgnoreCase) ||
                                               Item.EndsWith(".tar.gz", StringComparison.OrdinalIgnoreCase) ||
                                               Item.EndsWith(".tgz", StringComparison.OrdinalIgnoreCase) ||
                                               Item.EndsWith(".tar.bz2", StringComparison.OrdinalIgnoreCase) ||
                                               Item.EndsWith(".bz2", StringComparison.OrdinalIgnoreCase) ||
                                               Item.EndsWith(".gz", StringComparison.OrdinalIgnoreCase) ||
                                               Item.EndsWith(".rar", StringComparison.OrdinalIgnoreCase)))
                        {
                            CompressionUtil.ExtractAllAsync(Model.FromPath, Model.ToPath, DModel.ShouldCreateFolder, (s, e) =>
                                {
                                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                    {
                                        Model.UpdateProgress(e.ProgressPercentage);
                                    }).AsTask().Wait();
                                }).Wait();
                        }
                        else
                        {
                            throw new Exception(Globalization.GetString("QueueDialog_FileTypeIncorrect_Content"));
                        }
                    }
                    catch (AggregateException Ae) when(Ae.InnerException is UnauthorizedAccessException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UnauthorizedDecompression_Content"));
                            }).AsTask().Wait();
                    }
                    catch (AggregateException Ae) when(Ae.InnerException is FileNotFoundException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_LocateFileFailure_Content"));
                            }).AsTask().Wait();
                    }
                    catch (Exception ex)
                    {
                        LogTracer.Log(ex, "Decompression error");

                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_DecompressionError_Content"));
                            }).AsTask().Wait();
                    }

                    break;
                }
                }

                CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                {
                    if (Model.Status != OperationStatus.Error)
                    {
                        Model.UpdateProgress(100);
                        Model.UpdateStatus(OperationStatus.Completed);
                    }
                }).AsTask().Wait();
            }
            catch (Exception ex)
            {
                LogTracer.Log(ex, "A subthread in Task List threw an exception");
            }
            finally
            {
                Interlocked.Decrement(ref RunningTaskCounter);
            }
        }
Exemple #2
0
        private static void ExecuteTaskCore(OperationListBaseModel Model)
        {
            CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
            {
                Model.UpdateStatus(OperationStatus.Processing);
            }).AsTask().Wait();

            switch (Model)
            {
            case OperationListCompressionModel CModel:
            {
                try
                {
                    switch (CModel.Type)
                    {
                    case CompressionType.Zip:
                    {
                        CompressionUtil.CreateZipAsync(CModel.FromPath, CModel.ToPath, (int)CModel.Level, (s, e) =>
                                {
                                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                    {
                                        Model.UpdateProgress(e.ProgressPercentage);
                                    }).AsTask().Wait();
                                }).Wait();

                        break;
                    }

                    case CompressionType.Tar:
                    {
                        CompressionUtil.CreateTarAsync(CModel.FromPath, CModel.ToPath, (s, e) =>
                                {
                                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                    {
                                        Model.UpdateProgress(e.ProgressPercentage);
                                    }).AsTask().Wait();
                                }).Wait();

                        break;
                    }

                    case CompressionType.Gzip:
                    {
                        if (CModel.FromPath.Length == 1)
                        {
                            CompressionUtil.CreateGzipAsync(CModel.FromPath.First(), CModel.ToPath, (int)CModel.Level, (s, e) =>
                                    {
                                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                        {
                                            Model.UpdateProgress(e.ProgressPercentage);
                                        }).AsTask().Wait();
                                    }).Wait();
                        }
                        else
                        {
                            throw new ArgumentException("Gzip could not contains more than one item");
                        }

                        break;
                    }
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                        {
                            Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UnauthorizedCompression_Content"));
                        }).AsTask().Wait();
                }
                catch (FileNotFoundException)
                {
                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                        {
                            Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_LocateFileFailure_Content"));
                        }).AsTask().Wait();
                }
                catch (Exception ex)
                {
                    LogTracer.Log(ex, "Compression error");

                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                        {
                            Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_CompressionError_Content"));
                        }).AsTask().Wait();
                }

                break;
            }

            case OperationListDecompressionModel DModel:
            {
                try
                {
                    CompressionUtil.SetEncoding(DModel.Encoding);

                    if (Model.FromPath.All((Item) => Path.GetExtension(Item).Equals(".zip", StringComparison.OrdinalIgnoreCase)))
                    {
                        if (string.IsNullOrEmpty(Model.ToPath))
                        {
                            CompressionUtil.ExtractZipAsync(Model.FromPath, (s, e) =>
                                {
                                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                    {
                                        Model.UpdateProgress(e.ProgressPercentage);
                                    }).AsTask().Wait();
                                }).Wait();
                        }
                        else
                        {
                            CompressionUtil.ExtractZipAsync(Model.FromPath, Model.ToPath, (s, e) =>
                                {
                                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                    {
                                        Model.UpdateProgress(e.ProgressPercentage);
                                    }).AsTask().Wait();
                                }).Wait();
                        }
                    }
                    else if (Model.FromPath.All((Item) => Path.GetExtension(Item).Equals(".tar", StringComparison.OrdinalIgnoreCase)))
                    {
                        if (string.IsNullOrEmpty(Model.ToPath))
                        {
                            CompressionUtil.ExtractTarAsync(Model.FromPath, (s, e) =>
                                {
                                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                    {
                                        Model.UpdateProgress(e.ProgressPercentage);
                                    }).AsTask().Wait();
                                }).Wait();
                        }
                        else
                        {
                            CompressionUtil.ExtractTarAsync(Model.FromPath, Model.ToPath, (s, e) =>
                                {
                                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                    {
                                        Model.UpdateProgress(e.ProgressPercentage);
                                    }).AsTask().Wait();
                                }).Wait();
                        }
                    }
                    else if (Model.FromPath.All((Item) => Path.GetExtension(Item).Equals(".gz", StringComparison.OrdinalIgnoreCase)))
                    {
                        if (string.IsNullOrEmpty(Model.ToPath))
                        {
                            CompressionUtil.ExtractGZipAsync(Model.FromPath, (s, e) =>
                                {
                                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                    {
                                        Model.UpdateProgress(e.ProgressPercentage);
                                    }).AsTask().Wait();
                                }).Wait();
                        }
                        else
                        {
                            CompressionUtil.ExtractGZipAsync(Model.FromPath, Model.ToPath, (s, e) =>
                                {
                                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                    {
                                        Model.UpdateProgress(e.ProgressPercentage);
                                    }).AsTask().Wait();
                                }).Wait();
                        }
                    }
                    else
                    {
                        throw new Exception(Globalization.GetString("QueueDialog_FileTypeIncorrect_Content"));
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                        {
                            Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UnauthorizedDecompression_Content"));
                        }).AsTask().Wait();
                }
                catch (NotImplementedException)
                {
                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                        {
                            Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_CanNotDecompressEncrypted_Content"));
                        }).AsTask().Wait();
                }
                catch (FileNotFoundException)
                {
                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                        {
                            Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_LocateFileFailure_Content"));
                        }).AsTask().Wait();
                }
                catch (Exception ex)
                {
                    LogTracer.Log(ex, "Decompression error");

                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                        {
                            Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_DecompressionError_Content"));
                        }).AsTask().Wait();
                }

                break;
            }
            }

            CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
            {
                if (Model.Status != OperationStatus.Error)
                {
                    Model.UpdateProgress(100);
                    Model.UpdateStatus(OperationStatus.Complete);
                }
            }).AsTask().Wait();
        }
Exemple #3
0
        private static void ExecuteTaskCore(FullTrustProcessController.ExclusiveUsage Exclusive, OperationListBaseModel Model)
        {
            CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
            {
                Model.UpdateStatus(OperationStatus.Processing);
            }).AsTask().Wait();

            switch (Model)
            {
            case OperationListRemoteModel:
            {
                if (!Exclusive.Controller.PasteRemoteFile(Model.ToPath).Result)
                {
                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                        {
                            Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_CopyFailUnexpectError_Content"));
                        }).AsTask().Wait();
                }

                break;
            }

            case OperationListCopyModel:
            {
                try
                {
                    Exclusive.Controller.CopyAsync(Model.FromPath, Model.ToPath, ProgressHandler: (s, e) =>
                        {
                            Model.UpdateProgress(e.ProgressPercentage);
                        }).Wait();
                }
                catch (FileNotFoundException)
                {
                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                        {
                            Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_CopyFailForNotExist_Content"));
                        }).AsTask().Wait();
                }
                catch (InvalidOperationException)
                {
                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                        {
                            Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UnauthorizedPaste_Content"));
                        }).AsTask().Wait();
                }
                catch (Exception ex)
                {
                    LogTracer.Log(ex, "Copy failed for unexpected error");

                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                        {
                            Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_CopyFailUnexpectError_Content"));
                        }).AsTask().Wait();
                }

                break;
            }

            case OperationListMoveModel:
            {
                try
                {
                    Exclusive.Controller.MoveAsync(Model.FromPath, Model.ToPath, ProgressHandler: (s, e) =>
                        {
                            Model.UpdateProgress(e.ProgressPercentage);
                        }).Wait();
                }
                catch (FileNotFoundException)
                {
                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                        {
                            Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_MoveFailForNotExist_Content"));
                        }).AsTask().Wait();
                }
                catch (FileCaputureException)
                {
                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                        {
                            Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_Item_Captured_Content"));
                        }).AsTask().Wait();
                }
                catch (InvalidOperationException)
                {
                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                        {
                            Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UnauthorizedPaste_Content"));
                        }).AsTask().Wait();
                }
                catch (Exception ex)
                {
                    LogTracer.Log(ex, "Move failed for unexpected error");

                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                        {
                            Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_MoveFailUnexpectError_Content"));
                        }).AsTask().Wait();
                }

                break;
            }

            case OperationListDeleteModel DeleteModel:
            {
                try
                {
                    Exclusive.Controller.DeleteAsync(DeleteModel.FromPath, DeleteModel.IsPermanentDelete, ProgressHandler: (s, e) =>
                        {
                            Model.UpdateProgress(e.ProgressPercentage);
                        }).Wait();
                }
                catch (FileNotFoundException)
                {
                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                        {
                            Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_DeleteItemError_Content"));
                        }).AsTask().Wait();
                }
                catch (FileCaputureException)
                {
                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                        {
                            Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_Item_Captured_Content"));
                        }).AsTask().Wait();
                }
                catch (InvalidOperationException)
                {
                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                        {
                            Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UnauthorizedDelete_Content"));
                        }).AsTask().Wait();
                }
                catch (Exception ex)
                {
                    LogTracer.Log(ex, "Delete failed for unexpected error");

                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                        {
                            Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_DeleteFailUnexpectError_Content"));
                        }).AsTask().Wait();
                }

                break;
            }

            case OperationListUndoModel UndoModel:
            {
                try
                {
                    switch (UndoModel.UndoOperationKind)
                    {
                    case OperationKind.Copy:
                    {
                        Exclusive.Controller.DeleteAsync(Model.FromPath, true, true, (s, e) =>
                                {
                                    Model.UpdateProgress(e.ProgressPercentage);
                                }).Wait();

                        break;
                    }

                    case OperationKind.Move:
                    {
                        Exclusive.Controller.MoveAsync(Model.FromPath, Model.ToPath, true, (s, e) =>
                                {
                                    Model.UpdateProgress(e.ProgressPercentage);
                                }).Wait();

                        break;
                    }

                    case OperationKind.Delete:
                    {
                        if (!Exclusive.Controller.RestoreItemInRecycleBinAsync(Model.FromPath).Result)
                        {
                            throw new Exception();
                        }

                        break;
                    }
                    }
                }
                catch (Exception ex)
                {
                    LogTracer.Log(ex, "Undo failed for unexpected error");

                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                        {
                            Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UndoFailure_Content"));
                        }).AsTask().Wait();
                }

                break;
            }
            }

            CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
            {
                if (Model.Status != OperationStatus.Error)
                {
                    Model.UpdateProgress(100);
                    Model.UpdateStatus(OperationStatus.Complete);
                }
            }).AsTask().Wait();
        }
Exemple #4
0
        private static void ExecuteSubTaskCore(OperationListBaseModel Model)
        {
            Interlocked.Increment(ref RunningTaskCounter);

            try
            {
                CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                {
                    Model.UpdateStatus(OperationStatus.Preparing);
                }).AsTask().Wait();

                Model.PrepareSizeDataAsync().Wait();

                CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                {
                    Model.UpdateStatus(OperationStatus.Processing);
                    Model.UpdateProgress(0);
                }).AsTask().Wait();

                switch (Model)
                {
                case OperationListRemoteModel:
                {
                    using (FullTrustProcessController.ExclusiveUsage Exclusive = FullTrustProcessController.GetAvailableController().Result)
                    {
                        if (!Exclusive.Controller.PasteRemoteFile(Model.ToPath).Result)
                        {
                            CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                {
                                    Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_CopyFailUnexpectError_Content"));
                                }).AsTask().Wait();
                        }
                    }

                    break;
                }

                case OperationListCopyModel:
                {
                    try
                    {
                        using (FullTrustProcessController.ExclusiveUsage Exclusive = FullTrustProcessController.GetAvailableController().Result)
                        {
                            Exclusive.Controller.CopyAsync(Model.FromPath, Model.ToPath, ProgressHandler: (s, e) =>
                                {
                                    Model.UpdateProgress(e.ProgressPercentage);
                                }).Wait();
                        }
                    }
                    catch (FileNotFoundException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_CopyFailForNotExist_Content"));
                            }).AsTask().Wait();
                    }
                    catch (InvalidOperationException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UnauthorizedPaste_Content"));
                            }).AsTask().Wait();
                    }
                    catch (Exception ex)
                    {
                        LogTracer.Log(ex, "Copy failed for unexpected error");

                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_CopyFailUnexpectError_Content"));
                            }).AsTask().Wait();
                    }

                    break;
                }

                case OperationListMoveModel:
                {
                    try
                    {
                        using (FullTrustProcessController.ExclusiveUsage Exclusive = FullTrustProcessController.GetAvailableController().Result)
                        {
                            Exclusive.Controller.MoveAsync(Model.FromPath, Model.ToPath, ProgressHandler: (s, e) =>
                                {
                                    Model.UpdateProgress(e.ProgressPercentage);
                                }).Wait();
                        }
                    }
                    catch (FileNotFoundException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_MoveFailForNotExist_Content"));
                            }).AsTask().Wait();
                    }
                    catch (FileCaputureException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_Item_Captured_Content"));
                            }).AsTask().Wait();
                    }
                    catch (InvalidOperationException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UnauthorizedPaste_Content"));
                            }).AsTask().Wait();
                    }
                    catch (Exception ex)
                    {
                        LogTracer.Log(ex, "Move failed for unexpected error");

                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_MoveFailUnexpectError_Content"));
                            }).AsTask().Wait();
                    }

                    break;
                }

                case OperationListDeleteModel DeleteModel:
                {
                    try
                    {
                        using (FullTrustProcessController.ExclusiveUsage Exclusive = FullTrustProcessController.GetAvailableController().Result)
                        {
                            Exclusive.Controller.DeleteAsync(DeleteModel.FromPath, DeleteModel.IsPermanentDelete, ProgressHandler: (s, e) =>
                                {
                                    Model.UpdateProgress(e.ProgressPercentage);
                                }).Wait();
                        }
                    }
                    catch (FileNotFoundException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_DeleteItemError_Content"));
                            }).AsTask().Wait();
                    }
                    catch (FileCaputureException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_Item_Captured_Content"));
                            }).AsTask().Wait();
                    }
                    catch (InvalidOperationException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UnauthorizedDelete_Content"));
                            }).AsTask().Wait();
                    }
                    catch (Exception ex)
                    {
                        LogTracer.Log(ex, "Delete failed for unexpected error");

                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_DeleteFailUnexpectError_Content"));
                            }).AsTask().Wait();
                    }

                    break;
                }

                case OperationListUndoModel UndoModel:
                {
                    try
                    {
                        using (FullTrustProcessController.ExclusiveUsage Exclusive = FullTrustProcessController.GetAvailableController().Result)
                        {
                            switch (UndoModel.UndoOperationKind)
                            {
                            case OperationKind.Copy:
                            {
                                Exclusive.Controller.DeleteAsync(Model.FromPath, true, true, (s, e) =>
                                        {
                                            Model.UpdateProgress(e.ProgressPercentage);
                                        }).Wait();

                                break;
                            }

                            case OperationKind.Move:
                            {
                                Exclusive.Controller.MoveAsync(Model.FromPath, Model.ToPath, true, (s, e) =>
                                        {
                                            Model.UpdateProgress(e.ProgressPercentage);
                                        }).Wait();

                                break;
                            }

                            case OperationKind.Delete:
                            {
                                if (!Exclusive.Controller.RestoreItemInRecycleBinAsync(Model.FromPath).Result)
                                {
                                    throw new Exception();
                                }

                                break;
                            }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        LogTracer.Log(ex, "Undo failed for unexpected error");

                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UndoFailure_Content"));
                            }).AsTask().Wait();
                    }

                    break;
                }

                case OperationListCompressionModel CModel:
                {
                    try
                    {
                        switch (CModel.Type)
                        {
                        case CompressionType.Zip:
                        {
                            CompressionUtil.CreateZipAsync(CModel.FromPath, CModel.ToPath, (int)CModel.Level, (s, e) =>
                                    {
                                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                        {
                                            Model.UpdateProgress(e.ProgressPercentage);
                                        }).AsTask().Wait();
                                    }).Wait();

                            break;
                        }

                        case CompressionType.Tar:
                        {
                            CompressionUtil.CreateTarAsync(CModel.FromPath, CModel.ToPath, (s, e) =>
                                    {
                                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                        {
                                            Model.UpdateProgress(e.ProgressPercentage);
                                        }).AsTask().Wait();
                                    }).Wait();

                            break;
                        }

                        case CompressionType.Gzip:
                        {
                            if (CModel.FromPath.Length == 1)
                            {
                                CompressionUtil.CreateGzipAsync(CModel.FromPath.First(), CModel.ToPath, (int)CModel.Level, (s, e) =>
                                        {
                                            CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                            {
                                                Model.UpdateProgress(e.ProgressPercentage);
                                            }).AsTask().Wait();
                                        }).Wait();
                            }
                            else
                            {
                                throw new ArgumentException("Gzip could not contains more than one item");
                            }

                            break;
                        }
                        }
                    }
                    catch (UnauthorizedAccessException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UnauthorizedCompression_Content"));
                            }).AsTask().Wait();
                    }
                    catch (FileNotFoundException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_LocateFileFailure_Content"));
                            }).AsTask().Wait();
                    }
                    catch (Exception ex)
                    {
                        LogTracer.Log(ex, "Compression error");

                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_CompressionError_Content"));
                            }).AsTask().Wait();
                    }

                    break;
                }

                case OperationListDecompressionModel DModel:
                {
                    try
                    {
                        CompressionUtil.SetEncoding(DModel.Encoding);

                        if (Model.FromPath.All((Item) => Path.GetExtension(Item).Equals(".zip", StringComparison.OrdinalIgnoreCase)))
                        {
                            if (string.IsNullOrEmpty(Model.ToPath))
                            {
                                CompressionUtil.ExtractZipAsync(Model.FromPath, (s, e) =>
                                    {
                                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                        {
                                            Model.UpdateProgress(e.ProgressPercentage);
                                        }).AsTask().Wait();
                                    }).Wait();
                            }
                            else
                            {
                                CompressionUtil.ExtractZipAsync(Model.FromPath, Model.ToPath, (s, e) =>
                                    {
                                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                        {
                                            Model.UpdateProgress(e.ProgressPercentage);
                                        }).AsTask().Wait();
                                    }).Wait();
                            }
                        }
                        else if (Model.FromPath.All((Item) => Path.GetExtension(Item).Equals(".tar", StringComparison.OrdinalIgnoreCase)))
                        {
                            if (string.IsNullOrEmpty(Model.ToPath))
                            {
                                CompressionUtil.ExtractTarAsync(Model.FromPath, (s, e) =>
                                    {
                                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                        {
                                            Model.UpdateProgress(e.ProgressPercentage);
                                        }).AsTask().Wait();
                                    }).Wait();
                            }
                            else
                            {
                                CompressionUtil.ExtractTarAsync(Model.FromPath, Model.ToPath, (s, e) =>
                                    {
                                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                        {
                                            Model.UpdateProgress(e.ProgressPercentage);
                                        }).AsTask().Wait();
                                    }).Wait();
                            }
                        }
                        else if (Model.FromPath.All((Item) => Path.GetExtension(Item).Equals(".gz", StringComparison.OrdinalIgnoreCase)))
                        {
                            if (string.IsNullOrEmpty(Model.ToPath))
                            {
                                CompressionUtil.ExtractGZipAsync(Model.FromPath, (s, e) =>
                                    {
                                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                        {
                                            Model.UpdateProgress(e.ProgressPercentage);
                                        }).AsTask().Wait();
                                    }).Wait();
                            }
                            else
                            {
                                CompressionUtil.ExtractGZipAsync(Model.FromPath, Model.ToPath, (s, e) =>
                                    {
                                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                        {
                                            Model.UpdateProgress(e.ProgressPercentage);
                                        }).AsTask().Wait();
                                    }).Wait();
                            }
                        }
                        else
                        {
                            throw new Exception(Globalization.GetString("QueueDialog_FileTypeIncorrect_Content"));
                        }
                    }
                    catch (UnauthorizedAccessException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_UnauthorizedDecompression_Content"));
                            }).AsTask().Wait();
                    }
                    catch (NotImplementedException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_CanNotDecompressEncrypted_Content"));
                            }).AsTask().Wait();
                    }
                    catch (FileNotFoundException)
                    {
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_LocateFileFailure_Content"));
                            }).AsTask().Wait();
                    }
                    catch (Exception ex)
                    {
                        LogTracer.Log(ex, "Decompression error");

                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                Model.UpdateStatus(OperationStatus.Error, Globalization.GetString("QueueDialog_DecompressionError_Content"));
                            }).AsTask().Wait();
                    }

                    break;
                }
                }

                CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                {
                    if (Model.Status != OperationStatus.Error)
                    {
                        Model.UpdateProgress(100);
                        Model.UpdateStatus(OperationStatus.Complete);
                    }
                }).AsTask().Wait();
            }
            catch (Exception ex)
            {
                LogTracer.Log(ex, "A subthread in Task List threw an exception");
            }
            finally
            {
                Interlocked.Decrement(ref RunningTaskCounter);
            }
        }