void ValidateSourceAndDestinationContents(IActivityIOOperationsEndPoint src,
IActivityIOOperationsEndPoint dst,
Dev2CRUDOperationTO 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(
"The following file(s) exist in the destination folder and overwrite is set to false:- " +
fileNames);
}
}
}
}