Esempio n. 1
0
 public static FDFSFileInfo GetFileInfo(StorageNode storageNode, string fileName)
 {
     return
         (new FDFSFileInfo(
              QUERY_FILE_INFO.Instance.GetRequest(new object[]
                                                  { storageNode.EndPoint, storageNode.GroupName, fileName }).GetResponse()));
 }
Esempio n. 2
0
 public static async Task <FDFSFileInfo> GetFileInfoAsync(StorageNode storageNode, string fileName)
 {
     return
         (new FDFSFileInfo(
              await QUERY_FILE_INFO.Instance.GetRequest(new object[]
                                                        { storageNode.EndPoint, storageNode.GroupName, fileName }).GetResponseAsync()));
 }
Esempio n. 3
0
 public static async Task <string> UploadAppenderFileAsync(StorageNode storageNode, byte[] contentByte, string fileExt)
 {
     using (var contentStream = new MemoryStream(contentByte, false))
     {
         return(await UploadAppenderFileAsync(storageNode, contentStream, fileExt));
     }
 }
Esempio n. 4
0
        /// <summary>
        /// 上传可以Append的文件
        /// </summary>
        /// <param name="storageNode">GetStorageNode方法返回的存储节点</param>
        /// <param name="contentByte">文件内容</param>
        /// <param name="fileExt">文件扩展名(注意:不包含".")</param>
        /// <returns>文件名</returns>
        public static string UploadAppenderFile(StorageNode storageNode, byte[] contentByte, string fileExt)
        {
            FDFSRequest storageReqeust = UPLOAD_APPEND_FILE.Instance.GetRequest(storageNode.EndPoint, storageNode.StorePathIndex, contentByte.Length, fileExt, contentByte);

            UPLOAD_APPEND_FILE.Response storageResponse = new UPLOAD_APPEND_FILE.Response(storageReqeust.GetResponse());
            return(storageResponse.FileName);
        }
Esempio n. 5
0
 public static Task <FDFSFileInfo> GetFileInfoAsync(StorageNode storageNode, string fileName)
 {
     return(QUERY_FILE_INFO.Instance.GetRequest(storageNode.EndPoint,
                                                storageNode.GroupName,
                                                fileName)
            .GetResponseAsync <FDFSFileInfo>());
 }
Esempio n. 6
0
        /// <summary>
        /// 增量下载文件
        /// </summary>
        /// <param name="storageNode">GetStorageNode方法返回的存储节点</param>
        /// <param name="fileName">文件名</param>
        /// <param name="offset">从文件起始点的偏移量</param>
        /// <param name="length">要读取的字节数</param>
        /// <returns>文件内容</returns>
        public static byte[] DownloadFile(StorageNode storageNode, string fileName, long offset, long length)
        {
            FDFSRequest storageReqeust = DOWNLOAD_FILE.Instance.GetRequest(storageNode.EndPoint, offset, length, storageNode.GroupName, fileName);

            DOWNLOAD_FILE.Response storageResponse = new DOWNLOAD_FILE.Response(storageReqeust.GetResponse());
            return(storageResponse.Content);
        }
