示例#1
0
        public string Rename(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, IDev2CRUDOperationTO args)
        {
            string performRename()
            {
                if (src.PathIs(src.IOPath) != dst.PathIs(dst.IOPath))
                {
                    throw new Exception(ErrorResource.SourceAndDestinationNOTFilesOrDirectory);
                }
                if (dst.PathExist(dst.IOPath))
                {
                    if (!args.Overwrite)
                    {
                        throw new Exception(ErrorResource.DestinationDirectoryExist);
                    }
                    dst.Delete(dst.IOPath);
                }

                return(Move(src, dst, args));
            }

            try
            {
                return(performRename());
            }
            finally
            {
                RemoveAllTmpFiles();
            }
        }
示例#2
0
 bool PerformTransfer(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, IDev2CRUDOperationTO args, string origDstPath, IActivityIOPath p, bool result)
 {
     try
     {
         if (dst.PathIs(dst.IOPath) == enPathType.Directory)
         {
             var cpPath =
                 ActivityIOFactory.CreatePathFromString(
                     $"{origDstPath}{dst.PathSeperator()}{Dev2ActivityIOPathUtils.ExtractFileName(p.Path)}",
                     dst.IOPath.Username,
                     dst.IOPath.Password, true, dst.IOPath.PrivateKeyFile);
             var path = cpPath.Path;
             DoFileTransfer(src, dst, args, cpPath, p, path, ref result);
         }
         else
         {
             if (args.Overwrite || !dst.PathExist(dst.IOPath))
             {
                 var tmp  = origDstPath + @"\\" + Dev2ActivityIOPathUtils.ExtractFileName(p.Path);
                 var path = ActivityIOFactory.CreatePathFromString(tmp, dst.IOPath.Username, dst.IOPath.Password, dst.IOPath.PrivateKeyFile);
                 DoFileTransfer(src, dst, args, path, p, path.Path, ref result);
             }
         }
     }
     catch (Exception ex)
     {
         Dev2Logger.Error(ex, GlobalConstants.WarewolfError);
     }
     return(result);
 }
 void CreateSourceFileWithSomeDummyData()
 {
     try
     {
         Dev2Logger.Log.Debug(string.Format("Source File: {0}", ScenarioContext.Current.Get <string>(ActualSourceHolder)));
         var             broker = ActivityIOFactory.CreateOperationsBroker();
         IActivityIOPath source = ActivityIOFactory.CreatePathFromString(ScenarioContext.Current.Get <string>(ActualSourceHolder),
                                                                         ScenarioContext.Current.Get <string>(SourceUsernameHolder),
                                                                         ScenarioContext.Current.Get <string>(SourcePasswordHolder),
                                                                         true);
         var ops = ActivityIOFactory.CreatePutRawOperationTO(WriteType.Overwrite, Guid.NewGuid().ToString());
         IActivityIOOperationsEndPoint sourceEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(source);
         if (sourceEndPoint.PathIs(sourceEndPoint.IOPath) == enPathType.File)
         {
             var result = broker.PutRaw(sourceEndPoint, ops);
             if (result != "Success")
             {
                 result = broker.PutRaw(sourceEndPoint, ops);
                 if (result != "Success")
                 {
                     Dev2Logger.Log.Debug("Create Source File for file op test error");
                 }
             }
         }
     }
     catch (Exception e)
     {
         Dev2Logger.Log.Debug("Create Source File for file op test error", e);
     }
 }
示例#4
0
        public string CreateEndPoint(IActivityIOOperationsEndPoint dst, IDev2CRUDOperationTO args, bool createToFile)
        {
            var activityIOPath = dst.IOPath;
            var dirParts       = MakeDirectoryParts(activityIOPath, dst.PathSeperator());

            var ok = CreateDirectoriesForPath(dst, args, dirParts);

            if (!ok)
            {
                return(ResultBad);
            }



            var shouldCreateFile = dst.PathIs(dst.IOPath) == enPathType.File && createToFile;

            if (shouldCreateFile)
            {
                if (CreateFile(dst, args))
                {
                    return(ResultOk);
                }
            }
            else
            {
                return(ResultOk);
            }


            return(ResultBad);
        }
