Пример #1
0
        /// <summary>
        /// 删除服务器上文件
        /// </summary>
        /// <param name="webFileServer"></param>
        /// <param name="fileName">虚拟路径 或 物理路径 地址</param>
        /// <param name="targetServer"></param>
        public static void DeleteServerFile(string webFileServer, string fileName, UtilConstants.ServerType targetServer)
        {
            if (string.IsNullOrWhiteSpace(fileName))
            {
                return;
            }

            switch (targetServer)
            {
            case UtilConstants.ServerType.WebFileService:
                if (string.IsNullOrWhiteSpace(webFileServer))
                {
                    return;
                }

                WebDAVFileServer dav = GetWebDAVServer(webFileServer);
                dav.DeleteFile(fileName);

                break;

            case UtilConstants.ServerType.WebService:
                string physicsPath = CommonUtils.GetPhysicsPath(fileName);
                System.IO.File.Delete(physicsPath);
                break;

            case UtilConstants.ServerType.FTPService:
                break;

            default:
                break;
            }
        }
Пример #2
0
        /// <summary>
        /// 判断文件服务器是否存在指定文件
        /// </summary>
        /// <param name="server"></param>
        /// <param name="fileName"></param>
        /// <param name="user"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static bool IsExistInFSServer(string server, string fileName, string user, string password)
        {
            //log.InfoFormat("server={0}, fileName={1}, user={2}, password={3}", server, fileName, user, password);
            WebDAVFileServer fileService = new WebDAVFileServer(server, user, password);

            return(fileService.IsFileExist(fileName));
        }
Пример #3
0
        private static WebDAVFileServer GetWebDAVServer2()
        {
            //读取配置信息
            string           webFileServer = WebUtils.GetSettingsValue("WebFileServer2");
            string           userId        = WebUtils.GetSettingsValue("WebFileServerUser2");
            string           pwd           = WebUtils.GetSettingsValue("WebFileServerPwd2");
            WebDAVFileServer dav           = new WebDAVFileServer(webFileServer, userId, pwd);

            return(dav);
        }
Пример #4
0
        /// <summary>
        /// 判断fs-www文件服务器是否存在指定文件
        /// </summary>
        /// <param name="webFileServer"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static bool IsExistFile(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return(false);
            }
            WebDAVFileServer fileService = GetWebDAVServer2();

            return(fileService.IsFileExist(fileName));
        }
Пример #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dir"></param>
        public static string CreateDir(string dir)
        {
            if (string.IsNullOrEmpty(dir))
            {
                return("");
            }
            WebDAVFileServer fileService = GetWebDAVServer("");

            fileService.CreateDir(dir);
            return(dir);
        }
Пример #6
0
        private static WebDAVFileServer GetWebDAVServer(string webFileServer)
        {
            //读取配置信息
            if (string.IsNullOrWhiteSpace(webFileServer))
            {
                webFileServer = WebUtils.GetSettingsValue("WebFileServer");
            }
            string           userId = WebUtils.GetSettingsValue("WebFileServerUser");
            string           pwd    = WebUtils.GetSettingsValue("WebFileServerPwd");
            WebDAVFileServer dav    = new WebDAVFileServer(webFileServer, userId, pwd);

            return(dav);
        }
Пример #7
0
        public static void DeleteServerFile(string fileName, UtilConstants.ServerType targetServer)
        {
            switch (targetServer)
            {
            case UtilConstants.ServerType.WebFileService:
                WebDAVFileServer dav = GetWebDAVServer("");
                dav.DeleteFile(fileName);

                break;

            case UtilConstants.ServerType.WebService:
                break;

            case UtilConstants.ServerType.FTPService:
                break;

            default:
                break;
            }
        }
Пример #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="baseDir"></param>
        /// <param name="dir">4位年+2位月+2位日</param>
        public static string CreateDir(string baseDir, string dir)
        {
            if (string.IsNullOrEmpty(dir))
            {
                return("");
            }
            dir = string.Format("{0}/{1}/{2}/", dir.Substring(0, 4), dir.Substring(4, 2), dir.Substring(6, 2));
            WebDAVFileServer fileService = GetWebDAVServer("");

            string[] dirs = dir.Split('/');
            foreach (string d in dirs)
            {
                if (!string.IsNullOrEmpty(d))
                {
                    baseDir += d + "/";
                    fileService.CreateDir(baseDir);
                }
            }
            return(baseDir);
        }
Пример #9
0
        /// <summary>
        /// 客户端文件下载
        /// </summary>
        /// <param name="webFileServer"></param>
        /// <param name="filePath">文件虚拟路径地址</param>
        /// <param name="targetServer"></param>
        /// <returns></returns>
        public static Stream FileDownload(string webFileServer, string filePath, UtilConstants.ServerType targetServer)
        {
            Stream input = null;

            switch (targetServer)
            {
            case UtilConstants.ServerType.WebFileService:
                WebDAVFileServer dav = GetWebDAVServer(webFileServer);
                input = dav.DownLoadFile(filePath);
                break;

            case UtilConstants.ServerType.WebService:
                input = new FileStream(ToolsLib.Utility.WebUtils.Resulve(filePath), FileMode.Open, FileAccess.Read, FileShare.Read);
                break;

            default:
                break;
            }
            return(input);
        }