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;
}