Esempio n. 1
0
        protected override void Run(bool success)
        {
            base.Run(success);

            Logger.Trace("Unzip File: {0} to Path: {1}", archiveFilePath, extractedPath);

            try
            {
                zipHelper.Extract(archiveFilePath, extractedPath, Token, zipFileProgress, estimatedDurationProgress);
            }
            catch (Exception ex)
            {
                var message = "Error Unzipping file";

                Logger.Error(ex, message);
                throw new UnzipTaskException(message);
            }

            if (expectedMD5 != null)
            {
                var calculatedMD5 = fileSystem.CalculateFolderMD5(extractedPath);
                if (!calculatedMD5.Equals(expectedMD5, StringComparison.InvariantCultureIgnoreCase))
                {
                    extractedPath.DeleteIfExists();

                    var message = $"Extracted MD5: {calculatedMD5} Does not match expected: {expectedMD5}";
                    Logger.Error(message);

                    throw new UnzipTaskException(message);
                }
            }

            Logger.Trace("Completed Unzip");
        }
Esempio n. 2
0
        protected virtual SPath RunUnzip(bool success)
        {
            Logger.Trace("Unzip File: {0} to Path: {1}", archiveFilePath, extractedPath);

            Exception exception = null;
            var       attempts  = 0;

            do
            {
                if (Token.IsCancellationRequested)
                {
                    break;
                }

                exception = null;
                try
                {
                    success = zipHelper.Extract(archiveFilePath, extractedPath, Token,
                                                (file, size) =>
                    {
                        var task = new TaskData(file, size);
                        tasks.Add(file, task);
                        progressReporter.UpdateProgress(task.progress);
                    },
                                                (fileRead, fileTotal, file) =>
                    {
                        if (tasks.TryGetValue(file, out TaskData task))
                        {
                            task.UpdateProgress(fileRead, fileTotal);
                            progressReporter.UpdateProgress(task.progress);
                            if (fileRead == fileTotal)
                            {
                                tasks.Remove(file);
                            }
                        }
                        return(!Token.IsCancellationRequested);
                    });

                    if (!success)
                    {
                        //extractedPath.DeleteIfExists();
                        var message = $"Failed to extract {archiveFilePath} to {extractedPath}";
                        exception = new UnzipException(message);
                    }
                }
                catch (Exception ex)
                {
                    exception = ex;
                    success   = false;
                }
            } while (attempts++ < RetryCount);

            if (!success)
            {
                Token.ThrowIfCancellationRequested();
                throw new UnzipException("Error unzipping file", exception);
            }
            return(extractedPath);
        }
Esempio n. 3
0
        protected virtual NPath RunUnzip(bool success)
        {
            Logger.Trace("Unzip File: {0} to Path: {1}", archiveFilePath, extractedPath);

            Exception exception = null;
            var       attempts  = 0;

            do
            {
                if (Token.IsCancellationRequested)
                {
                    break;
                }

                exception = null;
                try
                {
                    success = zipHelper.Extract(archiveFilePath, extractedPath, Token,
                                                (value, total) =>
                    {
                        UpdateProgress(value, total);
                        return(!Token.IsCancellationRequested);
                    });

                    if (!success)
                    {
                        extractedPath.DeleteIfExists();

                        var message = $"Failed to extract {archiveFilePath} to {extractedPath}";
                        exception = new UnzipException(message);
                    }
                }
                catch (Exception ex)
                {
                    exception = ex;
                    success   = false;
                }
            } while (attempts++ < RetryCount);

            if (!success)
            {
                Token.ThrowIfCancellationRequested();
                throw new UnzipException("Error unzipping file", exception);
            }
            return(extractedPath);
        }