示例#5
0
        string ValidateZipSourceDestinationFileOperation(IActivityIOOperationsEndPoint src,
                                                         IActivityIOOperationsEndPoint dst,
                                                         IDev2ZipOperationTO args,
                                                         Func <string> performAfterValidation)
        {
            _common.AddMissingFileDirectoryParts(src, dst);


            if (dst.PathIs(dst.IOPath) == enPathType.Directory)
            {
                var sourcePart =
                    src.IOPath.Path.Split(src.PathSeperator().ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
                    .Last();
                if (src.PathIs(src.IOPath) == enPathType.File)
                {
                    var fileInfo = new FileInfo(sourcePart);
                    dst.IOPath.Path = dst.Combine(sourcePart.Replace(fileInfo.Extension, ".zip"));
                }
                else
                {
                    dst.IOPath.Path = dst.IOPath.Path + ".zip";
                }
            }
            else
            {
                var sourcePart =
                    dst.IOPath.Path.Split(dst.PathSeperator().ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
                    .Last();
                var fileInfo = new FileInfo(sourcePart);
                dst.IOPath.Path = dst.IOPath.Path.Replace(fileInfo.Extension, ".zip");
            }

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

            var opStatus = CreateEndPoint(dst, new Dev2CRUDOperationTO(args.Overwrite),
                                          dst.PathIs(dst.IOPath) == enPathType.Directory);

            if (!opStatus.Equals(ResultOk))
            {
                throw new Exception(string.Format(ErrorResource.RecursiveDirectoryCreateFailed, dst.IOPath.Path));
            }

            return(performAfterValidation());
        }
示例#6
0
        public string Copy(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, IDev2CRUDOperationTO args)
        {
            string status;

            try
            {
                status = ValidateCopySourceDestinationFileOperation(src, dst, args, () =>
                {
                    if (src.RequiresLocalTmpStorage())
                    {
                        if (dst.PathIs(dst.IOPath) == enPathType.Directory)
                        {
                            dst.IOPath.Path = dst.Combine(GetFileNameFromEndPoint(src));
                        }

                        using (var s = src.Get(src.IOPath, _filesToDelete))
                        {
                            dst.Put(s, dst.IOPath, args, Path.IsPathRooted(src.IOPath.Path) ? Path.GetDirectoryName(src.IOPath.Path) : null, _filesToDelete);
                            s.Close();
                            s.Dispose();
                        }
                    }
                    else
                    {
                        var sourceFile = new FileInfo(src.IOPath.Path);
                        if (dst.PathIs(dst.IOPath) == enPathType.Directory)
                        {
                            dst.IOPath.Path = dst.Combine(sourceFile.Name);
                        }

                        using (var s = src.Get(src.IOPath, _filesToDelete))
                        {
                            if (sourceFile.Directory != null)
                            {
                                dst.Put(s, dst.IOPath, args, sourceFile.Directory.ToString(), _filesToDelete);
                            }
                        }
                    }
                    return(ResultOk);
                });
            }
            finally
            {
                _filesToDelete.ForEach(RemoveTmpFile);
            }
            return(status);
        }
        protected static void RemovedFilesCreatedForTesting()
        {
            // ReSharper disable EmptyGeneralCatchClause


            Dev2Logger.Log.Debug("Cleanup");

            var    broker = ActivityIOFactory.CreateOperationsBroker();
            string destLocation;

            if (ScenarioContext.Current != null && ScenarioContext.Current.TryGetValue(CommonSteps.ActualDestinationHolder, out destLocation))
            {
                IActivityIOPath dst = ActivityIOFactory.CreatePathFromString(destLocation,
                                                                             ScenarioContext.Current.Get <string>(CommonSteps.DestinationUsernameHolder),
                                                                             ScenarioContext.Current.Get <string>(CommonSteps.DestinationPasswordHolder),
                                                                             true);
                IActivityIOOperationsEndPoint dstEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(dst);
                try
                {
                    if (dstEndPoint.PathIs(dstEndPoint.IOPath) == enPathType.File)
                    {
                        broker.Delete(dstEndPoint);
                    }
                }
                catch (Exception)
                {
                    Dev2Logger.Log.Debug("Cleanup Error");
                    //    throw;
                }
            }

            string sourceLocation;

            if (ScenarioContext.Current != null && ScenarioContext.Current.TryGetValue(CommonSteps.ActualSourceHolder, out sourceLocation))
            {
                IActivityIOPath source = ActivityIOFactory.CreatePathFromString(sourceLocation,
                                                                                ScenarioContext.Current.Get <string>(CommonSteps.SourceUsernameHolder),
                                                                                ScenarioContext.Current.Get <string>(CommonSteps.SourcePasswordHolder),
                                                                                true);
                IActivityIOOperationsEndPoint sourceEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(source);
                try
                {
                    if (sourceEndPoint.PathIs(sourceEndPoint.IOPath) == enPathType.File)
                    {
                        broker.Delete(sourceEndPoint);
                    }
                }
                catch (Exception)
                {
                    Dev2Logger.Log.Debug("Cleanup Error");
                    //The file may already be deleted
                    // throw;
                }
            }

            // SOME SILLY CHICKEN BUNDLED TWO DIS-JOIN OPERATIONS IN THIS METHOD.
            // THIS CAUSED THE SFTP SERVER TO NEVER SHUTDOWN WHEN THE COMMONSTEPS.ACTUALSOURCEHOLDER KEY WAS NOT PRESENT!
            // ;)
        }
        protected void RemovedFilesCreatedForTesting()
        {
            // ReSharper disable EmptyGeneralCatchClause



            var    broker = ActivityIOFactory.CreateOperationsBroker();
            string destLocation;

            if (scenarioContext != null && scenarioContext.TryGetValue(CommonSteps.ActualDestinationHolder, out destLocation))
            {
                IActivityIOPath dst = ActivityIOFactory.CreatePathFromString(destLocation,
                                                                             scenarioContext.Get <string>(CommonSteps.DestinationUsernameHolder),
                                                                             scenarioContext.Get <string>(CommonSteps.DestinationPasswordHolder),
                                                                             true);
                IActivityIOOperationsEndPoint dstEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(dst);
                try
                {
                    if (dstEndPoint.PathIs(dstEndPoint.IOPath) == enPathType.File)
                    {
                        broker.Delete(dstEndPoint);
                    }
                }
                catch (Exception)
                {
                    //    throw;
                }
            }

            string sourceLocation;

            if (scenarioContext != null && scenarioContext.TryGetValue(CommonSteps.ActualSourceHolder, out sourceLocation))
            {
                if (string.IsNullOrEmpty(sourceLocation))
                {
                    scenarioContext.TryGetValue(CommonSteps.SourceHolder, out sourceLocation);
                }
                if (string.IsNullOrEmpty(sourceLocation))
                {
                    return;
                }
                IActivityIOPath source = ActivityIOFactory.CreatePathFromString(sourceLocation,
                                                                                scenarioContext.Get <string>(CommonSteps.SourceUsernameHolder),
                                                                                scenarioContext.Get <string>(CommonSteps.SourcePasswordHolder),
                                                                                true);
                IActivityIOOperationsEndPoint sourceEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(source);
                try
                {
                    broker.Delete(sourceEndPoint);
                }
                catch (Exception)
                {
                    //The file may already be deleted
                }
            }
        }
示例#9
0
        protected static void RemovedFilesCreatedForTesting()
        {
            // ReSharper disable EmptyGeneralCatchClause


            Dev2Logger.Log.Debug("Cleanup");

            var    broker = ActivityIOFactory.CreateOperationsBroker();
            string destLocation;

            if (ScenarioContext.Current != null && ScenarioContext.Current.TryGetValue(CommonSteps.ActualDestinationHolder, out destLocation))
            {
                IActivityIOPath dst = ActivityIOFactory.CreatePathFromString(destLocation,
                                                                             ScenarioContext.Current.Get <string>(CommonSteps.DestinationUsernameHolder),
                                                                             ScenarioContext.Current.Get <string>(CommonSteps.DestinationPasswordHolder),
                                                                             true);
                IActivityIOOperationsEndPoint dstEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(dst);
                try
                {
                    if (dstEndPoint.PathIs(dstEndPoint.IOPath) == enPathType.File)
                    {
                        broker.Delete(dstEndPoint);
                    }
                }
                catch (Exception)
                {
                    Dev2Logger.Log.Debug("Cleanup Error");
                    //    throw;
                }
            }

            string sourceLocation;

            if (ScenarioContext.Current != null && ScenarioContext.Current.TryGetValue(CommonSteps.ActualSourceHolder, out sourceLocation))
            {
                IActivityIOPath source = ActivityIOFactory.CreatePathFromString(sourceLocation,
                                                                                ScenarioContext.Current.Get <string>(CommonSteps.SourceUsernameHolder),
                                                                                ScenarioContext.Current.Get <string>(CommonSteps.SourcePasswordHolder),
                                                                                true);
                IActivityIOOperationsEndPoint sourceEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(source);
                try
                {
                    if (sourceEndPoint.PathIs(sourceEndPoint.IOPath) == enPathType.File)
                    {
                        broker.Delete(sourceEndPoint);
                    }
                }
                catch (Exception)
                {
                    Dev2Logger.Log.Debug("Cleanup Error");
                    //The file may already be deleted
                }
            }
        }
        private string CopyRequiresLocalTmpStorage(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, IDev2CRUDOperationTO args)
        {
            if (dst.PathIs(dst.IOPath) == enPathType.Directory)
            {
                dst.IOPath.Path = dst.Combine(_implementation.GetFileNameFromEndPoint(src));
            }

            using (var s = src.Get(src.IOPath, _filesToDelete))
            {
                var result = dst.Put(s, dst.IOPath, args, Path.IsPathRooted(src.IOPath.Path) ? Path.GetDirectoryName(src.IOPath.Path) : null, _filesToDelete);
                s.Close();
                return(result == -1 ? ActivityIOBrokerBaseDriver.ResultBad : ActivityIOBrokerBaseDriver.ResultOk);
            }
        }
示例#11
0
        void CreateSourceFileWithSomeDummyData()
        {
            var             broker = ActivityIOFactory.CreateOperationsBroker();
            IActivityIOPath source = ActivityIOFactory.CreatePathFromString(ScenarioContext.Current.Get <string>(ActualSourceHolder),
                                                                            ScenarioContext.Current.Get <string>(SourceUsernameHolder),
                                                                            ScenarioContext.Current.Get <string>(SourcePasswordHolder),
                                                                            true);
            var ops = ActivityIOFactory.CreatePutRawOperationTO(WriteType.Overwrite, Guid.NewGuid().ToString());
            IActivityIOOperationsEndPoint sourceEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(source);

            if (sourceEndPoint.PathIs(sourceEndPoint.IOPath) == enPathType.File)
            {
                broker.PutRaw(sourceEndPoint, ops);
            }
        }
示例#12
0
 void CreateSourceFileWithSomeDummyData(int numberOfGuids = 1)
 {
     try
     {
         Dev2Logger.Debug(string.Format("Source File: {0}", scenarioContext.Get <string>(ActualSourceHolder)));
         var             broker = ActivityIOFactory.CreateOperationsBroker();
         IActivityIOPath source = ActivityIOFactory.CreatePathFromString(scenarioContext.Get <string>(ActualSourceHolder),
                                                                         scenarioContext.Get <string>(SourceUsernameHolder),
                                                                         scenarioContext.Get <string>(SourcePasswordHolder),
                                                                         true, "");
         StringBuilder sb = new StringBuilder();
         Enumerable.Range(1, numberOfGuids).ToList().ForEach(x => sb.Append(Guid.NewGuid().ToString()));
         var ops = ActivityIOFactory.CreatePutRawOperationTO(WriteType.Overwrite, sb.ToString());
         IActivityIOOperationsEndPoint sourceEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(source);
         if (sourceEndPoint.PathIs(sourceEndPoint.IOPath) == enPathType.File)
         {
             var result = broker.PutRaw(sourceEndPoint, ops);
             if (result != "Success")
             {
                 result = broker.PutRaw(sourceEndPoint, ops);
                 if (result != "Success")
                 {
                     Dev2Logger.Debug("Create Source File for file op test error");
                 }
             }
         }
         else if (sourceEndPoint.PathIs(sourceEndPoint.IOPath) == enPathType.Directory && source.Path.Contains("emptydir"))
         {
             broker.Create(sourceEndPoint, new Dev2CRUDOperationTO(true, false), false);
         }
     }
     catch (Exception e)
     {
         Dev2Logger.Debug("Create Source File for file op test error", e);
     }
 }
示例#13
0
        void EnsureFilesDontExists(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst)
        {
            if (dst.PathExist(dst.IOPath))
            {
                if (dst.PathIs(dst.IOPath) == enPathType.File)
                {
                    throw new Exception(ErrorResource.FileWithSameNameExist);
                }
                var dstContents          = dst.ListDirectory(dst.IOPath);
                var destinationFileNames = dstContents.Select(dstFile => GetFileNameFromEndPoint(dst, dstFile));
                var sourceFile           = GetFileNameFromEndPoint(src);

                if (destinationFileNames.Contains(sourceFile))
                {
                    throw new Exception(string.Format(ErrorResource.FileExistInDestinationFolder, sourceFile));
                }
            }
        }
示例#14
0
        public void ValidateSourceAndDestinationPaths(IActivityIOOperationsEndPoint src,
                                                      IActivityIOOperationsEndPoint dst)
        {
            if (src.IOPath.Path.Trim().Length == 0)
            {
                throw new Exception(ErrorResource.SourceCannotBeAnEmptyString);
            }

            var sourceParts = src.IOPath.Path.Split(src.PathSeperator().ToCharArray(),
                                                    StringSplitOptions.RemoveEmptyEntries).ToList();

            if (dst.IOPath.Path.Trim().Length == 0)
            {
                dst.IOPath.Path = src.IOPath.Path;
            }
            else
            {
                // TODO: verify if this condition is possible, UNC paths start with @"\\" but @"\\file" is always rooted
                if (!Path.IsPathRooted(dst.IOPath.Path) && IsNotFtpTypePath(dst.IOPath) && IsUncFileTypePath(dst.IOPath.Path))
                {
                    var lastPart = sourceParts.Last();

                    dst.IOPath.Path =
                        Path.Combine(src.PathIs(dst.IOPath) == enPathType.Directory
                                         ? src.IOPath.Path
                                         : src.IOPath.Path.Replace(lastPart, ""), dst.IOPath.Path);
                }
            }

            var destinationParts = dst.IOPath.Path.Split(dst.PathSeperator().ToCharArray(),
                                                         StringSplitOptions.RemoveEmptyEntries).ToList();

            while (destinationParts.Count > sourceParts.Count)
            {
                destinationParts.Remove(destinationParts.Last());
            }

            if (destinationParts.OrderBy(i => i).SequenceEqual(
                    sourceParts.OrderBy(i => i)))
            {
                throw new Exception(ErrorResource.DestinationDirectoryCannotBeAChild);
            }
        }
示例#15
0
        string ValidateRenameSourceAndDesinationTypes(IActivityIOOperationsEndPoint src,
                                                      IActivityIOOperationsEndPoint dst,
                                                      IDev2CRUDOperationTO args)
        {
            if (src.PathIs(src.IOPath) != dst.PathIs(dst.IOPath))
            {
                throw new Exception(ErrorResource.SourceAndDestinationNOTFilesOrDirectory);
            }
            if (dst.PathExist(dst.IOPath))
            {
                if (!args.Overwrite)
                {
                    throw new Exception(ErrorResource.DestinationDirectoryExist);
                }
                dst.Delete(dst.IOPath);
            }

            return(Move(src, dst, args));
        }
        public string Zip(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, IDev2ZipOperationTO args)
        {
            string status;

            try
            {
                status = _validator.ValidateZipSourceDestinationFileOperation(src, dst, args, () =>
                {
                    string tempFileName;

                    tempFileName = src.PathIs(src.IOPath) == enPathType.Directory || Dev2ActivityIOPathUtils.IsStarWildCard(src.IOPath.Path) ? _implementation.ZipDirectoryToALocalTempFile(src, args) : _implementation.ZipFileToALocalTempFile(src, args);

                    return(_implementation.TransferTempZipFileToDestination(src, dst, args, tempFileName));
                });
            }
            finally
            {
                RemoveAllTmpFiles();
            }
            return(status);
        }
示例#17
0
        public string Zip(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, IDev2ZipOperationTO args)
        {
            string status;

            try
            {
                status = ValidateZipSourceDestinationFileOperation(src, dst, args, () =>
                {
                    string tempFileName;

                    tempFileName = src.PathIs(src.IOPath) == enPathType.Directory || Dev2ActivityIOPathUtils.IsStarWildCard(src.IOPath.Path) ? ZipDirectoryToALocalTempFile(src, args) : ZipFileToALocalTempFile(src, args);

                    return(TransferTempZipFileToDestination(src, dst, args, tempFileName));
                });
            }
            finally
            {
                _filesToDelete.ForEach(RemoveTmpFile);
            }
            return(status);
        }
示例#18
0
        string ValidateCopySourceDestinationFileOperation(IActivityIOOperationsEndPoint src,
                                                          IActivityIOOperationsEndPoint dst,
                                                          IDev2CRUDOperationTO args,
                                                          Func <string> performAfterValidation)
        {
            var result = ResultOk;

            _common.ValidateSourceAndDestinationPaths(src, dst);
            var opStatus = CreateEndPoint(dst, args, dst.PathIs(dst.IOPath) == enPathType.Directory);

            if (!opStatus.Equals("Success"))
            {
                throw new Exception(string.Format(ErrorResource.RecursiveDirectoryCreateFailed, dst.IOPath.Path));
            }
            if (src.PathIs(src.IOPath) == enPathType.Directory)
            {
                if (!TransferDirectoryContents(src, dst, args))
                {
                    result = ResultBad;
                }
            }
            else
            {
                if (!args.Overwrite)
                {
                    EnsureFilesDontExists(src, dst);
                }

                if (!Dev2ActivityIOPathUtils.IsStarWildCard(src.IOPath.Path))
                {
                    return(performAfterValidation?.Invoke());
                }
                if (!TransferDirectoryContents(src, dst, args))
                {
                    result = ResultBad;
                }
            }

            return(result);
        }
        public string Copy(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, IDev2CRUDOperationTO args)
        {
            string status;

            try
            {
                status = _validator.ValidateCopySourceDestinationFileOperation(src, dst, args, () =>
                {
                    if (src.RequiresLocalTmpStorage())
                    {
                        return(CopyRequiresLocalTmpStorage(src, dst, args));
                    }
                    else
                    {
                        var sourceFile = _fileWrapper.Info(src.IOPath.Path);
                        if (dst.PathIs(dst.IOPath) == enPathType.Directory)
                        {
                            dst.IOPath.Path = dst.Combine(sourceFile.Name);
                        }

                        using (var s = src.Get(src.IOPath, _filesToDelete))
                        {
                            if (sourceFile.Directory != null)
                            {
                                var result = dst.Put(s, dst.IOPath, args, sourceFile.Directory.ToString(), _filesToDelete);

                                return(result == -1 ? ActivityIOBrokerBaseDriver.ResultBad : ActivityIOBrokerBaseDriver.ResultOk);
                            }
                        }
                    }
                    return(ActivityIOBrokerBaseDriver.ResultBad);
                });
            }
            finally
            {
                RemoveAllTmpFiles();
            }
            return(status);
        }
示例#20
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());
        }
