/// <summary>
        /// </summary>
        /// <param name="paramList">
        ///     1,IPEndPoint    IPEndPoint-->the storage IPEndPoint
        ///     2,Byte          StorePathIndex
        ///     3,long          FileSize
        ///     4,string        File Ext
        ///     5,byte[FileSize]    File Content
        /// </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 storePathIndex = (byte)paramList[1];
            var fileSize       = (int)paramList[2];
            var ext            = (string)paramList[3];
            var contentBuffer  = (byte[])paramList[4];

            #region 拷贝后缀扩展名值

            var    extBuffer  = new byte[Consts.FDFS_FILE_EXT_NAME_MAX_LEN];
            byte[] bse        = Util.StringToByte(ext);
            int    extNameLen = bse.Length;
            if (extNameLen > Consts.FDFS_FILE_EXT_NAME_MAX_LEN)
            {
                extNameLen = Consts.FDFS_FILE_EXT_NAME_MAX_LEN;
            }
            Array.Copy(bse, 0, extBuffer, 0, extNameLen);

            #endregion

            var result = new UPLOAD_APPEND_FILE {
                Connection = ConnectionManager.GetStorageConnection(endPoint)
            };
            if (ext.Length > Consts.FDFS_FILE_EXT_NAME_MAX_LEN)
            {
                throw new FDFSException("file ext is too long");
            }

            long length     = 1 + Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_FILE_EXT_NAME_MAX_LEN + contentBuffer.Length;
            var  bodyBuffer = new byte[length];
            bodyBuffer[0] = storePathIndex;

            byte[] fileSizeBuffer = Util.LongToBuffer(fileSize);
            Array.Copy(fileSizeBuffer, 0, bodyBuffer, 1, fileSizeBuffer.Length);

            Array.Copy(extBuffer, 0, bodyBuffer, 1 + Consts.FDFS_PROTO_PKG_LEN_SIZE, extBuffer.Length);

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

            result.Body   = bodyBuffer;
            result.Header = new FDFSHeader(length, Consts.STORAGE_PROTO_CMD_UPLOAD_APPENDER_FILE, 0);
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// </summary>
        /// <param name="paramList">
        ///     1,IPEndPoint    IPEndPoint-->the storage IPEndPoint
        ///     2,Byte          StorePathIndex
        ///     3,long          FileSize
        ///     4,string        File Ext
        ///     5,byte[FileSize]    File Content
        /// </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 storePathIndex = (byte)paramList[1];
            var fileSize = (int)paramList[2];
            var ext = (string)paramList[3];
            var contentBuffer = (byte[])paramList[4];

            #region 拷贝后缀扩展名值

            var extBuffer = new byte[Consts.FDFS_FILE_EXT_NAME_MAX_LEN];
            byte[] bse = Util.StringToByte(ext);
            int extNameLen = bse.Length;
            if (extNameLen > Consts.FDFS_FILE_EXT_NAME_MAX_LEN)
            {
                extNameLen = Consts.FDFS_FILE_EXT_NAME_MAX_LEN;
            }
            Array.Copy(bse, 0, extBuffer, 0, extNameLen);

            #endregion

            var result = new UPLOAD_APPEND_FILE { Connection = ConnectionManager.GetStorageConnection(endPoint) };
            if (ext.Length > Consts.FDFS_FILE_EXT_NAME_MAX_LEN)
                throw new FDFSException("file ext is too long");

            long length = 1 + Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_FILE_EXT_NAME_MAX_LEN + contentBuffer.Length;
            var bodyBuffer = new byte[length];
            bodyBuffer[0] = storePathIndex;

            byte[] fileSizeBuffer = Util.LongToBuffer(fileSize);
            Array.Copy(fileSizeBuffer, 0, bodyBuffer, 1, fileSizeBuffer.Length);

            Array.Copy(extBuffer, 0, bodyBuffer, 1 + Consts.FDFS_PROTO_PKG_LEN_SIZE, extBuffer.Length);

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

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