Example #1
0
        public virtual T[] TakeBuffer <T>(int bufferCount)
        {
            T[]  buffer;
            bool doTrack = false;

            if (typeof(T) == typeof(double))
            {
                buffer  = _doublePool.TakeBuffer(bufferCount) as T[];
                doTrack = true;
            }
            else if (typeof(T) == typeof(byte))
            {
                buffer  = _bytePool.TakeBuffer(bufferCount) as T[];
                doTrack = true;
            }
            else
            {
                buffer = new T[bufferCount];
            }
            if (doTrack)
            {
                AtomicCounter cnt;
                if (_cwt.TryGetValue(buffer, out cnt))
                {
                    Interlocked.Increment(ref cnt.Count);
                }
                else
                {
                    _cwt.Add(buffer, new AtomicCounter {
                        Count = 1
                    });
                }
            }
            return(buffer);
        }
Example #2
0
            public override byte[] TakeBuffer(int bufferSize)
            {
                if (bufferSize < 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(bufferSize), bufferSize,
                                                                                                              SR.ValueMustBeNonNegative));
                }

                return(innerBufferManager.TakeBuffer(bufferSize));
            }
Example #3
0
 public T[] TakeBuffer <T>(int bufferCount)
 {
     if (typeof(T) == typeof(double))
     {
         return(_doublePool.TakeBuffer(bufferCount) as T[]);
     }
     else
     {
         return(new T[bufferCount]);
     }
 }
Example #4
0
 private static ByteBuffer.ManagedBuffer AllocateBuffer(int size, InternalBufferManager bufferManager)
 {
     if (bufferManager != null)
     {
         byte[] numArray = bufferManager.TakeBuffer(size);
         if (numArray != null)
         {
             return(new ByteBuffer.ManagedBuffer(numArray, bufferManager));
         }
     }
     return(new ByteBuffer.ManagedBuffer(ByteBuffer.BufferManager.TakeBuffer(size), ByteBuffer.BufferManager));
 }
Example #5
0
 public void Reinitialize(int initialSize, int maxSizeQuota, int effectiveMaxSize, InternalBufferManager bufferManager)
 {
     this.maxSizeQuota     = maxSizeQuota;
     this.maxSize          = effectiveMaxSize;
     this.bufferManager    = bufferManager;
     this.currentChunk     = bufferManager.TakeBuffer(initialSize);
     this.currentChunkSize = 0;
     this.totalSize        = 0;
     this.chunkCount       = 1;
     this.chunks[0]        = this.currentChunk;
     this.initialized      = true;
 }
Example #6
0
        private static void DeserializeGroupState(SessionState messageGroupState, XmlReader reader)
        {
            int num;

            byte[] numArray = SessionState.ReadBytes(reader, 9);
            long   num1     = BitConverter.ToInt64(numArray, 1);

            if (num1 == (long)0)
            {
                return;
            }
            InternalBufferManager bufferManager = ThrottledBufferManager.GetBufferManager();

            using (BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(1024, 2147483647, bufferManager))
            {
                byte[] numArray1 = bufferManager.TakeBuffer(1024);
                long   num2      = (long)0;
                try
                {
                    while (true)
                    {
                        int num3 = reader.ReadContentAsBase64(numArray1, 0, (int)numArray1.Length);
                        if (num3 == 0)
                        {
                            break;
                        }
                        num2 = num2 + (long)num3;
                        bufferedOutputStream.Write(numArray1, 0, num3);
                    }
                }
                finally
                {
                    bufferManager.ReturnBuffer(numArray1);
                }
                byte[] array = bufferedOutputStream.ToArray(out num);
                messageGroupState.Stream = new BufferedInputStream(array, num, bufferManager);
                if (num1 > (long)0 && num2 != num1)
                {
                    throw Fx.Exception.AsError(new InvalidOperationException(SRClient.FailedToDeSerializeEntireSessionStateStream), null);
                }
            }
        }