示例#21
0
 static bool PerformTransfer(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, Dev2CRUDOperationTO args, string origDstPath, IActivityIOPath p, bool result)
 {
     try
     {
         if(dst.PathIs(dst.IOPath) == enPathType.Directory)
         {
             var cpPath =
                 ActivityIOFactory.CreatePathFromString(
                     string.Format("{0}{1}{2}", origDstPath, dst.PathSeperator(),
                         Dev2ActivityIOPathUtils.ExtractFileName(p.Path)),
                     dst.IOPath.Username,
                     dst.IOPath.Password, true,dst.IOPath.PrivateKeyFile);
             var path = cpPath.Path;
             DoFileTransfer(src, dst, args, cpPath, p, path, ref result);
         }
         else if(args.Overwrite || !dst.PathExist(dst.IOPath))
         {
             var tmp = origDstPath + "\\" + Dev2ActivityIOPathUtils.ExtractFileName(p.Path);
             var path = ActivityIOFactory.CreatePathFromString(tmp, dst.IOPath.Username, dst.IOPath.Password, dst.IOPath.PrivateKeyFile);
             DoFileTransfer(src, dst, args, path, p, path.Path, ref result);
         }
     }
     catch(Exception ex)
     {
         Dev2Logger.Log.Error(ex);
     }
     return result;
 }
