コード例 #1
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 != 6)
            {
                throw new FDFSException("param count is wrong");
            }
            IPEndPoint endPoint = (IPEndPoint)paramList[0];

            int    fileSize       = (int)paramList[1];
            string masterFilename = paramList[2].ToString();
            string prefix_name    = (string)paramList[3];
            string ext            = (string)paramList[4];

            byte[] contentBuffer = (byte[])paramList[5];
            byte[] sizeBytes;
            byte[] hexLenBytes;
            byte[] masterFilenameBytes = Util.StringToByte(masterFilename);
            int    offset;

            #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_SLAVE_FILE result = new UPLOAD_SLAVE_FILE();
            result.Connection = ConnectionManager.GetStorageConnection(endPoint);
            if (ext.Length > Consts.FDFS_FILE_EXT_NAME_MAX_LEN)
            {
                throw new FDFSException("file ext is too long");
            }

            sizeBytes = new byte[2 * Consts.FDFS_PROTO_PKG_LEN_SIZE];
            //long length = 1 + Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_FILE_EXT_NAME_MAX_LEN + contentBuffer.Length;
            long length = sizeBytes.Length + +Consts.FDFS_FILE_PREFIX_MAX_LEN + Consts.FDFS_FILE_EXT_NAME_MAX_LEN + masterFilenameBytes.Length + contentBuffer.Length;
            //body_len = sizeBytes.length + ProtoCommon.FDFS_FILE_PREFIX_MAX_LEN + ProtoCommon.FDFS_FILE_EXT_NAME_MAX_LEN
            //             + masterFilenameBytes.length + file_size;
            byte[] bodyBuffer = new byte[length];
            hexLenBytes = Util.LongToBuffer(masterFilename.Length);
            offset      = hexLenBytes.Length;

            //Array.Copy(hexLenBytes, 0, sizeBytes, 0, hexLenBytes.Length);

            Array.Copy(hexLenBytes, 0, bodyBuffer, 0, hexLenBytes.Length);
            //System.arraycopy(sizeBytes, 0, wholePkg, header.length, sizeBytes.length);

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

            offset = sizeBytes.Length;

            byte[] prefix_name_bs  = new byte[Consts.FDFS_FILE_PREFIX_MAX_LEN];
            byte[] bs              = Util.StringToByte(prefix_name);
            int    prefix_name_len = bs.Length;
            if (prefix_name_len > Consts.FDFS_FILE_PREFIX_MAX_LEN)
            {
                prefix_name_len = Consts.FDFS_FILE_PREFIX_MAX_LEN;
            }
            if (prefix_name_len > 0)
            {
                Array.Copy(bs, 0, prefix_name_bs, 0, prefix_name_len);
            }
            Array.Copy(prefix_name_bs, 0, bodyBuffer, offset, prefix_name_bs.Length);

            offset += prefix_name_bs.Length;

            Array.Copy(extBuffer, 0, bodyBuffer, offset, extBuffer.Length);

            offset += extBuffer.Length;

            Array.Copy(masterFilenameBytes, 0, bodyBuffer, offset, masterFilenameBytes.Length);
            offset += masterFilenameBytes.Length;

            Array.Copy(contentBuffer, 0, bodyBuffer, offset, contentBuffer.Length);

            result.Body   = bodyBuffer;
            result.Header = new FDFSHeader(length, Consts.STORAGE_PROTO_CMD_UPLOAD_SLAVE_FILE, 0);
            return(result);
        }