Esempio n. 7
0
 /// <summary>
 /// 获取存储节点
 /// </summary>
 /// <param name="groupName">组名,如果没有组名由服务器自动分配</param>
 /// <returns>存储节点实体类</returns>
 public static StorageNode GetStorageNode(string groupName)
 {
     if (string.IsNullOrEmpty(groupName))
     {
         using (var trackerRequest = QUERY_STORE_WITHOUT_GROUP_ONE.CreateRequest())
         {
             var trackerResponse = new QUERY_STORE_WITHOUT_GROUP_ONE.Response(trackerRequest.GetTrackerResponse());
             var storeEndPoint   = new IPEndPoint(IPAddress.Parse(trackerResponse.IpStr), trackerResponse.Port);
             Console.WriteLine($"{DateTime.Now.ToString("yyyyMMdd hh:mm:ss:fff")} => GetStorageNode(tracker = {trackerResponse.IpStr},store = {storeEndPoint.Address})");//log
             var result = new StorageNode
             {
                 GroupName      = trackerResponse.GroupName,
                 EndPoint       = storeEndPoint,
                 StorePathIndex = trackerResponse.StorePathIndex
             };
             return(result);
         }
     }
     else
     {
         using (var trackerRequest = QUERY_STORE_WITH_GROUP_ONE.CreateRequest(groupName))
         {
             var trackerResponse = new QUERY_STORE_WITH_GROUP_ONE.Response(trackerRequest.GetTrackerResponse());
             var storeEndPoint   = new IPEndPoint(IPAddress.Parse(trackerResponse.IpStr), trackerResponse.Port);
             Console.WriteLine($"{DateTime.Now.ToString("yyyyMMdd hh:mm:ss:fff")} => GetStorageNode(tracker = {trackerResponse.IpStr},store = {storeEndPoint.Address})");//log
             var result = new StorageNode
             {
                 GroupName      = trackerResponse.GroupName,
                 EndPoint       = storeEndPoint,
                 StorePathIndex = trackerResponse.StorePathIndex
             };
             return(result);
         }
     }
 }
Esempio n. 8
0
        /// <summary>
        /// 获取文件信息
        /// </summary>
        /// <param name="storageNode">GetStorageNode方法返回的存储节点</param>
        /// <param name="fileName">文件名</param>
        /// <returns></returns>
        public static FDFSFileInfo GetFileInfo(StorageNode storageNode, string fileName)
        {
            FDFSRequest  storageReqeust = QUERY_FILE_INFO.Instance.GetRequest(storageNode.EndPoint, storageNode.GroupName, fileName);
            FDFSFileInfo result         = new FDFSFileInfo(storageReqeust.GetResponse());

            return(result);
        }
        public override FDFSRequest GetRequest(params object[] paramList)
        {
            if (paramList.Length != 3)
            {
                throw new FDFSException("param count is wrong");
            }

            StorageNode storageNode = (StorageNode)paramList[0];
            string      fileExt     = (string)paramList[1] ?? string.Empty;

            if (fileExt.Length > 0 && fileExt[0] == '.')
            {
                fileExt = fileExt.Substring(1);
            }

            var contentStream = (Stream)paramList[2];

            var contentByteLength = contentStream.Length;

            UPLOAD_APPEND_FILE uploadAppendFile = new UPLOAD_APPEND_FILE
            {
                ConnectionType = FDFSConnectionType.StorageConnection,
                EndPoint       = storageNode.EndPoint
            };

            if (fileExt.Length > 6)
            {
                throw new FDFSException("file ext is too long");
            }

            const int bodyBufferLen = 15;

            uploadAppendFile.SetBodyBuffer(bodyBufferLen);

            int offset = 0;

            uploadAppendFile.BodyBuffer[offset++] = storageNode.StorePathIndex;

            Util.LongToBuffer(contentByteLength, uploadAppendFile.BodyBuffer, offset);
            offset += 8;

            var fileExtByteCount = Util.StringByteCount(fileExt);

            Util.StringToByte(fileExt, uploadAppendFile.BodyBuffer, offset, fileExtByteCount);
            if (fileExtByteCount < 6)
            {
                for (var i = offset + fileExtByteCount; i < offset + 6; i++)
                {
                    uploadAppendFile.BodyBuffer[i] = 0;
                }
            }

            uploadAppendFile.BodyStream = contentStream;

            var length = bodyBufferLen + contentByteLength;

            uploadAppendFile.Header = new FDFSHeader(length, FDFSConstants.STORAGE_PROTO_CMD_UPLOAD_APPENDER_FILE, 0);
            return(uploadAppendFile);
        }
Esempio n. 10
0
 public UPLOAD_APPEND_FILE_Args(StorageNode storageNode,
                                byte[] fileBuffer,
                                string fileExt)
 {
     _storageNode = storageNode;
     _fileBuffer  = fileBuffer;
     _fileExt     = fileExt;
 }
