示例#1
0
        private ItemStorage ObjectToItemStorage(object toStore, Type objectType, bool keysOnly, DynamoDBFlatConfig flatConfig)
        {
            ItemStorageConfig config  = StorageConfigCache.GetConfig(objectType, flatConfig);
            ItemStorage       storage = ObjectToItemStorageHelper(toStore, config, flatConfig, keysOnly, flatConfig.IgnoreNullValues.Value);

            return(storage);
        }
示例#2
0
        private IEnumerable <T> FromSearch <T>(ContextSearch cs)
        {
            if (cs == null)
            {
                throw new ArgumentNullException("cs");
            }

            // Configure search to not collect results
            cs.Search.CollectResults = false;

            ItemStorageConfig storageConfig = StorageConfigCache.GetConfig <T>(cs.FlatConfig);

            while (!cs.Search.IsDone)
            {
                List <Document> set = cs.Search.GetNextSetHelper(false);
                foreach (var document in set)
                {
                    ItemStorage storage = new ItemStorage(storageConfig);
                    storage.Document = document;
                    T instance = DocumentToObject <T>(storage, cs.FlatConfig);
                    yield return(instance);
                }
            }

            // Reset search to allow retrieving items more than once
            cs.Search.Reset();
        }
示例#3
0
        // Serializes a given value to Document
        // Use only for property conversions, not for full item conversion
        private Document SerializeToDocument(object value, Type type, DynamoDBFlatConfig flatConfig)
        {
            ItemStorageConfig config = StorageConfigCache.GetConfig(type, flatConfig, conversionOnly: true);
            var itemStorage          = ObjectToItemStorageHelper(value, config, flatConfig, keysOnly: false, ignoreNullValues: flatConfig.IgnoreNullValues.Value);
            var doc = itemStorage.Document;

            return(doc);
        }
示例#4
0
        private Task <T> LoadHelperAsync <T>(T keyObject, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken)
        {
            DynamoDBFlatConfig flatConfig    = new DynamoDBFlatConfig(operationConfig, this.Config);
            ItemStorageConfig  storageConfig = StorageConfigCache.GetConfig <T>(flatConfig);
            Key key = MakeKey <T>(keyObject, storageConfig, flatConfig);

            return(LoadHelperAsync <T>(key, flatConfig, storageConfig, cancellationToken));
        }
示例#5
0
        private T LoadHelper <T>(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig)
        {
            DynamoDBFlatConfig flatConfig    = new DynamoDBFlatConfig(operationConfig, this.Config);
            ItemStorageConfig  storageConfig = StorageConfigCache.GetConfig <T>(flatConfig);
            Key key = MakeKey(hashKey, rangeKey, storageConfig, flatConfig);

            return(LoadHelper <T>(key, flatConfig, storageConfig));
        }
示例#6
0
        private T LoadHelper <T>(T keyObject, DynamoDBOperationConfig operationConfig, bool isAsync)
        {
            DynamoDBFlatConfig flatConfig    = new DynamoDBFlatConfig(operationConfig, this.Config);
            ItemStorageConfig  storageConfig = StorageConfigCache.GetConfig <T>(flatConfig);
            Key key = MakeKey <T>(keyObject, storageConfig, flatConfig);

            return(LoadHelper <T>(key, flatConfig, storageConfig, isAsync));
        }
示例#7
0
        private ContextSearch ConvertQueryByValue <T>(object hashKeyValue, QueryOperator op, IEnumerable <object> values, DynamoDBOperationConfig operationConfig)
        {
            DynamoDBFlatConfig    flatConfig    = new DynamoDBFlatConfig(operationConfig, Config);
            ItemStorageConfig     storageConfig = StorageConfigCache.GetConfig <T>(flatConfig);
            List <QueryCondition> conditions    = CreateQueryConditions(flatConfig, op, values, storageConfig);
            ContextSearch         query         = ConvertQueryByValue <T>(hashKeyValue, conditions, operationConfig, storageConfig);

            return(query);
        }
        internal Table GetTargetTableInternal <T>(DynamoDBOperationConfig operationConfig)
        {
            Type type = typeof(T);
            DynamoDBFlatConfig flatConfig    = new DynamoDBFlatConfig(operationConfig, this.Config);
            ItemStorageConfig  storageConfig = StorageConfigCache.GetConfig(type, flatConfig);
            Table table = GetTargetTable(storageConfig, flatConfig);

            return(table);
        }
示例#9
0
        internal Table GetTargetTableInternal <T>(DynamoDBOperationConfig operationConfig)
        {
            Type type = typeof(T);
            DynamoDBFlatConfig flatConfig    = new DynamoDBFlatConfig(operationConfig, this.Config);
            ItemStorageConfig  storageConfig = StorageConfigCache.GetConfig(type, flatConfig);
            Table table = GetTargetTable(storageConfig, flatConfig);

            //Table copy = table.Copy(Table.DynamoDBConsumer.DocumentModel);
            return(table);
        }
