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);
        }
Exemple #2
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];

            byte[] contentByte = (byte[])paramList[2];

            int contentByteLength = contentByte.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");
            }
            int length = 15 + contentByteLength;

            uploadAppendFile.SetBodyBuffer(length);

            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;
                }
            }

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

            uploadAppendFile.Header = new FDFSHeader(length, FDFSConstants.STORAGE_PROTO_CMD_UPLOAD_APPENDER_FILE, 0);
            return(uploadAppendFile);
        }
Exemple #3
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");
            }
            IPEndPoint endPoint = (IPEndPoint)paramList[0];

            byte   storePathIndex = (byte)paramList[1];
            int    fileSize       = (int)paramList[2];
            string ext            = (string)paramList[3];

            byte[] contentBuffer = (byte[])paramList[4];

            #region 拷贝后缀扩展名值
            byte[] extBuffer    = new byte[Consts.FDFS_FILE_EXT_NAME_MAX_LEN];
            byte[] bse          = Util.StringToByte(ext);
            int    ext_name_len = bse.Length;
            if (ext_name_len > Consts.FDFS_FILE_EXT_NAME_MAX_LEN)
            {
                ext_name_len = Consts.FDFS_FILE_EXT_NAME_MAX_LEN;
            }
            Array.Copy(bse, 0, extBuffer, 0, ext_name_len);
            #endregion

            UPLOAD_APPEND_FILE result = new UPLOAD_APPEND_FILE();
            result.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;
            byte[] 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);
        }
Exemple #4
0
        public override FDFSRequest GetRequest(params object[] paramList)
        {
            if ((int)paramList.Length != 5)
            {
                throw new FDFSException("param count is wrong");
            }
            IPEndPoint pEndPoint = (IPEndPoint)paramList[0];
            byte       num       = (byte)paramList[1];
            int        num1      = (int)paramList[2];
            string     str       = (string)paramList[3];

            byte[] numArray  = (byte[])paramList[4];
            byte[] numArray1 = new byte[6];
            byte[] num2      = Util.StringToByte(str);
            int    length    = (int)num2.Length;

            if (length > 6)
            {
                length = 6;
            }
            Array.Copy(num2, 0, numArray1, 0, length);
            UPLOAD_APPEND_FILE uploadAppendFile = new UPLOAD_APPEND_FILE()
            {
                ConnectionType = 1,
                EndPoint       = pEndPoint
            };

            if (str.Length > 6)
            {
                throw new FDFSException("file ext is too long");
            }
            long length1 = 15 + numArray.Length;

            byte[] numArray2 = new byte[length1];
            numArray2[0] = num;
            byte[] buffer = Util.LongToBuffer((long)num1);
            Array.Copy(buffer, 0, numArray2, 1, (int)buffer.Length);
            Array.Copy(numArray1, 0, numArray2, 9, (int)numArray1.Length);
            Array.Copy(numArray, 0, numArray2, 15, (int)numArray.Length);
            uploadAppendFile.Body   = numArray2;
            uploadAppendFile.Header = new FDFSHeader(length1, 23, 0);
            return(uploadAppendFile);
        }
        /// <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");
            IPEndPoint endPoint = (IPEndPoint)paramList[0];

            byte storePathIndex = (byte)paramList[1];
            int fileSize = (int)paramList[2];
            string ext = (string)paramList[3];
            byte[] contentBuffer = (byte[])paramList[4];

            #region 拷贝后缀扩展名值
            byte[] extBuffer = new byte[Consts.FDFS_FILE_EXT_NAME_MAX_LEN];
            byte[] bse = Util.StringToByte(ext);
            int ext_name_len = bse.Length;
            if (ext_name_len > Consts.FDFS_FILE_EXT_NAME_MAX_LEN)
            {
                ext_name_len = Consts.FDFS_FILE_EXT_NAME_MAX_LEN;
            }
            Array.Copy(bse, 0, extBuffer, 0, ext_name_len);
            #endregion

            UPLOAD_APPEND_FILE result = new UPLOAD_APPEND_FILE();
            result.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;
            byte[] 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;
        }
Exemple #6
0
 static UPLOAD_APPEND_FILE()
 {
     UPLOAD_APPEND_FILE._instance = null;
 }