Esempio n. 11
0
        public static IDictionary <string, string> GetMetaData(StorageNode storageNode, string fileName)
        {
            FDFSRequest storageRequest = GET_METADATA.Instance.GetRequest(storageNode.EndPoint, storageNode.GroupName, fileName);

            GET_METADATA.Response storageResponse = new GET_METADATA.Response();
            storageRequest.GetResponse(storageResponse);
            return(storageResponse.MetaData);
        }
Esempio n. 12
0
        public static async Task <string> UploadFileAsync(this StorageNode storageNode, Stream fileStream, string fileExt, CancellationToken token)
        {
            var response = await new UPLOAD_FILE(storageNode.EndPoint).RequestAsync(
                new UPLOAD_FILE_Args(storageNode, fileStream, fileExt),
                token);

            return(response.FileName);
        }
Esempio n. 13
0
 public UPLOAD_FILE_Args(StorageNode storageNode,
                         Stream fileStream,
                         string fileExt)
 {
     _storageNode = storageNode;
     _fileStream  = fileStream;
     _fileExt     = fileExt;
 }
Esempio n. 14
0
        /// <summary>
        /// 下载文件
        /// </summary>
        /// <param name="storageNode">GetStorageNode方法返回的存储节点</param>
        /// <param name="fileName">文件名</param>
        /// <returns>文件内容</returns>
        public static byte[] DownloadFile(StorageNode storageNode, string fileName)
        {
            var storageReqeust = DOWNLOAD_FILE.Instance.GetRequest(storageNode.EndPoint, 0L, 0L, storageNode.GroupName, fileName);

            var storageResponse = new DOWNLOAD_FILE.Response(storageReqeust.GetResponse());

            return(storageResponse.Content);
        }
Esempio n. 15
0
 /// <summary>
 /// 增量下载文件
 /// </summary>
 /// <param name="storageNode">GetStorageNode方法返回的存储节点</param>
 /// <param name="fileName">文件名</param>
 /// <param name="offset">从文件起始点的偏移量</param>
 /// <param name="length">要读取的字节数</param>
 /// <returns>文件内容</returns>
 public static byte[] DownloadFile(StorageNode storageNode, string fileName, long offset, long length)
 {
     fileName = GetFileName(storageNode.GroupName, fileName);
     using (var storageReqeust = DOWNLOAD_FILE.CreateRequest(storageNode.EndPoint, offset, length, storageNode.GroupName, fileName))
     {
         var storageResponse = new DOWNLOAD_FILE.Response(storageReqeust.GetStorageResponse());
         return(storageResponse.Content);
     }
 }
Esempio n. 16
0
 public static string UploadFile(StorageNode storageNode, byte[] contentByte, string fileExt)
 {
     UPLOAD_FILE.Response response =
         new UPLOAD_FILE.Response(
             UPLOAD_FILE.Instance.GetRequest(new object[]
                                             { storageNode.EndPoint, storageNode.StorePathIndex, contentByte.Length, fileExt, contentByte })
             .GetResponse());
     return(response.FileName);
 }
Esempio n. 17
0
 public static async Task <string> UploadAppenderFileAsync(StorageNode storageNode, byte[] contentByte, string fileExt)
 {
     UPLOAD_APPEND_FILE.Response response =
         new UPLOAD_APPEND_FILE.Response(
             await UPLOAD_APPEND_FILE.Instance.GetRequest(new object[]
                                                          { storageNode.EndPoint, storageNode.StorePathIndex, contentByte.Length, fileExt, contentByte })
             .GetResponseAsync());
     return(response.FileName);
 }
Esempio n. 18
0
        public static async Task <string> UploadAppenderFileAsync(StorageNode storageNode, byte[] contentByte, string fileExt)
        {
            var response = await UPLOAD_APPEND_FILE.Instance.GetRequest(storageNode,
                                                                        fileExt,
                                                                        contentByte)
                           .GetResponseAsync <UPLOAD_APPEND_FILE.Response>();

            return(response.FileName);
        }
