示例#1
0
        static DictionaryTableEntity ToDictionaryTableEntity(object entity, string partitionKey, string rowkey, IEnumerable <PropertyInfo> properties)
        {
            var toPersist = new DictionaryTableEntity
            {
                PartitionKey = partitionKey,
                RowKey       = rowkey
            };

            foreach (var propertyInfo in properties)
            {
                if (propertyInfo.PropertyType == typeof(byte[]))
                {
                    toPersist.Add(propertyInfo.Name, (byte[])propertyInfo.GetValue(entity, null));
                }
                else if (propertyInfo.PropertyType == typeof(bool))
                {
                    toPersist.Add(propertyInfo.Name, (bool)propertyInfo.GetValue(entity, null));
                }
                else if (propertyInfo.PropertyType == typeof(DateTime))
                {
                    toPersist.Add(propertyInfo.Name, (DateTime)propertyInfo.GetValue(entity, null));
                }
                else if (propertyInfo.PropertyType == typeof(Guid))
                {
                    toPersist.Add(propertyInfo.Name, (Guid)propertyInfo.GetValue(entity, null));
                }
                else if (propertyInfo.PropertyType == typeof(Int32))
                {
                    toPersist.Add(propertyInfo.Name, (Int32)propertyInfo.GetValue(entity, null));
                }
                else if (propertyInfo.PropertyType == typeof(Int64))
                {
                    toPersist.Add(propertyInfo.Name, (Int64)propertyInfo.GetValue(entity, null));
                }
                else if (propertyInfo.PropertyType == typeof(Double))
                {
                    toPersist.Add(propertyInfo.Name, (Double)propertyInfo.GetValue(entity, null));
                }
                else if (propertyInfo.PropertyType == typeof(string))
                {
                    toPersist.Add(propertyInfo.Name, (string)propertyInfo.GetValue(entity, null));
                }
                else
                {
                    throw new NotSupportedException(
                              string.Format("The property type '{0}' is not supported in windows azure table storage",
                                            propertyInfo.PropertyType.Name));
                }
            }
            return(toPersist);
        }
示例#2
0
 DictionaryTableEntity ToDictionaryTableEntity(object entity, DictionaryTableEntity toPersist, IEnumerable <PropertyInfo> properties)
 {
     foreach (var propertyInfo in properties)
     {
         if (propertyInfo.PropertyType == typeof(byte[]))
         {
             toPersist[propertyInfo.Name] = new EntityProperty((byte[])propertyInfo.GetValue(entity, null));
         }
         else if (propertyInfo.PropertyType == typeof(bool))
         {
             toPersist[propertyInfo.Name] = new EntityProperty((bool)propertyInfo.GetValue(entity, null));
         }
         else if (propertyInfo.PropertyType == typeof(DateTime))
         {
             toPersist[propertyInfo.Name] = new EntityProperty((DateTime)propertyInfo.GetValue(entity, null));
         }
         else if (propertyInfo.PropertyType == typeof(Guid))
         {
             toPersist[propertyInfo.Name] = new EntityProperty((Guid)propertyInfo.GetValue(entity, null));
         }
         else if (propertyInfo.PropertyType == typeof(Int32))
         {
             toPersist[propertyInfo.Name] = new EntityProperty((Int32)propertyInfo.GetValue(entity, null));
         }
         else if (propertyInfo.PropertyType == typeof(Int64))
         {
             toPersist[propertyInfo.Name] = new EntityProperty((Int64)propertyInfo.GetValue(entity, null));
         }
         else if (propertyInfo.PropertyType == typeof(Double))
         {
             toPersist[propertyInfo.Name] = new EntityProperty((Double)propertyInfo.GetValue(entity, null));
         }
         else if (propertyInfo.PropertyType == typeof(string))
         {
             toPersist[propertyInfo.Name] = new EntityProperty((string)propertyInfo.GetValue(entity, null));
         }
         else
         {
             throw new NotSupportedException(
                       string.Format("The property type '{0}' is not supported in windows azure table storage",
                                     propertyInfo.PropertyType.Name));
         }
     }
     return(toPersist);
 }
示例#3
0
        void AddToCache(string id, DictionaryTableEntity tableEntity)
        {
            var item = dictionaryTableCache.GetCacheItem(id);

            if (item == null)
            {
                item = new CacheItem(id, tableEntity);
                dictionaryTableCache.Set(item, new CacheItemPolicy
                {
                    Priority          = CacheItemPriority.NotRemovable,
                    SlidingExpiration = TimeSpan.FromMilliseconds(longevity)
                });
            }
            else
            {
                item.Value = tableEntity;
            }
        }
示例#4
0
        object ToEntity(Type entityType, DictionaryTableEntity entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var toCreate = Activator.CreateInstance(entityType);

            foreach (var propertyInfo in entityType.GetProperties())
            {
                if (entity.ContainsKey(propertyInfo.Name))
                {
                    if (propertyInfo.PropertyType == typeof(byte[]))
                    {
                        propertyInfo.SetValue(toCreate, entity[propertyInfo.Name].BinaryValue, null);
                    }
                    else if (propertyInfo.PropertyType == typeof(bool))
                    {
                        var boolean = entity[propertyInfo.Name].BooleanValue;
                        propertyInfo.SetValue(toCreate, boolean.HasValue && boolean.Value, null);
                    }
                    else if (propertyInfo.PropertyType == typeof(DateTime))
                    {
                        var dateTimeOffset = entity[propertyInfo.Name].DateTimeOffsetValue;
                        propertyInfo.SetValue(toCreate, dateTimeOffset.HasValue ? dateTimeOffset.Value.DateTime : default(DateTime), null);
                    }
                    else if (propertyInfo.PropertyType == typeof(Guid))
                    {
                        var guid = entity[propertyInfo.Name].GuidValue;
                        propertyInfo.SetValue(toCreate, guid.HasValue ? guid.Value : default(Guid), null);
                    }
                    else if (propertyInfo.PropertyType == typeof(Int32))
                    {
                        var int32 = entity[propertyInfo.Name].Int32Value;
                        propertyInfo.SetValue(toCreate, int32.HasValue ? int32.Value : default(Int32), null);
                    }
                    else if (propertyInfo.PropertyType == typeof(Double))
                    {
                        var d = entity[propertyInfo.Name].DoubleValue;
                        propertyInfo.SetValue(toCreate, d.HasValue ? d.Value : default(Int64), null);
                    }
                    else if (propertyInfo.PropertyType == typeof(Int64))
                    {
                        var int64 = entity[propertyInfo.Name].Int64Value;
                        propertyInfo.SetValue(toCreate, int64.HasValue ? int64.Value : default(Int64), null);
                    }
                    else if (propertyInfo.PropertyType == typeof(string))
                    {
                        propertyInfo.SetValue(toCreate, entity[propertyInfo.Name].StringValue, null);
                    }
                    else
                    {
                        throw new NotSupportedException(
                                  string.Format("The property type '{0}' is not supported in windows azure table storage",
                                                propertyInfo.PropertyType.Name));
                    }
                }
            }
            return(toCreate);
        }