コード例 #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 != 6)
                throw new FDFSException("param count is wrong");
            IPEndPoint endPoint = (IPEndPoint)paramList[0];
            
            int fileSize = (int)paramList[1];
            string masterFilename = paramList[2].ToString();
            string prefix_name = (string)paramList[3];
            string ext = (string)paramList[4];
            byte[] contentBuffer = (byte[])paramList[5];
            byte[] sizeBytes;
            byte[] hexLenBytes;
            byte[] masterFilenameBytes = Util.StringToByte(masterFilename);
            int offset;

            #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_SLAVE_FILE result = new UPLOAD_SLAVE_FILE();
            result.Connection = ConnectionManager.GetStorageConnection(endPoint);
            if(ext.Length>Consts.FDFS_FILE_EXT_NAME_MAX_LEN)
                throw new FDFSException("file ext is too long");

            sizeBytes = new byte[2 * Consts.FDFS_PROTO_PKG_LEN_SIZE];
            //long length = 1 + Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_FILE_EXT_NAME_MAX_LEN + contentBuffer.Length;
            long length = sizeBytes.Length + +Consts.FDFS_FILE_PREFIX_MAX_LEN + Consts.FDFS_FILE_EXT_NAME_MAX_LEN + masterFilenameBytes.Length + contentBuffer.Length;
            //body_len = sizeBytes.length + ProtoCommon.FDFS_FILE_PREFIX_MAX_LEN + ProtoCommon.FDFS_FILE_EXT_NAME_MAX_LEN
            //             + masterFilenameBytes.length + file_size;
            byte[] bodyBuffer = new byte[length];
            hexLenBytes = Util.LongToBuffer(masterFilename.Length);
            offset = hexLenBytes.Length;

            //Array.Copy(hexLenBytes, 0, sizeBytes, 0, hexLenBytes.Length);

            Array.Copy(hexLenBytes, 0, bodyBuffer, 0, hexLenBytes.Length);
            //System.arraycopy(sizeBytes, 0, wholePkg, header.length, sizeBytes.length);

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

            offset = sizeBytes.Length ;

            byte[] prefix_name_bs = new byte[Consts.FDFS_FILE_PREFIX_MAX_LEN];
            byte[] bs = Util.StringToByte(prefix_name);
            int prefix_name_len = bs.Length;
            if (prefix_name_len > Consts.FDFS_FILE_PREFIX_MAX_LEN)
            {
                prefix_name_len = Consts.FDFS_FILE_PREFIX_MAX_LEN;
            }
            if (prefix_name_len > 0)
            {
                Array.Copy(bs, 0, prefix_name_bs, 0, prefix_name_len);
            }
            Array.Copy(prefix_name_bs, 0, bodyBuffer, offset, prefix_name_bs.Length);

            offset += prefix_name_bs.Length;

            Array.Copy(extBuffer, 0, bodyBuffer, offset , extBuffer.Length);

            offset += extBuffer.Length;

            Array.Copy(masterFilenameBytes, 0, bodyBuffer, offset, masterFilenameBytes.Length);
            offset += masterFilenameBytes.Length;

            Array.Copy(contentBuffer, 0, bodyBuffer, offset , contentBuffer.Length);

            result.Body = bodyBuffer;
            result.Header = new FDFSHeader(length, Consts.STORAGE_PROTO_CMD_UPLOAD_SLAVE_FILE, 0);
            return result;
        }
コード例 #3
0
        public override FDFSRequest GetRequest(params object[] paramList)
        {
            if (paramList.Length != 6)
            {
                throw new FDFSException("param count is wrong");
            }
            IPEndPoint endPoint = (IPEndPoint)paramList[0];
            int        num      = (int)paramList[1];
            string     input    = paramList[2].ToString();
            string     str2     = (string)paramList[3];
            string     str3     = (string)paramList[4];

            byte[] sourceArray      = (byte[])paramList[5];
            byte[] buffer4          = Util.StringToByte(input);
            byte[] destinationArray = new byte[6];
            byte[] buffer6          = Util.StringToByte(str3);
            int    length           = buffer6.Length;

            if (length > 6)
            {
                length = 6;
            }
            Array.Copy(buffer6, 0, destinationArray, 0, length);
            UPLOAD_SLAVE_FILE uploadSlaveFile = new UPLOAD_SLAVE_FILE
            {
                ConnectionType = 1,
                EndPoint       = endPoint
            };

            if (str3.Length > 6)
            {
                throw new FDFSException("file ext is too long");
            }
            byte[] buffer2 = new byte[0x10];
            long   num4    = (((buffer2.Length + 0x10) + 6) + buffer4.Length) + sourceArray.Length;

            byte[] buffer7          = new byte[num4];
            byte[] buffer3          = Util.LongToBuffer((long)input.Length);
            int    destinationIndex = buffer3.Length;

            Array.Copy(buffer3, 0, buffer7, 0, buffer3.Length);
            byte[] buffer8 = Util.LongToBuffer((long)num);
            Array.Copy(buffer8, 0, buffer7, destinationIndex, buffer8.Length);
            destinationIndex = buffer2.Length;
            byte[] buffer9  = new byte[0x10];
            byte[] buffer10 = Util.StringToByte(str2);
            int    num5     = buffer10.Length;

            if (num5 > 0x10)
            {
                num5 = 0x10;
            }
            if (num5 > 0)
            {
                Array.Copy(buffer10, 0, buffer9, 0, num5);
            }
            Array.Copy(buffer9, 0, buffer7, destinationIndex, buffer9.Length);
            destinationIndex += buffer9.Length;
            Array.Copy(destinationArray, 0, buffer7, destinationIndex, destinationArray.Length);
            destinationIndex += destinationArray.Length;
            Array.Copy(buffer4, 0, buffer7, destinationIndex, buffer4.Length);
            destinationIndex += buffer4.Length;
            Array.Copy(sourceArray, 0, buffer7, destinationIndex, sourceArray.Length);
            uploadSlaveFile.Body   = buffer7;
            uploadSlaveFile.Header = new FDFSHeader(num4, 0x15, 0);
            return(uploadSlaveFile);
        }