示例#1
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);
        }
        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);
        }