private EntityResolver <MinMaxItemRecord> GetMinMaxItemRecordResolver() { return((partKey, rowKey, timestamp, propertySegment, etag) => { var rec = new MinMaxItemRecord(); try { rec.PartitionKey = partKey; rec.RowKey = rowKey; rec.Timestamp = timestamp.Date; rec.ETag = etag; if (propertySegment.ContainsKey("MinItemId")) { rec.MinItemId = propertySegment.FirstOrDefault(ps => ps.Key == "MinItemId").Value.Int32Value.GetValueOrDefault(0); } if (propertySegment.ContainsKey("MaxItemId")) { rec.MaxItemId = propertySegment.FirstOrDefault(ps => ps.Key == "MaxItemId").Value.Int32Value.GetValueOrDefault(0); } } catch (Exception e) { Log.Error().Exception(e).Message("Failed to create Min Max Item Record resolver.").Write(); throw; } return rec; }); }
public void UpdateRecordStats() { // Save off max item identifier by Type in separate table. // Create the resolver first. var resolver = GetItemRecordResolver(); // Declare types that we will create a record for. var types = new[] { "job", "story", "comment", "poll", "pollopt" }; foreach (var type in types) { var filter = TableQuery.GenerateFilterCondition("Type", QueryComparisons.Equal, type); var query = new TableQuery(); query.FilterString = filter; var getAllTask = _adapter.GetAll(_tableName, query, resolver); getAllTask.Wait(); var itemRecordsForType = getAllTask.Result; if (itemRecordsForType.Any()) { var minMaxRecord = new MinMaxItemRecord() { PartitionKey = type, RowKey = "0", MinItemId = itemRecordsForType.Min(i => Convert.ToInt32(i.RowKey)), MaxItemId = itemRecordsForType.Max(i => Convert.ToInt32(i.RowKey)), SnapShotRecordCount = Convert.ToInt32(itemRecordsForType.Count) }; _adapter.Save(minMaxRecord, _minMaxRecordTableName, minMaxRecord.PartitionKey, minMaxRecord.RowKey); } } }