Esempio n. 1
0
            public object FromEntry(DynamoDBEntry entry)
            {
                Primitive primitive = entry.AsPrimitive();
                string    text      = primitive.AsString();
                Status    status    = (Status)Enum.Parse(typeof(Status), text);

                return(status);
            }
Esempio n. 2
0
        public void Initialize(string tableName, Type tableEntityType, Primitive hashKeyValue)
        {
            if (this._tableEntityType != null)
            {
                throw new InvalidOperationException("An attempt to re-use an instance of RedisTableCache for another <table>:<hash key> pair was made. This is not allowed");
            }

            this._tableEntityType = tableEntityType;

            this.TableName    = tableName;
            this.HashKeyValue = hashKeyValue == null ? string.Empty : hashKeyValue.AsString();

            this._redis = new RedisWrapper(this._redisConn, this._dbIndex, this.GetCacheKeyPrefix(), this._cacheItemsTtl, s => this.OnLog.FireSafely(s));
        }
Esempio n. 3
0
        public object FromEntry(DynamoDBEntry entry)
        {
            Primitive primitive        = entry as Primitive;
            var       entryStringValue = primitive?.AsString();

            if (string.IsNullOrEmpty(entryStringValue))
            {
                return(default(TEnum));
            }

            TEnum valueAsEnum = (TEnum)Enum.Parse(typeof(TEnum), entryStringValue);

            return(valueAsEnum);
        }
        public void Initialize(string tableName, Type tableEntityType, Primitive hashKeyValue)
        {
            if (this._tableEntityType != null)
            {
                throw new InvalidOperationException("An attempt to re-use an instance of EnyimTableCache for another <table>:<hash key> pair was made. This is not allowed");
            }

            this._tableEntityType = tableEntityType;

            this._tableName    = tableName;
            this._hashKeyValue = hashKeyValue == null ? string.Empty : hashKeyValue.AsString();

            if (this.GetIndexListKeyInCache(this._hashKeyValue).Length > MaxKeyLength)
            {
                throw new ArgumentException("The hash key value is too long for MemcacheD. Cannot use cache with that value.");
            }
        }
Esempio n. 5
0
        public void Initialize(string tableName, Type tableEntityType, Primitive hashKeyValue)
        {
            if (this._tableEntityType != null)
            {
                throw new InvalidOperationException("An attempt to re-use an instance of EnyimTableCache for another <table>:<hash key> pair was made. This is not allowed");
            }

            this._tableEntityType = tableEntityType;

            this._tableName = tableName;
            this._hashKeyValue = hashKeyValue == null ? string.Empty : hashKeyValue.AsString();

            if (this.GetIndexListKeyInCache(this._hashKeyValue).Length > MaxKeyLength)
            {
                throw new ArgumentException("The hash key value is too long for MemcacheD. Cannot use cache with that value.");
            }
        }
