示例#1
0
        public async Task InsertOrUpdate(string tableName, TableEntityModel entity)
        {
            CloudTable table = await this.GetTable(tableName);

            var dataEntity = new DynamicTableEntity(entity.PartitionKey, entity.RowKey, null, entity.EntityProperties);
            await table.ExecuteAsync(TableOperation.InsertOrReplace(dataEntity));
        }
示例#2
0
        public async Task <TableEntityModelCollection> List(string tableName, string partitionKey, int segmentCount = 20, string tokenStr = null, string filter = null)
        {
            CloudTable table = await this.GetTable(tableName);

            var query = new TableQuery <DynamicTableEntity>()
                        .Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey));

            if (filter != null)
            {
                query.Where(filter);
            }

            query.TakeCount = segmentCount;

            TableContinuationToken token = null;

            if (!string.IsNullOrWhiteSpace(tokenStr))
            {
                token = new TableContinuationToken();
                using (var reader = new StringReader(tokenStr))
                {
                    token.ReadXml(XmlReader.Create(reader));
                }
            }

            TableQuerySegment <DynamicTableEntity> result = await table.ExecuteQuerySegmentedAsync <DynamicTableEntity>(query, token);

            var resultCollection = new TableEntityModelCollection();

            if (result.ContinuationToken != null)
            {
                StringBuilder sb = new StringBuilder();
                using (var xmlWriter = XmlWriter.Create(sb))
                {
                    result.ContinuationToken.WriteXml(xmlWriter);
                }

                resultCollection.ContinuationToken = sb.ToString();
            }

            foreach (var item in result.Results)
            {
                var entity = new TableEntityModel()
                {
                    PartitionKey     = item.PartitionKey,
                    RowKey           = item.RowKey,
                    EntityProperties = item.Properties
                };

                resultCollection.Entities.Add(entity);
            }

            return(resultCollection);
        }
示例#3
0
        public async Task <TableEntityModel> Get(string tableName, string partitionKey, string rowKey)
        {
            CloudTable table = await this.GetTable(tableName);

            TableResult result = await table.ExecuteAsync(TableOperation.Retrieve(partitionKey, rowKey));

            var data  = result.Result as DynamicTableEntity;
            var model = new TableEntityModel();

            model.PartitionKey     = data.PartitionKey;
            model.RowKey           = data.RowKey;
            model.EntityProperties = data.Properties;
            return(model);
        }