Esempio n. 1
0
        public void ExtractFile(IDev2UnZipOperationTO args, ZipFile zip, string extractFromPath)
        {
            if (zip != null)
            {
                using (zip)
                {
                    if (!string.IsNullOrEmpty(args.ArchivePassword))
                    {
                        zip.Password = args.ArchivePassword;
                    }

                    foreach (var ze in zip)
                    {
                        try
                        {
                            ze.Extract(extractFromPath,
                                       args.Overwrite
                                           ? ExtractExistingFileAction.OverwriteSilently
                                           : ExtractExistingFileAction.DoNotOverwrite);
                        }
                        catch (BadPasswordException bpe)
                        {
                            throw new Exception(ErrorResource.InvalidArchivePassword, bpe);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public void ExtractFile(IDev2UnZipOperationTO args, IIonicZipFileWrapper zip, string extractFromPath)
        {
            if (zip != null)
            {
                using (zip)
                {
                    if (!string.IsNullOrEmpty(args.ArchivePassword))
                    {
                        zip.Password = args.ArchivePassword;
                    }

                    foreach (var ze in zip)
                    {
                        try
                        {
                            ze.Extract(extractFromPath,
                                       args.Overwrite
                                           ? FileOverwrite.Yes
                                           : FileOverwrite.No);
                        }
                        catch (BadPasswordException bpe)
                        {
                            throw new Exception(ErrorResource.InvalidArchivePassword, bpe);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
 public string UnZip(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, IDev2UnZipOperationTO args)
 {
     Source               = src;
     Destination          = dst;
     Dev2UnZipOperationTO = args;
     return("Successful");
 }
Esempio n. 4
0
        string ValidateUnzipSourceDestinationFileOperation(IActivityIOOperationsEndPoint src,
                                                           IActivityIOOperationsEndPoint dst,
                                                           IDev2UnZipOperationTO args,
                                                           Func <string> performAfterValidation)
        {
            _common.ValidateSourceAndDestinationPaths(src, dst);

            if (dst.PathIs(dst.IOPath) != enPathType.Directory)
            {
                throw new Exception(ErrorResource.DestinationMustBeADirectory);
            }

            if (src.PathIs(src.IOPath) != enPathType.File)
            {
                throw new Exception(ErrorResource.SourceMustBeAFile);
            }

            if (!args.Overwrite && dst.PathExist(dst.IOPath))
            {
                throw new Exception(ErrorResource.DestinationDirectoryExist);
            }

            return(performAfterValidation?.Invoke());
        }
        public string UnZip(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, IDev2UnZipOperationTO args)
        {
            string status;

            try
            {
                status = _validator.ValidateUnzipSourceDestinationFileOperation(src, dst, args, () =>
                {
                    IIonicZipFileWrapper zip;
                    var tempFile = string.Empty;

                    if (src.RequiresLocalTmpStorage())
                    {
                        var tmpZip = _implementation.CreateTmpFile();
                        using (var s = src.Get(src.IOPath, _filesToDelete))
                        {
                            _fileWrapper.WriteAllBytes(tmpZip, s.ToByteArray());
                        }

                        tempFile = tmpZip;
                        zip      = _zipFileFactory.Read(tempFile);
                    }
                    else
                    {
                        zip = _zipFileFactory.Read(src.Get(src.IOPath, _filesToDelete));
                    }

                    if (dst.RequiresLocalTmpStorage())
                    {
                        var tempPath = _common.CreateTmpDirectory();
                        _common.ExtractFile(args, zip, tempPath);
                        var endPointPath = ActivityIOFactory.CreatePathFromString(tempPath, string.Empty, string.Empty);
                        var endPoint     = ActivityIOFactory.CreateOperationEndPointFromIOPath(endPointPath);
                        Move(endPoint, dst, new Dev2CRUDOperationTO(args.Overwrite));
                    }
                    else
                    {
                        _common.ExtractFile(args, zip, dst.IOPath.Path);
                    }

                    if (src.RequiresLocalTmpStorage())
                    {
                        _fileWrapper.Delete(tempFile);
                    }

                    return(ActivityIOBrokerBaseDriver.ResultOk);
                });
            }
            finally
            {
                RemoveAllTmpFiles();
            }

            return(status);
        }
Esempio n. 6
0
        public string UnZip(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, IDev2UnZipOperationTO args)
        {
            string status;

            try
            {
                status = ValidateUnzipSourceDestinationFileOperation(src, dst, args, () =>
                {
                    ZipFile zip;
                    var tempFile = string.Empty;

                    if (src.RequiresLocalTmpStorage())
                    {
                        var tmpZip = CreateTmpFile();
                        using (var s = src.Get(src.IOPath, _filesToDelete))
                        {
                            _fileWrapper.WriteAllBytes(tmpZip, s.ToByteArray());
                        }

                        tempFile = tmpZip;
                        zip      = ZipFile.Read(tempFile);
                    }
                    else
                    {
                        zip = ZipFile.Read(src.Get(src.IOPath, _filesToDelete));
                    }

                    if (dst.RequiresLocalTmpStorage())
                    {
                        // unzip locally then Put the contents of the archive to the dst end-point
                        var tempPath = _common.CreateTmpDirectory();
                        _common.ExtractFile(args, zip, tempPath);
                        var endPointPath = ActivityIOFactory.CreatePathFromString(tempPath, string.Empty, string.Empty);
                        var endPoint     = ActivityIOFactory.CreateOperationEndPointFromIOPath(endPointPath);
                        Move(endPoint, dst, new Dev2CRUDOperationTO(args.Overwrite));
                    }
                    else
                    {
                        _common.ExtractFile(args, zip, dst.IOPath.Path);
                    }

                    if (src.RequiresLocalTmpStorage())
                    {
                        _fileWrapper.Delete(tempFile);
                    }

                    return(ResultOk);
                });
            }
            finally
            {
                _filesToDelete.ForEach(RemoveTmpFile);
            }

            return(status);
        }