示例#22
0
        string ValidateRenameSourceAndDesinationTypes(IActivityIOOperationsEndPoint src,
                                                              IActivityIOOperationsEndPoint dst,
                                                              Dev2CRUDOperationTO args)
        {
            //ensures that the source and destination locations are of the same type
            if(src.PathIs(src.IOPath) != dst.PathIs(dst.IOPath))
            {
                throw new Exception("Source and destination need to be both files or directories");
            }

            //Rename Tool if the file/folder exists then delete it and put the source there
            if(dst.PathExist(dst.IOPath))
            {
                if(!args.Overwrite)
                {
                    throw new Exception("Destination directory already exists and overwrite is set to false");
                }

                //Clear the existing folder
                dst.Delete(dst.IOPath);
            }

            return Move(src, dst, args);
        }
示例#23
0
        string ValidateCopySourceDestinationFileOperation(IActivityIOOperationsEndPoint src,
                                                                  IActivityIOOperationsEndPoint dst,
                                                                  Dev2CRUDOperationTO args,
                                                                  Func<string> performAfterValidation)
        {
            var result = ResultOk;
            ValidateSourceAndDestinationPaths(src, dst);

            //ensures destination folder structure exists
            var opStatus = CreateEndPoint(dst, args, dst.PathIs(dst.IOPath) == enPathType.Directory);
            if(!opStatus.Equals("Success"))
            {
                throw new Exception("Recursive Directory Create Failed For [ " + dst.IOPath.Path + " ]");
            }

            //transfer contents to destination when the source is a directory
            if(src.PathIs(src.IOPath) == enPathType.Directory)
            {
                if(!TransferDirectoryContents(src, dst, args))
                {
                    result = ResultBad;
                }
            }
            else
            {
                if(!args.Overwrite)
                {
                    EnsureFilesDontExists(src, dst);
                }

                if(!Dev2ActivityIOPathUtils.IsStarWildCard(src.IOPath.Path))
                {
                    return performAfterValidation();
                }

                // we have star wild cards to deal with
                if(!TransferDirectoryContents(src, dst, args))
                {
                    result = ResultBad;
                }
            }

            return result;
        }
