CreateOperationEndPointFromIOPath() публичный статический Метод

Return the approperate operation end point based upon the IOPath type
public static CreateOperationEndPointFromIOPath ( IActivityIOPath target ) : IActivityIOOperationsEndPoint
target IActivityIOPath
Результат IActivityIOOperationsEndPoint
Пример #1
0
        void ValidateSourceAndDestinationContents(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, IDev2CRUDOperationTO args)
        {
            if (!args.Overwrite)
            {
                var srcContentsFolders = src.ListFoldersInDirectory(src.IOPath);
                foreach (var sourcePath in srcContentsFolders)
                {
                    var            sourceEndPoint      = ActivityIOFactory.CreateOperationEndPointFromIOPath(sourcePath);
                    IList <string> dirParts            = sourceEndPoint.IOPath.Path.Split(sourceEndPoint.PathSeperator().ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    var            directory           = dirParts.Last();
                    var            destinationPath     = ActivityIOFactory.CreatePathFromString(dst.Combine(directory), dst.IOPath.Username, dst.IOPath.Password, true, dst.IOPath.PrivateKeyFile);
                    var            destinationEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(destinationPath);
                    if (destinationEndPoint.PathExist(destinationEndPoint.IOPath))
                    {
                        ValidateSourceAndDestinationContents(sourceEndPoint, destinationEndPoint, args);
                    }
                }

                var srcContents          = src.ListFilesInDirectory(src.IOPath);
                var dstContents          = dst.ListFilesInDirectory(dst.IOPath);
                var sourceFileNames      = srcContents.Select(srcFile => GetFileNameFromEndPoint(src, srcFile)).ToList();
                var destinationFileNames = dstContents.Select(dstFile => GetFileNameFromEndPoint(dst, dstFile)).ToList();
                if (destinationFileNames.Count > 0)
                {
                    var commonFiles = sourceFileNames.Where(destinationFileNames.Contains).ToList();
                    if (commonFiles.Count > 0)
                    {
                        var fileNames = commonFiles.Aggregate("",
                                                              (current, commonFile) =>
                                                              current + "\r\n" + commonFile);
                        throw new Exception(string.Format(ErrorResource.FileExistInDestinationFolder, fileNames));
                    }
                }
            }
        }
Пример #2
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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        bool TransferFile(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, IDev2CRUDOperationTO args, string path, IActivityIOPath p, bool result)
        {
            var tmpPath    = ActivityIOFactory.CreatePathFromString(path, dst.IOPath.Username, dst.IOPath.Password, true, dst.IOPath.PrivateKeyFile);
            var tmpEp      = ActivityIOFactory.CreateOperationEndPointFromIOPath(tmpPath);
            var whereToPut = GetWhereToPut(src, dst);

            using (var s = src.Get(p, _filesToDelete))
            {
                if (tmpEp.Put(s, tmpEp.IOPath, args, whereToPut, _filesToDelete) < 0)
                {
                    result = false;
                }
                s.Close();
                s.Dispose();
            }
            return(result);
        }
Пример #5
0
        string TransferTempZipFileToDestination(IActivityIOOperationsEndPoint src,
                                                IActivityIOOperationsEndPoint dst, IDev2ZipOperationTO args,
                                                string tmpZip)
        {
            string result;

            using (Stream s2 = new MemoryStream(_fileWrapper.ReadAllBytes(tmpZip)))
            {
                dst =
                    ActivityIOFactory.CreateOperationEndPointFromIOPath(
                        ActivityIOFactory.CreatePathFromString(dst.IOPath.Path, dst.IOPath.Username,
                                                               dst.IOPath.Password, true, dst.IOPath.PrivateKeyFile));

                var zipTransferArgs = new Dev2CRUDOperationTO(args.Overwrite);

                result = ResultOk;

                if (src.RequiresLocalTmpStorage())
                {
                    if (dst.Put(s2, dst.IOPath, zipTransferArgs, null, _filesToDelete) < 0)
                    {
                        result = ResultBad;
                    }
                }
                else
                {
                    var fileInfo = new FileInfo(src.IOPath.Path);
                    if (fileInfo.Directory != null && Path.IsPathRooted(fileInfo.Directory.ToString()))
                    {
                        if (dst.Put(s2, dst.IOPath, zipTransferArgs, fileInfo.Directory.ToString(), _filesToDelete) < 0)
                        {
                            result = ResultBad;
                        }
                    }
                    else
                    {
                        if (dst.Put(s2, dst.IOPath, zipTransferArgs, null, _filesToDelete) < 0)
                        {
                            result = ResultBad;
                        }
                    }
                }
            }
            return(result);
        }
Пример #6
0
        public string ZipDirectoryToALocalTempFile(IActivityIOOperationsEndPoint src, IDev2ZipOperationTO args)
        {
            var tmpDir       = _common.CreateTmpDirectory();
            var tempFilename = CreateTmpFile();
            var tmpPath      = ActivityIOFactory.CreatePathFromString(tmpDir, "", "");
            var tmpEndPoint  = ActivityIOFactory.CreateOperationEndPointFromIOPath(tmpPath);

            TransferDirectoryContents(src, tmpEndPoint, new Dev2CRUDOperationTO(true));
            using (var zip = new ZipFile())
            {
                zip.SaveProgress += (sender, eventArgs) =>
                {
                    if (eventArgs.CurrentEntry != null)
                    {
                        Dev2Logger.Debug($"Event Type: {eventArgs.EventType} Total Entries: {eventArgs.EntriesTotal} Entries Saved: {eventArgs.EntriesSaved} Current Entry: {eventArgs.CurrentEntry.FileName}", GlobalConstants.WarewolfDebug);
                    }
                };
                if (args.ArchivePassword != string.Empty)
                {
                    zip.Password = args.ArchivePassword;
                }

                zip.CompressionLevel = _common.ExtractZipCompressionLevel(args.CompressionRatio);

                var toAdd = ListDirectory(tmpEndPoint, ReadTypes.FilesAndFolders);
                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);
            }
            var dir = new DirectoryWrapper();

            dir.CleanUp(tmpDir);

            return(tempFilename);
        }
Пример #7
0
 void RecursiveCopy(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, IDev2CRUDOperationTO args)
 {
     try
     {
         var srcContentsFolders = src.ListFoldersInDirectory(src.IOPath);
         Task.WaitAll(srcContentsFolders.Select(sourcePath => Task.Run(() =>
         {
             var sourceEndPoint      = ActivityIOFactory.CreateOperationEndPointFromIOPath(sourcePath);
             IList <string> dirParts = sourceEndPoint.IOPath.Path.Split(sourceEndPoint.PathSeperator().ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
             var destinationPath     = ActivityIOFactory.CreatePathFromString(dst.Combine(dirParts.Last()), dst.IOPath.Username, dst.IOPath.Password, true, dst.IOPath.PrivateKeyFile);
             var destinationEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(destinationPath);
             dst.CreateDirectory(destinationPath, args);
             TransferDirectoryContents(sourceEndPoint, destinationEndPoint, args);
         })).ToArray());
     }
     catch (AggregateException e)
     {
         var message = e.InnerExceptions.Where(exception => !string.IsNullOrEmpty(exception?.Message)).Aggregate(string.Empty, (current, exception) => current + exception.Message + "\r\n");
         throw new Exception(message, e);
     }
 }