Esempio n. 1
0
        /// <summary>
        /// Deserializes the specified value.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public T Deserialize <T>(RedisValue value) where T : class
        {
            using (var memoryStream = new MemoryStream(value))
            {
                var type = typeof(T);
                var isRedisCacheItemType = type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IRedisCacheItem <>);
                var valueType            = isRedisCacheItemType ? type.GetGenericArguments().FirstOrDefault() : null;

                if (valueType != null && valueType == typeof(DataTable))
                {
                    return(new ProtobufRedisCacheItem <DataTable>
                    {
                        Value = DataSerializer.DeserializeDataTable(memoryStream)
                    } as T);
                }

                if (valueType != null && valueType == typeof(DataSet))
                {
                    return(new ProtobufRedisCacheItem <DataSet>
                    {
                        Value = DataSerializer.DeserializeDataSet(memoryStream)
                    } as T);
                }

                if (valueType != null && valueType == typeof(IDataReader))
                {
                    return(new ProtobufRedisCacheItem <IDataReader>
                    {
                        Value = DataSerializer.Deserialize(memoryStream)
                    } as T);
                }

                if (configuration.BuildSerializers != null)
                {
                    configuration.BuildSerializers.Build <T>();
                }

                if (isRedisCacheItemType)
                {
                    var originalType = type;
                    type = ProtobutRedisCacheItemType;
                    type = type.MakeGenericType(originalType.GetGenericArguments());
                }

                return(Serializer.NonGeneric.Deserialize(type, memoryStream) as T);
            }
        }
            public void ShouldDeserializeDataSet()
            {
                // Arrange
                var dataSet = new DataSet();

                dataSet.Tables.Add(this.CreateTable(0));

                var stream = new MemoryStream();

                DataSerializer.Serialize(stream, dataSet);

                stream.Position = 0;

                // Act
                var result = DataSerializer.DeserializeDataSet(stream, "bar");

                // Assert
                Assert.Single(result.Tables);
            }
Esempio n. 3
0
        public static BooleanValue <DataSet> DeSerializeDataSet(byte[] buffer, params string[] tables)
        {
            using (MemoryStream ms = new MemoryStream(buffer))
            {
                DataSet ds = null;
                BooleanValue <DataSet> bv = new BooleanValue <DataSet>(ds);
                try
                {
                    ds       = DataSerializer.DeserializeDataSet(ms, tables);
                    bv.Value = ds;
                }
                catch (Exception ex)
                {
                    bv.ErrorText = ex.Message;
                }

                return(bv);
            }
        }