Example #7
0
 public T[] TakeBuffer <T>(int bufferCount)
 {
     if (typeof(T) == typeof(double))
     {
         var           buffer = _doublePool.TakeBuffer(bufferCount) as T[];
         AtomicCounter cnt;
         if (_cwt.TryGetValue(buffer, out cnt))
         {
             cnt.Count++;
         }
         else
         {
             _cwt.Add(buffer, new AtomicCounter {
                 Count = 1
             });
         }
         return(buffer);
     }
     else
     {
         return(new T[bufferCount]);
     }
 }
        public static object ConvertByteArrayToNativeValue(int messageVersion, PropertyValueType propertyTypeId, byte[] bytes)
        {
            switch (propertyTypeId)
            {
            case PropertyValueType.Null:
            {
                return(null);
            }

            case PropertyValueType.Byte:
            {
                return(bytes[0]);
            }

            case PropertyValueType.SByte:
            {
                return((sbyte)bytes[0]);
            }

            case PropertyValueType.Char:
            {
                return(BitConverter.ToChar(bytes, 0));
            }

            case PropertyValueType.Int16:
            {
                return(BitConverter.ToInt16(bytes, 0));
            }

            case PropertyValueType.UInt16:
            {
                return(BitConverter.ToUInt16(bytes, 0));
            }

            case PropertyValueType.Int32:
            {
                return(BitConverter.ToInt32(bytes, 0));
            }

            case PropertyValueType.UInt32:
            {
                return(BitConverter.ToUInt32(bytes, 0));
            }

            case PropertyValueType.Int64:
            {
                return(BitConverter.ToInt64(bytes, 0));
            }

            case PropertyValueType.UInt64:
            {
                return(BitConverter.ToUInt64(bytes, 0));
            }

            case PropertyValueType.Single:
            {
                return(BitConverter.ToSingle(bytes, 0));
            }

            case PropertyValueType.Double:
            {
                return(BitConverter.ToDouble(bytes, 0));
            }

            case PropertyValueType.Decimal:
            {
                if (messageVersion < BrokeredMessage.MessageVersion3)
                {
                    return(XmlConvert.ToDecimal(Encoding.UTF8.GetString(bytes)));
                }
                int[] num = new int[] { BitConverter.ToInt32(bytes, 0), BitConverter.ToInt32(bytes, 4), BitConverter.ToInt32(bytes, 8), BitConverter.ToInt32(bytes, 12) };
                return(new decimal(num));
            }

            case PropertyValueType.Boolean:
            {
                return(BitConverter.ToBoolean(bytes, 0));
            }

            case PropertyValueType.Guid:
            {
                return(new Guid(bytes));
            }

            case PropertyValueType.String:
            {
                return(Encoding.UTF8.GetString(bytes));
            }

            case PropertyValueType.Uri:
            {
                return(new Uri(Encoding.UTF8.GetString(bytes)));
            }

            case PropertyValueType.DateTime:
            {
                return(DateTime.FromBinary(BitConverter.ToInt64(bytes, 0)));
            }

            case PropertyValueType.DateTimeOffset:
            {
                if (messageVersion < BrokeredMessage.MessageVersion3)
                {
                    return(XmlConvert.ToDateTimeOffset(Encoding.UTF8.GetString(bytes)));
                }
                long num1 = BitConverter.ToInt64(bytes, 0);
                long num2 = BitConverter.ToInt64(bytes, 8);
                return(new DateTimeOffset(num1, TimeSpan.FromTicks(num2)));
            }

            case PropertyValueType.TimeSpan:
            {
                if (messageVersion >= BrokeredMessage.MessageVersion3)
                {
                    return(TimeSpan.FromTicks(BitConverter.ToInt64(bytes, 0)));
                }
                double num3 = BitConverter.ToDouble(bytes, 0);
                if (num3.CompareTo(TimeSpan.MaxValue.TotalMilliseconds) == 0)
                {
                    return(TimeSpan.MaxValue);
                }
                return(TimeSpan.FromMilliseconds(num3));
            }

            case PropertyValueType.Stream:
            {
                InternalBufferManager bufferManager = ThrottledBufferManager.GetBufferManager();
                int    length   = (int)bytes.Length;
                byte[] numArray = bufferManager.TakeBuffer(length);
                Buffer.BlockCopy(bytes, 0, numArray, 0, length);
                return(new BufferedInputStream(numArray, length, bufferManager));
            }
            }
            throw Fx.Exception.AsError(new SerializationException(SRClient.FailedToDeserializeUnsupportedProperty(propertyTypeId.ToString())), null);
        }