zoukankan      html  css  js  c++  java
  • ftp缓存信息

    using System.Collections.Generic;
    using NewTempo.Ftp;
    using System.IO;
    using NshowAdClient.NshowAdServices;
    using NshowAdClient.Helper;
    
    namespace NshowAdClient.Services
    {
        public static class
            FtpHelpService
        {
            static readonly Dictionary<int, FtpInfo> ClientFtpCache = new Dictionary<int, FtpInfo>();
    
            static FtpInfo ShareFtpInfo { get; set; }
    
            static readonly object GetShareFtpLock = new object();
            public static MyFtp GetShareFtp()
            {
                lock (GetShareFtpLock)
                {
                    if (LoginUserHelper.Mode == RoleType.Client)
                    {
                        return GetClientFtp(LoginUserHelper.UserId);
                    }
    
                    if (ShareFtpInfo == null)
                    {
                        using (var service = new NshowAdServiceClient())
                        {
                            ShareFtpInfo = service.GetFtpInfo();
                        }
                    }
    
                    MyFtp ftp = new MyFtp(ShareFtpInfo.FtpAddress, ShareFtpInfo.User, ShareFtpInfo.Password);
                    return ftp;
                    //return new MyFtp("61.145.119.85:21", "wcf", "wcf");
                }
            }
    
            static readonly object GetClientFtpLock = new object();
            public static MyFtp GetClientFtp(int clientId)
            {
                lock (GetClientFtpLock)
                {
                    FtpInfo ftpInfo;
                    if (ClientFtpCache.ContainsKey(clientId))
                    {
                        ftpInfo = ClientFtpCache[clientId];
                    }
                    else
                    {
                        using (var service = new NshowAdServiceClient())
                        {
                            ftpInfo = service.GetClientFtpInfo(clientId);
                            ClientFtpCache.Add(clientId, ftpInfo);
                        }
                    }
    
                    var ftp = new MyFtp(ftpInfo.FtpAddress, ftpInfo.User, ftpInfo.Password);
                    return ftp;
                    //return new MyFtp("61.145.119.85:21", "wcf", "wcf");
                }
            }
    
            public static MyFtp GetFtp(string ftpIp, string userName, string password)
            {
                return new MyFtp(ftpIp, userName, password);
            }
    
            public static void CreateDir(string path, MyFtp myFtp)
            {
                var dirName = Path.GetDirectoryName(path);
                bool ret = myFtp.CreateDirectory(dirName);
            }
    
            public static FtpInfo GetClientFtpInfo(int clientId)
            {
                lock (GetClientFtpLock)
                {
                    if (ClientFtpCache.ContainsKey(clientId))
                    {
                        return ClientFtpCache[clientId];
                    }
                    else
                    {
                        using (var service = new NshowAdServiceClient())
                        {
                            FtpInfo ftpInfo = service.GetClientFtpInfo(clientId);
                            ClientFtpCache.Add(clientId, ftpInfo);
                            return ftpInfo;
                        }
                    }
                }
            }
        }
    }
    
  • 相关阅读:
    优秀程序设计的Kiss原则(keep it simple,stupid)
    前端模块化 (好文分享)
    sublime 常用快捷键(转)
    认识与入门 MarkDown (转Te_Lee)
    Sublime Text 3 常用插件以及安装方法(转)
    Flex 布局
    eclipse neon 离线安装插件
    mysql 自动备份命令
    java大并发数据保存方案
    基于webapi的移动互联架构
  • 原文地址:https://www.cnblogs.com/wywnet/p/4755215.html
Copyright © 2011-2022 走看看