示例#24
0
        string CreateEndPoint(IActivityIOOperationsEndPoint dst, IDev2CRUDOperationTO args, bool createToFile)
        {
            var result         = ResultOk;
            var activityIOPath = dst.IOPath;
            var dirParts       = MakeDirectoryParts(activityIOPath, dst.PathSeperator());

            var deepestIndex = -1;
            var startDepth   = dirParts.Count - 1;

            var pos = startDepth;

            while (pos >= 0 && deepestIndex == -1)
            {
                var tmpPath = ActivityIOFactory.CreatePathFromString(dirParts[pos], activityIOPath.Username,
                                                                     activityIOPath.Password, true, activityIOPath.PrivateKeyFile);
                try
                {
                    if (dst.ListDirectory(tmpPath) != null)
                    {
                        deepestIndex = pos;
                    }
                }
                catch (Exception e)
                {
                    Dev2Logger.Warn(e.Message, "Warewolf Warn");
                }
                finally
                {
                    pos--;
                }
            }

            pos = deepestIndex + 1;
            var ok = true;

            var origPath = dst.IOPath;

            while (pos <= startDepth && ok)
            {
                var toCreate = ActivityIOFactory.CreatePathFromString(dirParts[pos], dst.IOPath.Username,
                                                                      dst.IOPath.Password, true, dst.IOPath.PrivateKeyFile);
                dst.IOPath = toCreate;
                ok         = CreateDirectory(dst, args);
                pos++;
            }

            dst.IOPath = origPath;

            if (!ok)
            {
                result = ResultBad;
            }
            else
            {
                if (dst.PathIs(dst.IOPath) == enPathType.File && createToFile && !CreateFile(dst, args))
                {
                    result = ResultBad;
                }
            }

            return(result);
        }