Esempio n. 6
0
        public object FromEntry(DynamoDBEntry entry)
        {
            Primitive primitive = entry as Primitive;

            if (primitive == null)
            {
                return(null);
            }

            if (primitive.Type != DynamoDBEntryType.String)
            {
                throw new InvalidCastException();
            }
            string xml = primitive.AsString();

            using (StringReader reader = new StringReader(xml))
            {
                return(_serializer.Deserialize(reader));
            }
        }
 public static object PrimitiveToValue(Type type, Primitive primitive)
 {
     if (type == typeof(float))
     {
         return(primitive.AsSingle());
     }
     if (type == typeof(int))
     {
         return(primitive.AsInt());
     }
     if (type == typeof(string))
     {
         return(primitive.AsString());
     }
     if (type == typeof(long))
     {
         return(primitive.AsLong());
     }
     if (type == typeof(byte[]))
     {
         return(primitive.AsByteArray());
     }
     if (type.IsEnum)
     {
         return(Enum.Parse(type, primitive));
     }
     if (type == typeof(bool))
     {
         return(primitive.AsBoolean());
     }
     if (type == typeof(Guid))
     {
         return(primitive.AsGuid());
     }
     if (type == typeof(object))
     {
         return(primitive.Value);
     }
     throw new Exception(string.Format("Unsupported type {0}", type.Name));
 }
        // Primitive <--> Value type
        private static bool TryFromPrimitive(Type targetType, Primitive value, out object output)
        {
            if (value.Value == null)
            {
                output = null;
                return(true);
            }

            if (targetType.IsAssignableFrom(typeof(Boolean)))
            {
                output = value.AsBoolean();
            }
            else if (targetType.IsAssignableFrom(typeof(Byte)))
            {
                output = value.AsByte();
            }
            else if (targetType.IsAssignableFrom(typeof(Char)))
            {
                output = value.AsChar();
            }
            else if (targetType.IsAssignableFrom(typeof(DateTime)))
            {
                output = value.AsDateTime();
            }
            else if (targetType.IsAssignableFrom(typeof(Decimal)))
            {
                output = value.AsDecimal();
            }
            else if (targetType.IsAssignableFrom(typeof(Double)))
            {
                output = value.AsDouble();
            }
            else if (targetType.IsAssignableFrom(typeof(int)))
            {
                output = value.AsInt();
            }
            else if (targetType.IsAssignableFrom(typeof(long)))
            {
                output = value.AsLong();
            }
            else if (targetType.IsAssignableFrom(typeof(SByte)))
            {
                output = value.AsSByte();
            }
            else if (targetType.IsAssignableFrom(typeof(short)))
            {
                output = value.AsShort();
            }
            else if (targetType.IsAssignableFrom(typeof(Single)))
            {
                output = value.AsSingle();
            }
            else if (targetType.IsAssignableFrom(typeof(String)))
            {
                output = value.AsString();
            }
            else if (targetType.IsAssignableFrom(typeof(uint)))
            {
                output = value.AsUInt();
            }
            else if (targetType.IsAssignableFrom(typeof(ulong)))
            {
                output = value.AsULong();
            }
            else if (targetType.IsAssignableFrom(typeof(ushort)))
            {
                output = value.AsUShort();
            }
            else if (targetType.IsAssignableFrom(typeof(Guid)))
            {
                output = value.AsGuid();
            }
            else if (targetType.IsAssignableFrom(typeof(byte[])))
            {
                output = value.AsByteArray();
            }
            else if (targetType.IsAssignableFrom(typeof(MemoryStream)))
            {
                output = value.AsMemoryStream();
            }
            else
            {
                output = null;
                return(false);
            }
            return(true);
        }
Esempio n. 9
0
        // Primitive <--> Value type
        private static bool TryFromPrimitive(Type targetType, Primitive value, out object output)
        {
            if (value.Value == null)
            {
                output = null;
                return(true);
            }

            try
            {
                var targetTypeWrapper = TypeFactory.GetTypeInfo(targetType);
                if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(Boolean))))
                {
                    output = value.AsBoolean();
                }
                else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(Byte))))
                {
                    output = value.AsByte();
                }
                else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(Char))))
                {
                    output = value.AsChar();
                }
                else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(DateTime))))
                {
                    output = value.AsDateTime();
                }
                else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(Decimal))))
                {
                    output = value.AsDecimal();
                }
                else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(Double))))
                {
                    output = value.AsDouble();
                }
                else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(int))))
                {
                    output = value.AsInt();
                }
                else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(long))))
                {
                    output = value.AsLong();
                }
                else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(SByte))))
                {
                    output = value.AsSByte();
                }
                else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(short))))
                {
                    output = value.AsShort();
                }
                else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(Single))))
                {
                    output = value.AsSingle();
                }
                else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(String))))
                {
                    output = value.AsString();
                }
                else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(uint))))
                {
                    output = value.AsUInt();
                }
                else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(ulong))))
                {
                    output = value.AsULong();
                }
                else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(ushort))))
                {
                    output = value.AsUShort();
                }
                else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(Guid))))
                {
                    output = value.AsGuid();
                }
                else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(byte[]))))
                {
                    output = value.AsByteArray();
                }
                else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(MemoryStream))))
                {
                    output = value.AsMemoryStream();
                }
                else
                {
                    output = null;
                    return(false);
                }
                return(true);
            }
            catch (InvalidCastException)
            {
                throw new InvalidCastException(string.Format(CultureInfo.InvariantCulture,
                                                             "Unable to cast value [{0}] of type [{1}] to type [{2}]",
                                                             value.Value,
                                                             value.Value.GetType().FullName,
                                                             targetType.FullName));
            }
        }
Esempio n. 10
0
        public object FromEntry(DynamoDBEntry entry)
        {
            Primitive p = entry as Primitive;

            return(StringToDateTime(p.AsString()));
        }