Beispiel #1
0
        /// <summary>
        /// </summary>
        /// <param name="paramList">
        ///     1,IPEndPoint    IPEndPoint-->the storage IPEndPoint
        ///     2,long offset-->file offset
        ///     3,long byteSize -->download file bytes
        ///     4,string groupName
        ///     5,string fileName
        /// </param>
        /// <returns></returns>
        public override FDFSRequest GetRequest(params object[] paramList)
        {
            if (paramList.Length != 5)
            {
                throw new FDFSException("param count is wrong");
            }
            var endPoint  = (IPEndPoint)paramList[0];
            var offset    = (long)paramList[1];
            var byteSize  = (long)paramList[2];
            var groupName = (string)paramList[3];
            var fileName  = (string)paramList[4];

            var result = new DOWNLOAD_FILE {
                Connection = ConnectionManager.GetStorageConnection(endPoint)
            };

            if (groupName.Length > Consts.FDFS_GROUP_NAME_MAX_LEN)
            {
                throw new FDFSException("groupName is too long");
            }

            long length = Consts.FDFS_PROTO_PKG_LEN_SIZE +
                          Consts.FDFS_PROTO_PKG_LEN_SIZE +
                          Consts.FDFS_GROUP_NAME_MAX_LEN +
                          fileName.Length;
            var bodyBuffer = new byte[length];

            byte[] offsetBuffer    = Util.LongToBuffer(offset);
            byte[] byteSizeBuffer  = Util.LongToBuffer(byteSize);
            byte[] groupNameBuffer = Util.StringToByte(groupName);
            byte[] fileNameBuffer  = Util.StringToByte(fileName);
            Array.Copy(offsetBuffer, 0, bodyBuffer, 0, offsetBuffer.Length);
            Array.Copy(byteSizeBuffer, 0, bodyBuffer, Consts.FDFS_PROTO_PKG_LEN_SIZE, byteSizeBuffer.Length);
            Array.Copy(groupNameBuffer, 0, bodyBuffer, Consts.FDFS_PROTO_PKG_LEN_SIZE +
                       Consts.FDFS_PROTO_PKG_LEN_SIZE, groupNameBuffer.Length);
            Array.Copy(fileNameBuffer, 0, bodyBuffer, Consts.FDFS_PROTO_PKG_LEN_SIZE +
                       Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_GROUP_NAME_MAX_LEN,
                       fileNameBuffer.Length);

            result.Body   = bodyBuffer;
            result.Header = new FDFSHeader(length, Consts.STORAGE_PROTO_CMD_DOWNLOAD_FILE, 0);
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// </summary>
        /// <param name="paramList">
        ///     1,IPEndPoint    IPEndPoint-->the storage IPEndPoint
        ///     2,long offset-->file offset
        ///     3,long byteSize -->download file bytes
        ///     4,string groupName
        ///     5,string fileName
        /// </param>
        /// <returns></returns>
        public override FDFSRequest GetRequest(params object[] paramList)
        {
            if (paramList.Length != 5)
                throw new FDFSException("param count is wrong");
            var endPoint = (IPEndPoint)paramList[0];
            var offset = (long)paramList[1];
            var byteSize = (long)paramList[2];
            var groupName = (string)paramList[3];
            var fileName = (string)paramList[4];

            var result = new DOWNLOAD_FILE { Connection = ConnectionManager.GetStorageConnection(endPoint) };

            if (groupName.Length > Consts.FDFS_GROUP_NAME_MAX_LEN)
                throw new FDFSException("groupName is too long");

            long length = Consts.FDFS_PROTO_PKG_LEN_SIZE +
                          Consts.FDFS_PROTO_PKG_LEN_SIZE +
                          Consts.FDFS_GROUP_NAME_MAX_LEN +
                          fileName.Length;
            var bodyBuffer = new byte[length];
            byte[] offsetBuffer = Util.LongToBuffer(offset);
            byte[] byteSizeBuffer = Util.LongToBuffer(byteSize);
            byte[] groupNameBuffer = Util.StringToByte(groupName);
            byte[] fileNameBuffer = Util.StringToByte(fileName);
            Array.Copy(offsetBuffer, 0, bodyBuffer, 0, offsetBuffer.Length);
            Array.Copy(byteSizeBuffer, 0, bodyBuffer, Consts.FDFS_PROTO_PKG_LEN_SIZE, byteSizeBuffer.Length);
            Array.Copy(groupNameBuffer, 0, bodyBuffer, Consts.FDFS_PROTO_PKG_LEN_SIZE +
                                                       Consts.FDFS_PROTO_PKG_LEN_SIZE, groupNameBuffer.Length);
            Array.Copy(fileNameBuffer, 0, bodyBuffer, Consts.FDFS_PROTO_PKG_LEN_SIZE +
                                                      Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_GROUP_NAME_MAX_LEN,
                fileNameBuffer.Length);

            result.Body = bodyBuffer;
            result.Header = new FDFSHeader(length, Consts.STORAGE_PROTO_CMD_DOWNLOAD_FILE, 0);
            return result;
        }