Esempio n. 19
0
 /// <summary>
 /// 获取文件信息
 /// </summary>
 /// <param name="storageNode">GetStorageNode方法返回的存储节点</param>
 /// <param name="fileName">文件名</param>
 /// <returns></returns>
 public static FDFSFileInfo GetFileInfo(StorageNode storageNode, string fileName)
 {
     fileName = GetFileName(storageNode.GroupName, fileName);
     using (var storageReqeust = QUERY_FILE_INFO.CreateRequest(storageNode.EndPoint, storageNode.GroupName, fileName))
     {
         var result = new FDFSFileInfo(storageReqeust.GetStorageResponse());
         return(result);
     }
 }
Esempio n. 20
0
        public static async Task <string> UploadFileAsync(StorageNode storageNode, Stream contentStream, string fileExt)
        {
            var response = await UPLOAD_FILE.Instance.GetRequest(storageNode,
                                                                 fileExt,
                                                                 contentStream)
                           .GetResponseAsync <UPLOAD_FILE.Response>();

            return(response.FileName);
        }
Esempio n. 21
0
        public override FDFSRequest GetRequest(params object[] paramList)
        {
            if (paramList.Length != 3)
            {
                throw new FDFSException("param count is wrong");
            }

            StorageNode storageNode = (StorageNode)paramList[0];
            string      fileExt     = (string)paramList[1];

            if (fileExt[0] == '.')
            {
                fileExt = fileExt.Substring(1);
            }
            byte[] contentByte = (byte[])paramList[2];

            int contentByteLength = contentByte.Length;

            UPLOAD_FILE uploadFile = new UPLOAD_FILE
            {
                ConnectionType = FDFSConnectionType.StorageConnection,
                EndPoint       = storageNode.EndPoint
            };

            if (fileExt.Length > 6)
            {
                throw new FDFSException("file ext is too long");
            }

            int length = 15 + contentByteLength;

            uploadFile.SetBodyBuffer(length);

            int offset = 0;

            uploadFile.BodyBuffer[offset++] = storageNode.StorePathIndex;

            Util.LongToBuffer(contentByteLength, uploadFile.BodyBuffer, offset);
            offset += 8;

            var fileExtByteCount = Util.StringByteCount(fileExt);

            Util.StringToByte(fileExt, uploadFile.BodyBuffer, offset, fileExtByteCount);
            if (fileExtByteCount < 6)
            {
                for (var i = offset + fileExtByteCount; i < offset + 6; i++)
                {
                    uploadFile.BodyBuffer[i] = 0;
                }
            }

            offset += 6;
            Array.Copy(contentByte, 0, uploadFile.BodyBuffer, offset, contentByte.Length);

            uploadFile.Header = new FDFSHeader(length, FDFSConstants.STORAGE_PROTO_CMD_UPLOAD_FILE, 0);
            return(uploadFile);
        }
Esempio n. 22
0
        /// <summary>
        /// 异步下载
        /// </summary>
        /// <param name="storageNode"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static async Task <byte[]> DownloadFileAsync(StorageNode storageNode, string fileName)
        {
            fileName = GetFileName(storageNode.GroupName, fileName);

            using (var storageReqeust = DOWNLOAD_FILE.CreateRequest(storageNode.EndPoint, 0L, 0L, storageNode.GroupName, fileName))
            {
                Task <byte[]> task = null; // storageReqeust.ReadBytesAsync();
                await         task;
                return(task.Result);
            }
        }
Esempio n. 23
0
 public static string UploadFileByName(StorageNode storageNode, string filename)
 {
     using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
     {
         string               extension       = Path.GetExtension(filename).Substring(1);
         FDFSRequest          storageRequest  = UPLOAD_FILE.Instance.GetRequest(storageNode.EndPoint, storageNode.StorePathIndex, fs.Length, extension, fs);
         UPLOAD_FILE.Response storageResponse = new UPLOAD_FILE.Response();
         storageRequest.GetResponse(storageResponse);
         return(storageResponse.FileName);
     }
 }
