public string PutRaw(IActivityIOOperationsEndPoint dst, Dev2PutRawOperationTO args)
{
var result = ResultOk;
// directory put?
// wild char put?
try
{
_fileLock.EnterWriteLock();
if(dst.RequiresLocalTmpStorage())
{
var tmp = CreateTmpFile();
switch(args.WriteType)
{
case WriteType.AppendBottom:
using(var s = dst.Get(dst.IOPath, _filesToDelete))
{
File.WriteAllBytes(tmp, s.ToByteArray());
File.AppendAllText(tmp, args.FileContents);
}
break;
case WriteType.AppendTop:
using(var s = dst.Get(dst.IOPath, _filesToDelete))
{
File.WriteAllText(tmp, args.FileContents);
AppendToTemp(s, tmp);
}
break;
default:
if(IsBase64(args.FileContents))
{
var data = Convert.FromBase64String(args.FileContents.Replace("Content-Type:BASE64", ""));
File.WriteAllBytes(tmp, data);
}
else
{
File.WriteAllText(tmp, args.FileContents);
}
break;
}
result = MoveTmpFileToDestination(dst, tmp, result);
}
else
{
if(File.Exists(dst.IOPath.Path))
{
var tmp = CreateTmpFile();
switch(args.WriteType)
{
case WriteType.AppendBottom:
File.AppendAllText(dst.IOPath.Path, args.FileContents);
result = ResultOk;
break;
case WriteType.AppendTop:
using(var s = dst.Get(dst.IOPath, _filesToDelete))
{
File.WriteAllText(tmp, args.FileContents);
AppendToTemp(s, tmp);
result = MoveTmpFileToDestination(dst, tmp, result);
RemoveTmpFile(tmp);
}
break;
default:
if(IsBase64(args.FileContents))
{
var data = Convert.FromBase64String(args.FileContents.Replace("Content-Type:BASE64", ""));
File.WriteAllBytes(tmp, data);
}
else
{
File.WriteAllText(tmp, args.FileContents);
}
result = MoveTmpFileToDestination(dst, tmp, result);
RemoveTmpFile(tmp);
break;
}
}
else
{
// we can write directly to the file
Dev2CRUDOperationTO newArgs = new Dev2CRUDOperationTO(true);
CreateEndPoint(dst, newArgs, true);
if(IsBase64(args.FileContents))
{
var data = Convert.FromBase64String(args.FileContents.Replace("Content-Type:BASE64", ""));
File.WriteAllBytes(dst.IOPath.Path, data);
}
else
{
File.WriteAllText(dst.IOPath.Path, args.FileContents);
}
}
}
}
finally
{
_fileLock.ExitWriteLock();
for(var index = _filesToDelete.Count-1; index > 0; index--)
{
var name = _filesToDelete[index];
RemoveTmpFile(name);
}
}
return result;
}