Пример #1
0
        public static ResourceTableEntity GetResourceTableEntity(this IAzureStorageTableConfigProvider tableConfigProvider,
                                                                 string tableName,
                                                                 string partitionKey,
                                                                 string rowKey,
                                                                 DateTimeOffset?timestamp = null,
                                                                 IDictionary <string, EntityProperty> properties = null,
                                                                 string etag = null)
        {
            var entity = new ResourceTableEntity(tableConfigProvider.GetPartitionKeyFieldName(tableName),
                                                 tableConfigProvider.GetRowKeyFieldName(tableName),
                                                 tableConfigProvider.GetResourceFieldName(tableName))
            {
                PartitionKey = partitionKey,
                RowKey       = rowKey
            };


            if (timestamp.HasValue)
            {
                entity.Timestamp = timestamp.Value;
            }
            if (etag != null)
            {
                entity.ETag = etag;
            }
            if (properties != null)
            {
                entity.ReadEntity(properties, null);
            }

            return(entity);
        }
Пример #2
0
        public static async Task <dynamic> ExecuteRetrieveAsync(this CloudTable table,
                                                                IAzureStorageTableConfigProvider tableConfigProvider,
                                                                string partitionKey,
                                                                string rowKey)
        {
            var result =
                await table.ExecuteAsync(
                    TableOperation.Retrieve(partitionKey,
                                            rowKey,
                                            (pKey, rKey, timestamp, properties, etag) =>
                                            new ResourceTableEntity(pKey, rKey, timestamp, properties, etag)));

            return((result.Result as ResourceTableEntity)?.Resource);
        }
 /// <summary>
 /// Instantiates a <see cref="TableStorageRepository"/>
 /// </summary>
 /// <param name="logger"></param>
 /// <param name="tableConfigProvider"></param>
 /// <param name="options"></param>
 public TableStorageRepository(ILogger logger, IAzureStorageTableConfigProvider tableConfigProvider, IOptions <TableStorageOptions> options)
 {
     Logger = logger;
     TableConfigProvider = tableConfigProvider;
     TableClient         = (options?.Value ?? new TableStorageOptions()).CreateTableClient();
 }
Пример #4
0
        public static async Task <IEnumerable <dynamic> > ExecuteQueryAsync(this CloudTable table, IAzureStorageTableConfigProvider tableConfigProvider, TableQuery query)
        {
            var results = new List <dynamic>();

            TableContinuationToken continuationToken = null;

            do
            {
                // execute query and resolve results to ResourceTableEntity objects
                var result =
                    await table.ExecuteQuerySegmentedAsync(
                        query,
                        (partitionKey, rowKey, timestamp, properties, etag) => new ResourceTableEntity(partitionKey, rowKey, timestamp, properties, etag),
                        continuationToken);

                // add resource docs to results
                results.AddRange(result.Results.Select(e => e.Resource));

                continuationToken = result.ContinuationToken;
            }while (continuationToken != null);

            return(results);
        }