void AddMissingFileDirectoryParts(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)))
{
if(dst.PathIs(dst.IOPath) == enPathType.Directory)
{
var strings = src.IOPath.Path.Split(src.PathSeperator().ToCharArray(),
StringSplitOptions.RemoveEmptyEntries);
var lastPart = strings.Last();
dst.IOPath.Path = src.PathIs(src.IOPath) == enPathType.Directory
? Path.Combine(dst.IOPath.Path, lastPart)
: dst.IOPath.Path.Replace(lastPart, "");
}
}
else
{
if(dst.PathIs(dst.IOPath) == enPathType.Directory && src.PathIs(src.IOPath) == enPathType.Directory)
{
var strings = src.IOPath.Path.Split(src.PathSeperator().ToCharArray(),
StringSplitOptions.RemoveEmptyEntries);
var lastPart = strings.Last();
dst.IOPath.Path = dst.Combine(lastPart);
}
}
}