Exemplo n.º 1
0
        /// <summary>
        /// 写入数据
        /// </summary>
        /// <param name="data">数据</param>
        /// <returns>写入位置,失败返回-1</returns>
        internal long UnsafeWrite(ref memoryPool.pushSubArray data)
        {
            subArray <byte> dataArray = data.Value;

            Monitor.Enter(bufferLock);
            if (isDisposed == 0)
            {
                long fileBufferLength = this.fileBufferLength;
                this.fileBufferLength += dataArray.length;
                if (isWritting == 0)
                {
                    int length = currentIndex + dataArray.length;
                    if (length < bufferLength && flushCount == 0)
                    {
                        Buffer.BlockCopy(dataArray.array, dataArray.startIndex, buffer, currentIndex, dataArray.length);
                        checkFlushTime = date.nowTime.Now.AddTicks(checkFlushTicks);
                        currentIndex   = length;
                        bufferIndex    = this.fileBufferLength;
                        flushWait.Reset();
                        Monitor.Exit(bufferLock);
                        data.Push();
                        setCheckFlush();
                    }
                    else
                    {
                        buffers.array[0] = data;
                        buffers.UnsafeAddLength(1);
                        bufferSize  += dataArray.length;
                        isFlush      = 0;
                        isWritting   = 1;
                        isCopyBuffer = 0;
                        flushWait.Reset();
                        Monitor.Exit(bufferLock);
                        threadPool.TinyPool.FastStart(this, thread.callType.FileStreamWriteFile);
                    }
                }
                else
                {
                    try
                    {
                        buffers.Add(ref data);
                        bufferSize  += dataArray.length;
                        isCopyBuffer = 0;
                        flushWait.Reset();
                    }
                    finally { Monitor.Exit(bufferLock); }
                }
                return(fileBufferLength);
            }
            Monitor.Exit(bufferLock);
            data.Push();
            return(-1);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 写入数据
 /// </summary>
 /// <param name="data">数据</param>
 /// <param name="index">起始位置</param>
 /// <param name="count">写入字节数</param>
 /// <returns>写入位置,失败返回-1</returns>
 public long Write(byte[] data, int index, int count)
 {
     if (index + count > data.length() || index < 0 || count < 0)
     {
         log.Error.Throw(log.exceptionType.IndexOutOfRange);
     }
     if (count != 0)
     {
         memoryPool.pushSubArray pushData = default(memoryPool.pushSubArray);
         pushData.Value.UnsafeSet(data, index, count);
         return(UnsafeWrite(ref pushData));
     }
     return(0);
 }
Exemplo n.º 3
0
        /// <summary>
        /// 获取商品二维码URL
        /// </summary>
        /// <param name="product_id"></param>
        /// <returns></returns>
        public unsafe string GetProductUrl(string product_id)
        {
            productUrlSign sign = new productUrlSign {
                product_id = product_id
            };

            sign.setConfig(this);
            memoryPool.pushSubArray data = sign <productUrlSign> .GetData(sign, key);

            try
            {
                fixed(byte *bufferFixed = data.UnsafeArray)
                {
                    using (MD5 md5 = new MD5CryptoServiceProvider())
                    {
                        return("weixin://wxpay/bizpayurl?" + fastCSharp.String.UnsafeDeSerialize(bufferFixed, -data.SubArray.Count) + "&sign=" + sign.sign);
                    }
                }
            }
            finally { data.Push(); }
        }
Exemplo n.º 4
0
 internal long UnsafeWrite(byte[] data, int index, int count)
 {
     memoryPool.pushSubArray pushData = default(memoryPool.pushSubArray);
     pushData.Value.UnsafeSet(data, index, count);
     return(UnsafeWrite(ref pushData));
 }
Exemplo n.º 5
0
 internal long UnsafeWrite(byte[] data)
 {
     memoryPool.pushSubArray pushData = default(memoryPool.pushSubArray);
     pushData.Value.UnsafeSet(data, 0, data.Length);
     return(UnsafeWrite(ref pushData));
 }