Ejemplo n.º 1
0
        /// <summary>
        /// 本地化文件,仅供主服务器调用
        /// </summary>
        /// <param name="fileName"></param>
        public MasterService.FsFileInfo LocalizeFile(string fileName)
        {
            MasterService.FsFileInfo fileInfo = masterService.GetFileInfo(fileName, FileStoreConfig.FileServerName);

            string localFilePath = GetLocalFilePath(fileInfo.FileFullPathList);

            if (localFilePath != "")
            {
                fileInfo.FileFullPath = localFilePath;
                return(fileInfo);
            }

            FileService.InnerService innerService = new FileService.InnerService();
            innerService.Url = fileInfo.SrcFileServiceUrl;

            int pos    = 0;
            int length = 1024 * 1024;

            byte[] bytes = innerService.GetFileBytes(fileInfo.SrcFileFullPath, pos, length);
            while (bytes.Length > 0)
            {
                FileHelper.SaveFile(fileInfo.FileFullPath, bytes, fileInfo.FileSize, pos);
                pos  += length;
                bytes = innerService.GetFileBytes(fileInfo.SrcFileFullPath, pos, length);
            }

            masterService.UpdateFileServerNames(fileName, FileStoreConfig.FileServerName);

            return(fileInfo);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 本地化文件,仅供主服务器调用
        /// </summary>
        /// <param name="fileName"></param>
        public MasterService.FsFileInfo LocalizeFile(string fileName)
        {
            MasterService.FsFileInfo fileInfo = masterService.GetFileInfo(fileName, FileStoreConfig.FileServerName);

            //判断文件是否在本地
            if (File.Exists(fileInfo.SrcFileFullPath))
            {
                fileInfo.FileFullPath = fileInfo.SrcFileFullPath;
                return(fileInfo);
            }

            string localFilePath = GetLocalFilePath(fileInfo.FileFullPathList);

            if (localFilePath != "")
            {
                fileInfo.FileFullPath = localFilePath;
                return(fileInfo);
            }

            if (string.IsNullOrEmpty(fileInfo.SrcFileServiceUrl))
            {
                throw new Exception("所有服务器上没有找到物理文件【" + fileName + "】");
            }

            FileService.InnerService innerService = new FileService.InnerService();
            innerService.Url = fileInfo.SrcFileServiceUrl;

            int pos    = 0;
            int length = 1024 * 1024;

            byte[] bytes = innerService.GetFileBytes(fileInfo.SrcFileFullPath, pos, length);
            while (bytes.Length > 0)
            {
                FileHelper.SaveFile(fileInfo.FileFullPath, bytes, fileInfo.FileSize, pos);
                pos  += length;
                bytes = innerService.GetFileBytes(fileInfo.SrcFileFullPath, pos, length);
            }

            masterService.UpdateFileServerNames(fileName, FileStoreConfig.FileServerName);

            return(fileInfo);
        }