本文整理汇总了C#中IActivityIOOperationsEndPoint.RequiresLocalTmpStorage方法的典型用法代码示例。如果您正苦于以下问题:C# IActivityIOOperationsEndPoint.RequiresLocalTmpStorage方法的具体用法?C# IActivityIOOperationsEndPoint.RequiresLocalTmpStorage怎么用?C# IActivityIOOperationsEndPoint.RequiresLocalTmpStorage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IActivityIOOperationsEndPoint
的用法示例。
在下文中一共展示了IActivityIOOperationsEndPoint.RequiresLocalTmpStorage方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ZipFileToALocalTempFile
string ZipFileToALocalTempFile(IActivityIOOperationsEndPoint src, Dev2ZipOperationTO args)
{
// normal not wild char file && not directory
var packFile = src.IOPath.Path;
var tempFileName = CreateTmpFile();
if(src.RequiresLocalTmpStorage())
{
string tempDir = CreateTmpDirectory();
var tmpFile = Path.Combine(tempDir,
src.IOPath.Path.Split(src.PathSeperator().ToCharArray(),
StringSplitOptions.RemoveEmptyEntries)
.Last());
packFile = tmpFile;
using(var s = src.Get(src.IOPath, _filesToDelete))
{
File.WriteAllBytes(tmpFile, s.ToByteArray());
}
}
using(var zip = new ZipFile())
{
// set password if exist
if(args.ArchivePassword != string.Empty)
{
zip.Password = args.ArchivePassword;
}
// compression ratio
zip.CompressionLevel = ExtractZipCompressionLevel(args.CompressionRatio);
// add all files to archive
zip.AddFile(packFile, ".");
zip.Save(tempFileName);
}
return tempFileName;
}
示例2: PutRaw
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
{
//.........这里部分代码省略.........
示例3: Copy
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;
}
示例4: UnZip
public string UnZip(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst,
Dev2UnZipOperationTO args)
{
string status;
try
{
status = ValidateUnzipSourceDestinationFileOperation(src, dst, args, () =>
{
ZipFile zip;
var tempFile = "";
if(src.RequiresLocalTmpStorage())
{
var tmpZip = CreateTmpFile();
using(var s = src.Get(src.IOPath, _filesToDelete))
{
File.WriteAllBytes(tmpZip, s.ToByteArray());
}
tempFile = tmpZip;
zip = ZipFile.Read(tempFile);
}
else
{
zip = ZipFile.Read(src.Get(src.IOPath, _filesToDelete));
}
if(dst.RequiresLocalTmpStorage())
{
// unzip locally then Put the contents of the archive to the dst end-point
var tempPath = CreateTmpDirectory();
ExtractFile(args, zip, tempPath);
var endPointPath = ActivityIOFactory.CreatePathFromString(tempPath, "", "","");
var endPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(endPointPath);
Move(endPoint, dst, new Dev2CRUDOperationTO(args.Overwrite));
}
else
{
ExtractFile(args, zip, dst.IOPath.Path);
}
if(src.RequiresLocalTmpStorage())
{
File.Delete(tempFile);
}
return ResultOk;
});
}
finally
{
_filesToDelete.ForEach(RemoveTmpFile);
}
return status;
}
示例5: TransferTempZipFileToDestination
string TransferTempZipFileToDestination(IActivityIOOperationsEndPoint src,
IActivityIOOperationsEndPoint dst, Dev2ZipOperationTO args,
string tmpZip)
{
// now transfer the zip file to the correct location
string result;
using(Stream s2 = new MemoryStream(File.ReadAllBytes(tmpZip)))
{
// add archive name to path
dst =
ActivityIOFactory.CreateOperationEndPointFromIOPath(
ActivityIOFactory.CreatePathFromString(dst.IOPath.Path, dst.IOPath.Username,
dst.IOPath.Password, true, dst.IOPath.PrivateKeyFile));
var zipTransferArgs = new Dev2CRUDOperationTO(args.Overwrite);
result = ResultOk;
if(src.RequiresLocalTmpStorage())
{
if(dst.Put(s2, dst.IOPath, zipTransferArgs, null, _filesToDelete) < 0)
{
result = ResultBad;
}
}
else
{
var fileInfo = new FileInfo(src.IOPath.Path);
if(fileInfo.Directory != null && Path.IsPathRooted(fileInfo.Directory.ToString()))
{
if(dst.Put(s2, dst.IOPath, zipTransferArgs, fileInfo.Directory.ToString(), _filesToDelete) < 0)
{
result = ResultBad;
}
}
else
{
if(dst.Put(s2, dst.IOPath, zipTransferArgs, null, _filesToDelete) < 0)
{
result = ResultBad;
}
}
}
}
return result;
}