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;
                        }
                    }
                }
            }
        }
    }
    
  • 相关阅读:
    STM32 + RT Thread OS 学习笔记[四]
    Python学习入门基础教程(learning Python)--5.3 Python写文件基础
    Android Dialog
    poj 2513 连接火柴 字典树+欧拉通路 好题
    Ubuntu 问题解决汇总
    [置顶] 问题解决——产生未引用参数的警告
    BZOJ 1367([Baltic2004]sequence-左偏树+中位数贪心)
    【Cocos2d-X开发学习笔记】第01期:PC开发环境的详细搭建
    在navigationItem中添加搜索栏
    Loading half a billion rows into MySQL---转载
  • 原文地址:https://www.cnblogs.com/wywnet/p/4755215.html
Copyright © 2011-2022 走看看