Exemplo n.º 1
0
        /// <summary>
        /// </summary>
        /// <param name="paramList">
        ///     1,IPEndPoint    IPEndPoint-->the storage IPEndPoint
        ///     2,string        FileName
        ///     3,byte[]        File bytes
        /// </param>
        /// <returns></returns>
        public override FDFSRequest GetRequest(params object[] paramList)
        {
            if (paramList.Length != 3)
                throw new FDFSException("param count is wrong");
            var endPoint = (IPEndPoint)paramList[0];

            var fileName = (string)paramList[1];
            var contentBuffer = (byte[])paramList[2];

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

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

            byte[] fileNameLenBuffer = Util.LongToBuffer(fileName.Length);
            Array.Copy(fileNameLenBuffer, 0, bodyBuffer, 0, fileNameLenBuffer.Length);

            byte[] fileSizeBuffer = Util.LongToBuffer(contentBuffer.Length);
            Array.Copy(fileSizeBuffer, 0, bodyBuffer, Consts.FDFS_PROTO_PKG_LEN_SIZE, fileSizeBuffer.Length);

            byte[] fileNameBuffer = Util.StringToByte(fileName);
            Array.Copy(fileNameBuffer, 0, bodyBuffer, Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_PROTO_PKG_LEN_SIZE,
                fileNameBuffer.Length);

            Array.Copy(contentBuffer, 0, bodyBuffer,
                Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_PROTO_PKG_LEN_SIZE + fileNameBuffer.Length,
                contentBuffer.Length);

            result.Body = bodyBuffer;
            result.Header = new FDFSHeader(length, Consts.STORAGE_PROTO_CMD_APPEND_FILE, 0);
            return result;
        }
Exemplo n.º 2
0
        /// <summary>
        /// </summary>
        /// <param name="paramList">
        ///     1,IPEndPoint    IPEndPoint-->the storage IPEndPoint
        ///     2,string        FileName
        ///     3,byte[]        File bytes
        /// </param>
        /// <returns></returns>
        public override FDFSRequest GetRequest(params object[] paramList)
        {
            if (paramList.Length != 3)
            {
                throw new FDFSException("param count is wrong");
            }
            var endPoint = (IPEndPoint)paramList[0];

            var fileName      = (string)paramList[1];
            var contentBuffer = (byte[])paramList[2];

            var result = new APPEND_FILE {
                StorageConnection = ConnectionManager.GetStorageConnection(endPoint)
            };

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

            byte[] fileNameLenBuffer = Util.LongToBuffer(fileName.Length);
            Array.Copy(fileNameLenBuffer, 0, bodyBuffer, 0, fileNameLenBuffer.Length);

            byte[] fileSizeBuffer = Util.LongToBuffer(contentBuffer.Length);
            Array.Copy(fileSizeBuffer, 0, bodyBuffer, Consts.FDFS_PROTO_PKG_LEN_SIZE, fileSizeBuffer.Length);

            byte[] fileNameBuffer = Util.StringToByte(fileName);
            Array.Copy(fileNameBuffer, 0, bodyBuffer, Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_PROTO_PKG_LEN_SIZE,
                       fileNameBuffer.Length);

            Array.Copy(contentBuffer, 0, bodyBuffer,
                       Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_PROTO_PKG_LEN_SIZE + fileNameBuffer.Length,
                       contentBuffer.Length);

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