示例#25
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();
        }
示例#26
0
        void ValidateSourceAndDestinationPaths(IActivityIOOperationsEndPoint src,
                                                       IActivityIOOperationsEndPoint dst)
        {
            if(src.IOPath.Path.Trim().Length == 0)
            {
                throw new Exception("Source can not be an empty string");
            }

            var sourceParts = src.IOPath.Path.Split(src.PathSeperator().ToCharArray(),
                                                       StringSplitOptions.RemoveEmptyEntries).ToList();

            if(dst.IOPath.Path.Trim().Length == 0)
            {
                dst.IOPath.Path = src.IOPath.Path;
            }
            else
            {
                if(!Path.IsPathRooted(dst.IOPath.Path) && IsNotFtpTypePath(dst.IOPath) && IsUncFileTypePath(dst.IOPath))
                {

                    var lastPart = sourceParts.Last();

                    dst.IOPath.Path =
                        Path.Combine(src.PathIs(dst.IOPath) == enPathType.Directory
                                         ? src.IOPath.Path
                                         : src.IOPath.Path.Replace(lastPart, ""), dst.IOPath.Path);
                }
            }

            var destinationParts = dst.IOPath.Path.Split(dst.PathSeperator().ToCharArray(),
                                                       StringSplitOptions.RemoveEmptyEntries).ToList();

            while(destinationParts.Count > sourceParts.Count)
            {
                destinationParts.Remove(destinationParts.Last());
            }

            if(destinationParts.OrderBy(i => i).SequenceEqual(
                 sourceParts.OrderBy(i => i)))
            {
                throw new Exception("Destination directory can not be a child of the source directory");
            }
        }
