当前位置: 首页>>代码示例>>C#>>正文


C# IActivityIOPath类代码示例

本文整理汇总了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");
                    }
                }
            }
        }
开发者ID:FerdinandOlivier,项目名称:Warewolf-ESB,代码行数:35,代码来源:Dev2FTPProvider.cs

示例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;
        }
开发者ID:FerdinandOlivier,项目名称:Warewolf-ESB,代码行数:26,代码来源:Dev2FTPProvider.cs

示例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;
        }
开发者ID:Robin--,项目名称:Warewolf,代码行数:59,代码来源:Dev2FileSystemProvider.cs

示例4: IsStandardFtp

 static bool IsStandardFtp(IActivityIOPath path)
 {
     return path.PathType == enActivityIOPathType.FTP || path.PathType == enActivityIOPathType.FTPES || path.PathType == enActivityIOPathType.FTPS;
 }
开发者ID:FerdinandOlivier,项目名称:Warewolf-ESB,代码行数:4,代码来源:Dev2FTPProvider.cs

示例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;
 }
开发者ID:Robin--,项目名称:Warewolf,代码行数:16,代码来源:Dev2ActivityIOBroker.cs

示例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;
 }
开发者ID:Robin--,项目名称:Warewolf,代码行数:28,代码来源:Dev2ActivityIOBroker.cs

示例7: IsUncFileTypePath

 static bool IsUncFileTypePath(IActivityIOPath src)
 {
     return src.Path.StartsWith(@"\\");
 }
开发者ID:Robin--,项目名称:Warewolf,代码行数:4,代码来源:Dev2ActivityIOBroker.cs

示例8: RequiresAuth

        private bool RequiresAuth(IActivityIOPath path)
        {
            bool result = path.Username != string.Empty;

            return result;
        }
开发者ID:Robin--,项目名称:Warewolf,代码行数:6,代码来源:Dev2FileSystemProvider.cs

示例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;
        }
开发者ID:FerdinandOlivier,项目名称:Warewolf-ESB,代码行数:66,代码来源:Dev2FTPProvider.cs

示例10: IsFilePresent

 private bool IsFilePresent(IActivityIOPath path)
 {
     var isFilePresent = IsStandardFtp(path) ? IsFilePresentStandardFtp(path) : IsFilePresentSftp(path);
     return isFilePresent;
 }
开发者ID:FerdinandOlivier,项目名称:Warewolf-ESB,代码行数:5,代码来源:Dev2FTPProvider.cs

示例11: EnableSsl

 private static bool EnableSsl(IActivityIOPath path)
 {
     var result = path.PathType == enActivityIOPathType.FTPS || path.PathType == enActivityIOPathType.FTPES;
     return result;
 }
开发者ID:FerdinandOlivier,项目名称:Warewolf-ESB,代码行数:5,代码来源:Dev2FTPProvider.cs

示例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;
 }
开发者ID:FerdinandOlivier,项目名称:Warewolf-ESB,代码行数:25,代码来源:Dev2FTPProvider.cs

示例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;
        }
开发者ID:FerdinandOlivier,项目名称:Warewolf-ESB,代码行数:45,代码来源:Dev2FTPProvider.cs

示例14: DeleteOp

 internal bool DeleteOp(IActivityIOPath src)
 {
     return IsStandardFtp(src) ? DeleteUsingStandardFtp(src) : DeleteUsingSftp(src);
 }
开发者ID:FerdinandOlivier,项目名称:Warewolf-ESB,代码行数:4,代码来源:Dev2FTPProvider.cs

示例15: FileExist

        private bool FileExist(IActivityIOPath path)
        {
            bool result = File.Exists(path.Path);

            return result;
        }
开发者ID:Robin--,项目名称:Warewolf,代码行数:6,代码来源:Dev2FileSystemProvider.cs


注:本文中的IActivityIOPath类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。