PBI : 1172 Status : New Purpose : To provide the UnZip operation its args
Inheritance: IUnZip
Ejemplo n.º 1
0
        static void ExtractFile(Dev2UnZipOperationTO 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("Invalid archive password", bpe);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        string ValidateUnzipSourceDestinationFileOperation(IActivityIOOperationsEndPoint src,
                                                                   IActivityIOOperationsEndPoint dst,
                                                                   Dev2UnZipOperationTO args,
                                                                   Func<string> performAfterValidation)
        {
            ValidateSourceAndDestinationPaths(src, dst);

            if(dst.PathIs(dst.IOPath) != enPathType.Directory)
            {
                throw new Exception("Destination must be a directory");
            }

            if(src.PathIs(src.IOPath) != enPathType.File)
            {
                throw new Exception("Source must be a file");
            }

            if(!args.Overwrite && dst.PathExist(dst.IOPath))
            {
                throw new Exception("Destination directory already exists and overwrite is set to false");
            }

            return performAfterValidation();
        }
Ejemplo n.º 3
0
        public string UnZip(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst,
                            Dev2UnZipOperationTO args)
        {
            string status;

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

                        if(src.RequiresLocalTmpStorage())
                        {
                            var tmpZip = CreateTmpFile();
                            using(var s = src.Get(src.IOPath, _filesToDelete))
                            {
                                File.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 = CreateTmpDirectory();
                            ExtractFile(args, zip, tempPath);
                            var endPointPath = ActivityIOFactory.CreatePathFromString(tempPath, "", "","");
                            var endPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(endPointPath);
                            Move(endPoint, dst, new Dev2CRUDOperationTO(args.Overwrite));
                        }
                        else
                        {
                            ExtractFile(args, zip, dst.IOPath.Path);
                        }

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

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

            return status;
        }
 public string UnZip(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, Dev2UnZipOperationTO args)
 {
     Source = src;
     Destination = dst;
     Dev2UnZipOperationTO = args;
     return "Successful";
 }