Esempio n. 24
0
        public static async Task <string> UploadFileAsync(StorageNode storageNode, byte[] contentByte, string fileExt)
        {
            var req = UPLOAD_FILE.Instance.GetRequest(
                storageNode.EndPoint,
                storageNode.StorePathIndex,
                contentByte.Length,
                fileExt,
                contentByte);
            var response = new UPLOAD_FILE.Response(await req.GetResponseAsync());

            return(response.FileName);
        }
Esempio n. 25
0
        public static async Task <byte[]> DownloadFileAsync(StorageNode storageNode, string fileName,
                                                            long offset = 0,
                                                            long length = 0)
        {
            var response = await DOWNLOAD_FILE.Instance
                           .GetRequest(storageNode,
                                       fileName,
                                       Tuple.Create(offset, length))
                           .GetResponseAsync <DOWNLOAD_FILE.Response>();

            return(response.Content);
        }
Esempio n. 26
0
        public static async Task <byte[]> DownloadFileAsync(StorageNode storageNode, string fileName,
                                                            long offset = 0,
                                                            long length = 0)
        {
            using (var memoryStream = new MemoryStream(length > 0 ? (int)length : 0))
            {
                var downloadStream = new StreamDownloadCallback(memoryStream);
                await DownloadFileAsync(storageNode, fileName, downloadStream, offset, length);

                return(memoryStream.GetBuffer());
            }
        }
Esempio n. 27
0
 public static async Task DownloadFileAsync(StorageNode storageNode, string fileName,
                                            IDownloadCallback downloadCallback,
                                            long offset = 0,
                                            long length = 0)
 {
     await DOWNLOAD_FILE.Instance
     .GetRequest(storageNode,
                 fileName,
                 Tuple.Create(offset, length),
                 downloadCallback)
     .GetResponseAsync <DOWNLOAD_FILE.Response>();
 }
Esempio n. 28
0
        /// <summary>
        /// 获取存储节点
        /// </summary>
        /// <param name="groupName">组名</param>
        /// <returns>存储节点实体类</returns>
        public static StorageNode GetStorageNode(string groupName)
        {
            FDFSRequest trackerRequest = QUERY_STORE_WITH_GROUP_ONE.Instance.GetRequest(groupName);

            QUERY_STORE_WITH_GROUP_ONE.Response trackerResponse = new QUERY_STORE_WITH_GROUP_ONE.Response(trackerRequest.GetResponse());
            IPEndPoint  storeEndPoint = new IPEndPoint(IPAddress.Parse(trackerResponse.IPStr), trackerResponse.Port);
            StorageNode result        = new StorageNode();

            result.GroupName      = trackerResponse.GroupName;
            result.EndPoint       = storeEndPoint;
            result.StorePathIndex = trackerResponse.StorePathIndex;
            return(result);
        }
Esempio n. 29
0
        public static async Task <string> UploadSlaveFileAsync(this StorageNode storageNode,
                                                               string masterFile,
                                                               string prefix,
                                                               Stream fileStream,
                                                               string fileExt,
                                                               CancellationToken token)
        {
            var response = await new UPLOAD_SLAVE_FILE(storageNode.EndPoint).RequestAsync(
                new UPLOAD_SLAVE_FILE_Args(masterFile, prefix, fileExt, fileStream),
                token);

            return(response.FileName);
        }
Esempio n. 30
0
        public static StorageNode QueryStorageNodeForFile(string groupName, string fileid)
        {
            FDFSRequest trackerRequest = QUERY_FETCH_ONE.Instance.GetRequest(groupName, fileid);

            QUERY_FETCH_ONE.Response trackerResponse = new QUERY_FETCH_ONE.Response();
            trackerRequest.GetResponse(trackerResponse);
            IPEndPoint  storeEndPoint = new IPEndPoint(IPAddress.Parse(trackerResponse.IPStr), trackerResponse.Port);
            StorageNode result        = new StorageNode();

            result.GroupName      = trackerResponse.GroupName;
            result.EndPoint       = storeEndPoint;
            result.StorePathIndex = 0;
            return(result);
        }