Dev2.PathOperations.Dev2ActivityIOBroker.ZipDirectoryToALocalTempFile C# (CSharp) Method

ZipDirectoryToALocalTempFile() private method

private ZipDirectoryToALocalTempFile ( IActivityIOOperationsEndPoint src, Dev2ZipOperationTO args ) : string
src IActivityIOOperationsEndPoint
args Dev2ZipOperationTO
return string
        string ZipDirectoryToALocalTempFile(IActivityIOOperationsEndPoint src, Dev2ZipOperationTO args)
        {
            // tmp dir for files required
            var tmpDir = CreateTmpDirectory();
            var tempFilename = CreateTmpFile();
            var tmpPath = ActivityIOFactory.CreatePathFromString(tmpDir, "", "","");
            var tmpEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(tmpPath);

            // stage contents to local folder
            TransferDirectoryContents(src, tmpEndPoint, new Dev2CRUDOperationTO(true));
            using(var zip = new ZipFile())
            {
                zip.SaveProgress += (sender, eventArgs) =>
                {
                    if(eventArgs.CurrentEntry != null)
                    {
                        Dev2Logger.Log.Debug(string.Format("Event Type: {0} Total Entries: {1} Entries Saved: {2} Current Entry: {3}", eventArgs.EventType, eventArgs.EntriesTotal, eventArgs.EntriesSaved,  eventArgs.CurrentEntry.FileName));
                    }
                };
                // set password if exist
                if(args.ArchivePassword != string.Empty)
                {
                    zip.Password = args.ArchivePassword;
                }

                // compression ratio                    
                zip.CompressionLevel = ExtractZipCompressionLevel(args.CompressionRatio);

                var toAdd = ListDirectory(tmpEndPoint, ReadTypes.FilesAndFolders);
                // add all files to archive
                foreach(var p in toAdd)
                {
                    if(tmpEndPoint.PathIs(p) == enPathType.Directory)
                    {
                        var directoryPathInArchive = p.Path.Replace(tmpPath.Path, "");
                        zip.AddDirectory(p.Path, directoryPathInArchive);
                    }
                    else
                    {
                        zip.AddFile(p.Path, ".");
                    }
                }
                zip.Save(tempFilename);
            }

            // remove locally staged files
            DirectoryHelper.CleanUp(tmpDir);

            return tempFilename;
        }