示例#10
0
        private Task DeleteHelperAsync <T>(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken)
        {
            DynamoDBFlatConfig config        = new DynamoDBFlatConfig(operationConfig, this.Config);
            ItemStorageConfig  storageConfig = StorageConfigCache.GetConfig <T>(config);
            Key key = MakeKey(hashKey, rangeKey, storageConfig, config);

            Table table = GetTargetTable(storageConfig, config);

            return(table.DeleteHelperAsync(key, null, cancellationToken));
        }
示例#11
0
        private void DeleteHelper <T>(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig, bool isAsync)
        {
            DynamoDBFlatConfig config        = new DynamoDBFlatConfig(operationConfig, this.Config);
            ItemStorageConfig  storageConfig = StorageConfigCache.GetConfig <T>(config);
            Key key = MakeKey(hashKey, rangeKey, storageConfig, config);

            Table table = GetTargetTable(storageConfig, config);

            table.DeleteHelper(key, null, isAsync);
        }
示例#12
0
        internal T FromDocumentHelper <T>(Document document, DynamoDBFlatConfig flatConfig)
        {
            ItemStorageConfig storageConfig = StorageConfigCache.GetConfig <T>(flatConfig);
            ItemStorage       storage       = new ItemStorage(storageConfig);

            storage.Document = document;
            T instance = DocumentToObject <T>(storage, flatConfig);

            return(instance);
        }
示例#13
0
        // Deserializes a given Document to instance of targetType
        // Use only for property conversions, not for full item conversion
        private object DeserializeFromDocument(Document document, Type targetType, DynamoDBFlatConfig flatConfig)
        {
            ItemStorageConfig storageConfig = StorageConfigCache.GetConfig(targetType, flatConfig, conversionOnly: true);
            ItemStorage       storage       = new ItemStorage(storageConfig);

            storage.Document = document;
            object value = DocumentToObject(targetType, storage, flatConfig);

            return(value);
        }
示例#14
0
        private ContextSearch ConvertQueryByValue <T>(object hashKeyValue, IEnumerable <QueryCondition> conditions, DynamoDBOperationConfig operationConfig, ItemStorageConfig storageConfig = null)
        {
            DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig(operationConfig, Config);

            if (storageConfig == null)
            {
                storageConfig = StorageConfigCache.GetConfig <T>(flatConfig);
            }

            List <string> indexNames;
            QueryFilter   filter = ComposeQueryFilter(flatConfig, hashKeyValue, conditions, storageConfig, out indexNames);

            return(ConvertQueryHelper <T>(flatConfig, storageConfig, filter, indexNames));
        }
示例#15
0
 /// <summary>
 /// Implements the Dispose pattern
 /// </summary>
 /// <param name="disposing">Whether this object is being disposed via a call to Dispose
 /// or garbage collected.</param>
 protected virtual void Dispose(bool disposing)
 {
     if (!this.disposed)
     {
         if (disposing && Client != null)
         {
             if (ownClient)
             {
                 StorageConfigCache.Dispose();
                 Client.Dispose();
             }
             Client = null;
         }
         this.disposed = true;
     }
 }
示例#16
0
        private ContextSearch ConvertScan <T>(IEnumerable <ScanCondition> conditions, DynamoDBOperationConfig operationConfig)
        {
            DynamoDBFlatConfig flatConfig    = new DynamoDBFlatConfig(operationConfig, this.Config);
            ItemStorageConfig  storageConfig = StorageConfigCache.GetConfig <T>(flatConfig);
            ScanFilter         filter        = ComposeScanFilter(conditions, storageConfig, flatConfig);

            Table table      = GetTargetTable(storageConfig, flatConfig);
            var   scanConfig = new ScanOperationConfig
            {
                AttributesToGet     = storageConfig.AttributesToGet,
                Select              = SelectValues.SpecificAttributes,
                Filter              = filter,
                ConditionalOperator = flatConfig.ConditionalOperator
            };
            Search scan = table.Scan(scanConfig);

            return(new ContextSearch(scan, flatConfig));
        }
示例#17
0
        // Serializing an object into a DynamoDB document
        private ItemStorage ObjectToItemStorage <T>(T toStore, bool keysOnly, DynamoDBFlatConfig flatConfig)
        {
            if (toStore == null)
            {
                return(null);
            }

            Type objectType = typeof(T);

            ItemStorageConfig config = StorageConfigCache.GetConfig(objectType, flatConfig);

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

            ItemStorage storage = ObjectToItemStorage <T>(toStore, keysOnly, flatConfig.IgnoreNullValues.Value, config);

            return(storage);
        }