Esempio n. 1
0
        public static bool FillObjectWithEntity <TObject>(this PartitionInfo <TObject> partition, TObject obj, DynamicTableEntity entity)
        {
            if (entity == null)
            {
                return(false);
            }
            if (!DoesKeyInfoMatchKey(partition.PartitionKey, entity.PartitionKey))
            {
                return(false);
            }

            RowInfo <TObject> rowInfo;

            try
            {
                rowInfo = partition.Rows.Single(e => DoesKeyInfoMatchKey(e.RowKey, entity.RowKey));
            }
            catch (InvalidOperationException)
            {
                return(false);
            }

            partition.PartitionKey.KeySetter.Invoke(obj, entity.PartitionKey);
            rowInfo.RowKey.KeySetter.Invoke(obj, entity.RowKey);
            rowInfo.Properties.PropertiesSetter.Invoke(obj, entity.Properties);

            return(true);
        }
Esempio n. 2
0
        public static IEnumerable <DynamicTableEntity> ConvertObjectToEntities <TObject>(this PartitionInfo <TObject> partition, TObject obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }
            var partitionKey = partition.PartitionKey.KeyGetter.Invoke(obj);

            foreach (var entityInfo in partition.Rows)
            {
                var rowKey           = entityInfo.RowKey.KeyGetter.Invoke(obj);
                var entityProperties = entityInfo.Properties.PropertiesGetter.Invoke(obj).ToDictionary(e => e.Key, e => e.Value);
                yield return(new DynamicTableEntity(partitionKey, rowKey, null, entityProperties));
            }
        }
Esempio n. 3
0
        public static bool FillObjectWithEntity <TObject>(this PartitionInfo <TObject> partition, TObject obj, IEnumerable <DynamicTableEntity> entities)
        {
            var entityCollection = entities as ICollection <DynamicTableEntity> ?? entities.ToArray();

            return(entityCollection.Count > 0 && entityCollection.Aggregate(true, (b, entity) => b && partition.FillObjectWithEntity(obj, entity)));
        }