本文整理汇总了C#中IActivityIOPath类的典型用法代码示例。如果您正苦于以下问题:C# IActivityIOPath类的具体用法?C# IActivityIOPath怎么用?C# IActivityIOPath使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IActivityIOPath类属于命名空间,在下文中一共展示了IActivityIOPath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadFromFtp
void ReadFromFtp(IActivityIOPath path, ref Stream result)
{
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ConvertSslToPlain(path.Path));
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.UseBinary = true;
request.KeepAlive = true;
request.EnableSsl = EnableSsl(path);
if(path.IsNotCertVerifiable)
{
ServicePointManager.ServerCertificateValidationCallback = AcceptAllCertifications;
}
if(path.Username != string.Empty)
{
request.Credentials = new NetworkCredential(path.Username, path.Password);
}
using(var response = (FtpWebResponse)request.GetResponse())
{
using(var ftpStream = response.GetResponseStream())
{
if(ftpStream != null && ftpStream.CanRead)
{
byte[] data = ftpStream.ToByteArray();
result = new MemoryStream(data);
}
else
{
throw new Exception("Fail");
}
}
}
}
示例2: Get
public Stream Get(IActivityIOPath path, List<string> filesToCleanup)
{
Stream result = null;
try
{
if(IsStandardFtp(path))
{
ReadFromFtp(path, ref result);
}
else
{
Dev2Logger.Log.Debug(String.Format("SFTP_GET:{0}", path.Path));
ReadFromSftp(path, ref result, filesToCleanup);
}
}
catch(Exception ex)
{
Dev2Logger.Log.Error(this, ex);
var message = string.Format("{0} , [{1}]", ex.Message, path.Path);
throw new Exception(message, ex);
}
return result;
}
示例3: Get
public Stream Get(IActivityIOPath path, List<string> filesToCleanup)
{
Stream result;
if (!RequiresAuth(path))
{
if (File.Exists(path.Path))
{
result = new MemoryStream(File.ReadAllBytes(path.Path));
}
else
{
throw new Exception("File not found [ " + path.Path + " ]");
}
}
else
{
try
{
// handle UNC path
SafeTokenHandle safeTokenHandle;
string user = ExtractUserName(path);
string domain = ExtractDomain(path);
bool loginOk = LogonUser(user, domain, path.Password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, out safeTokenHandle);
if (loginOk)
{
using (safeTokenHandle)
{
WindowsIdentity newID = new WindowsIdentity(safeTokenHandle.DangerousGetHandle());
using (WindowsImpersonationContext impersonatedUser = newID.Impersonate())
{
// Do the operation here
result = new MemoryStream(File.ReadAllBytes(path.Path));
impersonatedUser.Undo(); // remove impersonation now
}
}
}
else
{
// login failed
throw new Exception("Failed to authenticate with user [ " + path.Username + " ] for resource [ " + path.Path + " ] ");
}
}
catch (Exception ex)
{
Dev2Logger.Log.Error(ex);
throw new Exception(ex.Message, ex);
}
}
return result;
}
示例4: IsStandardFtp
static bool IsStandardFtp(IActivityIOPath path)
{
return path.PathType == enActivityIOPathType.FTP || path.PathType == enActivityIOPathType.FTPES || path.PathType == enActivityIOPathType.FTPS;
}
示例5: TransferFile
static bool TransferFile(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, Dev2CRUDOperationTO args, string path, IActivityIOPath p, bool result)
{
var tmpPath = ActivityIOFactory.CreatePathFromString(path, dst.IOPath.Username, dst.IOPath.Password, true, dst.IOPath.PrivateKeyFile);
var tmpEp = ActivityIOFactory.CreateOperationEndPointFromIOPath(tmpPath);
var whereToPut = GetWhereToPut(src, dst);
using(var s = src.Get(p, _filesToDelete))
{
if(tmpEp.Put(s, tmpEp.IOPath, args, whereToPut, _filesToDelete) < 0)
{
result = false;
}
s.Close();
s.Dispose();
}
return result;
}
示例6: PerformTransfer
static bool PerformTransfer(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, Dev2CRUDOperationTO args, string origDstPath, IActivityIOPath p, bool result)
{
try
{
if(dst.PathIs(dst.IOPath) == enPathType.Directory)
{
var cpPath =
ActivityIOFactory.CreatePathFromString(
string.Format("{0}{1}{2}", origDstPath, dst.PathSeperator(),
Dev2ActivityIOPathUtils.ExtractFileName(p.Path)),
dst.IOPath.Username,
dst.IOPath.Password, true,dst.IOPath.PrivateKeyFile);
var path = cpPath.Path;
DoFileTransfer(src, dst, args, cpPath, p, path, ref result);
}
else if(args.Overwrite || !dst.PathExist(dst.IOPath))
{
var tmp = origDstPath + "\\" + Dev2ActivityIOPathUtils.ExtractFileName(p.Path);
var path = ActivityIOFactory.CreatePathFromString(tmp, dst.IOPath.Username, dst.IOPath.Password, dst.IOPath.PrivateKeyFile);
DoFileTransfer(src, dst, args, path, p, path.Path, ref result);
}
}
catch(Exception ex)
{
Dev2Logger.Log.Error(ex);
}
return result;
}
示例7: IsUncFileTypePath
static bool IsUncFileTypePath(IActivityIOPath src)
{
return src.Path.StartsWith(@"\\");
}
示例8: RequiresAuth
private bool RequiresAuth(IActivityIOPath path)
{
bool result = path.Username != string.Empty;
return result;
}
示例9: IsFilePresentStandardFtp
bool IsFilePresentStandardFtp(IActivityIOPath path)
{
FtpWebResponse response = null;
bool isAlive;
try
{
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ConvertSslToPlain(path.Path));
request.Method = WebRequestMethods.Ftp.GetFileSize;
request.UseBinary = true;
request.KeepAlive = false;
request.EnableSsl = EnableSsl(path);
if(path.Username != string.Empty)
{
request.Credentials = new NetworkCredential(path.Username, path.Password);
}
if(path.IsNotCertVerifiable)
{
ServicePointManager.ServerCertificateValidationCallback = AcceptAllCertifications;
}
using(response = (FtpWebResponse)request.GetResponse())
{
using(Stream responseStream = response.GetResponseStream())
{
if(responseStream != null)
{
using(StreamReader reader = new StreamReader(responseStream))
{
if(reader.EndOfStream)
{
// just check for exception, slow I know, but not sure how else to tackle this
}
}
}
}
}
// exception will be thrown if not present
isAlive = true;
}
catch(WebException wex)
{
Dev2Logger.Log.Error(this, wex);
isAlive = false;
}
catch(Exception ex)
{
Dev2Logger.Log.Error(this, ex);
throw;
}
finally
{
if(response != null)
{
response.Close();
}
}
return isAlive;
}
示例10: IsFilePresent
private bool IsFilePresent(IActivityIOPath path)
{
var isFilePresent = IsStandardFtp(path) ? IsFilePresentStandardFtp(path) : IsFilePresentSftp(path);
return isFilePresent;
}
示例11: EnableSsl
private static bool EnableSsl(IActivityIOPath path)
{
var result = path.PathType == enActivityIOPathType.FTPS || path.PathType == enActivityIOPathType.FTPES;
return result;
}
示例12: DeleteUsingSftp
bool DeleteUsingSftp(IActivityIOPath src)
{
var sftp = BuildSftpClient(src);
try
{
var fromPath = ExtractFileNameFromPath(src.Path);
if(PathIs(src) == enPathType.Directory)
{
sftp.DeleteDirectory(fromPath);
}
else
{
sftp.DeleteFile(fromPath);
}
}
catch(Exception)
{
throw new Exception(string.Format("Could not delete {0}. Please check the path exists.", src.Path));
}
finally
{
sftp.Dispose();
}
return true;
}
示例13: DeleteUsingStandardFtp
bool DeleteUsingStandardFtp(IActivityIOPath src)
{
FtpWebResponse response = null;
try
{
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ConvertSslToPlain(src.Path));
request.Method = PathIs(src) == enPathType.Directory ? WebRequestMethods.Ftp.RemoveDirectory : WebRequestMethods.Ftp.DeleteFile;
request.UseBinary = true;
request.KeepAlive = false;
request.EnableSsl = EnableSsl(src);
if(src.IsNotCertVerifiable)
{
ServicePointManager.ServerCertificateValidationCallback = AcceptAllCertifications;
}
if(src.Username != string.Empty)
{
request.Credentials = new NetworkCredential(src.Username, src.Password);
}
using(response = (FtpWebResponse)request.GetResponse())
{
if(response.StatusCode != FtpStatusCode.FileActionOK)
{
throw new Exception("Fail");
}
}
}
catch(Exception exception)
{
throw new Exception(string.Format("Could not delete {0}. Please check the path exists.", src.Path), exception);
}
finally
{
if(response != null)
{
response.Close();
}
}
return true;
}
示例14: DeleteOp
internal bool DeleteOp(IActivityIOPath src)
{
return IsStandardFtp(src) ? DeleteUsingStandardFtp(src) : DeleteUsingSftp(src);
}
示例15: FileExist
private bool FileExist(IActivityIOPath path)
{
bool result = File.Exists(path.Path);
return result;
}