コード例 #1
0
 public static ThrottledBufferManager GetThrottledBufferManager(int maxSize)
 {
     if (ThrottledBufferManager.instance == null)
     {
         lock (ThrottledBufferManager.syncLock)
         {
             if (ThrottledBufferManager.instance == null)
             {
                 ThrottledBufferManager.instance = new ThrottledBufferManager(maxSize);
             }
         }
     }
     return(ThrottledBufferManager.instance);
 }
コード例 #2
0
 public WrappedBufferManager(ThrottledBufferManager bufferManager)
 {
     this.ThrottledBufferManager = bufferManager;
 }
コード例 #3
0
 public static InternalBufferManager GetBufferManager()
 {
     return(ThrottledBufferManager.GetThrottledBufferManager().ProxyBufferManager);
 }
コード例 #4
0
 public static ThrottledBufferManager GetThrottledBufferManager()
 {
     return(ThrottledBufferManager.GetThrottledBufferManager(104857600));
 }
コード例 #5
0
        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);
        }