示例#27
0
        string ValidateZipSourceDestinationFileOperation(IActivityIOOperationsEndPoint src,
                                                                 IActivityIOOperationsEndPoint dst,
                                                                 Dev2ZipOperationTO args,
                                                                 Func<string> performAfterValidation)
        {
            AddMissingFileDirectoryParts(src, dst);


            if(dst.PathIs(dst.IOPath) == enPathType.Directory)
            {
                var sourcePart =
                    src.IOPath.Path.Split(src.PathSeperator().ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
                       .Last();
                if(src.PathIs(src.IOPath) == enPathType.File)
                {
                    var fileInfo = new FileInfo(sourcePart);
                    dst.IOPath.Path = dst.Combine(sourcePart.Replace(fileInfo.Extension, ".zip"));
                }
                else
                {
                    dst.IOPath.Path = dst.IOPath.Path + ".zip";
                }
            }
            else
            {
                var sourcePart =
                    dst.IOPath.Path.Split(dst.PathSeperator().ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
                       .Last();
                var fileInfo = new FileInfo(sourcePart);
                dst.IOPath.Path = dst.IOPath.Path.Replace(fileInfo.Extension, ".zip");
            }

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

            //ensures destination folder structure exists
            var opStatus = CreateEndPoint(dst, new Dev2CRUDOperationTO(args.Overwrite),
                                             dst.PathIs(dst.IOPath) == enPathType.Directory);
            if(!opStatus.Equals("Success"))
            {
                throw new Exception("Recursive Directory Create Failed For [ " + dst.IOPath.Path + " ]");
            }

            return performAfterValidation();
        }
示例#28
0
        void ValidateEndPoint(IActivityIOOperationsEndPoint endPoint, Dev2CRUDOperationTO args)
        {
            if(endPoint.IOPath.Path.Trim().Length == 0)
            {
                throw new Exception("Source can not be an empty string");
            }

            if(endPoint.PathExist(endPoint.IOPath) && !args.Overwrite)
            {
                var type = endPoint.PathIs(endPoint.IOPath) == enPathType.Directory ? "Directory" : "File";
                throw new Exception(string.Format("Destination {0} already exists and overwrite is set to false",
                                                  type));
            }
        }
示例#29
0
        public string Copy(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst,
                           Dev2CRUDOperationTO args)
        {
            string status;
            try
            {
                status = ValidateCopySourceDestinationFileOperation(src, dst, args, () =>
                    {
                        if(src.RequiresLocalTmpStorage())
                        {
                            if(dst.PathIs(dst.IOPath) == enPathType.Directory)
                            {
                                dst.IOPath.Path = dst.Combine(GetFileNameFromEndPoint(src));
                            }

                            using(var s = src.Get(src.IOPath, _filesToDelete))
                            {

                                // for flips sake quite putting short-hand notation in-line it causes bugs!!! ;)
                                dst.Put(s, dst.IOPath, args, Path.IsPathRooted(src.IOPath.Path) ? Path.GetDirectoryName(src.IOPath.Path) : null, _filesToDelete);
                                s.Close();
                                s.Dispose();
                            }
                        }
                        else
                        {
                            var sourceFile = new FileInfo(src.IOPath.Path);
                            if(dst.PathIs(dst.IOPath) == enPathType.Directory)
                            {
                                dst.IOPath.Path = dst.Combine(sourceFile.Name);
                            }

                            using(var s = src.Get(src.IOPath, _filesToDelete))
                            {
                                if(sourceFile.Directory != null)
                                {
                                    dst.Put(s, dst.IOPath, args, sourceFile.Directory.ToString(), _filesToDelete);
                                }
                            }
                        }
                        return ResultOk;
                    });
            }
            finally
            {
                _filesToDelete.ForEach(RemoveTmpFile);
            }
            return status;
        }
示例#30
0
        public string Zip(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, Dev2ZipOperationTO args)
        {
            string status;

            try
            {
                status = ValidateZipSourceDestinationFileOperation(src, dst, args, () =>
                {
                    string tempFileName;

                    if(src.PathIs(src.IOPath) == enPathType.Directory || Dev2ActivityIOPathUtils.IsStarWildCard(src.IOPath.Path))
                    {
                        tempFileName = ZipDirectoryToALocalTempFile(src, args);
                    }
                    else
                    {
                        tempFileName = ZipFileToALocalTempFile(src, args);
                    }

                    return TransferTempZipFileToDestination(src, dst, args, tempFileName);
                });
            }
            finally
            {
                _filesToDelete.ForEach(RemoveTmpFile);
            }
            return status;
        }
示例#31
0
        static void EnsureFilesDontExists(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst)
        {
            if(dst.PathExist(dst.IOPath))
            {
                // destination is a file
                if(dst.PathIs(dst.IOPath) == enPathType.File)
                {
                    throw new Exception(
                        "A file with the same name exists on the destination and overwrite is set to false");
                }

                //destination is a folder
                var dstContents = dst.ListDirectory(dst.IOPath);
                var destinationFileNames = dstContents.Select(dstFile => GetFileNameFromEndPoint(dst, dstFile));
                var sourceFile = GetFileNameFromEndPoint(src);

                if(destinationFileNames.Contains(sourceFile))
                {
                    throw new Exception(
                        "The following file(s) exist in the destination folder and overwrite is set to false :- " +
                        sourceFile);
                }
            }
        }
示例#32
0
        string CreateEndPoint(IActivityIOOperationsEndPoint dst, Dev2CRUDOperationTO args, bool createToFile)
        {
            var result = ResultOk;
            // check the the dir strucutre exist
            var activityIOPath = dst.IOPath;
            var dirParts = MakeDirectoryParts(activityIOPath, dst.PathSeperator());

            // check from lowest path part up
            var deepestIndex = -1;
            var startDepth = dirParts.Count - 1;

            var pos = startDepth;

            while(pos >= 0 && deepestIndex == -1)
            {
                var tmpPath = ActivityIOFactory.CreatePathFromString(dirParts[pos], activityIOPath.Username,
                                                                                 activityIOPath.Password, true,activityIOPath.PrivateKeyFile);
                try
                {
                    if(dst.ListDirectory(tmpPath) != null)
                    {
                        deepestIndex = pos;
                    }
                }
                // ReSharper disable EmptyGeneralCatchClause
                catch(Exception)
                // ReSharper restore EmptyGeneralCatchClause
                {
                    //Note that we doing a recursive create should the directory not exists
                }
                finally
                {
                    pos--;
                }
            }

            // now create all the directories we need ;)
            pos = deepestIndex + 1;
            var ok = true;

            var origPath = dst.IOPath;

            while(pos <= startDepth && ok)
            {
                var toCreate = ActivityIOFactory.CreatePathFromString(dirParts[pos], dst.IOPath.Username,
                                                                                  dst.IOPath.Password, true, dst.IOPath.PrivateKeyFile);
                dst.IOPath = toCreate;
                ok = CreateDirectory(dst, args);
                pos++;
            }

            dst.IOPath = origPath;

            // dir create failed
            if(!ok)
            {
                result = ResultBad;
            }
            else if(dst.PathIs(dst.IOPath) == enPathType.File && createToFile)
            {
                if(!CreateFile(dst, args))
                {
                    result = ResultBad;
                }
            }

            return result;
        }