private async Task DumpCollection(Uri collection, IReliableServiceQuery proxy, JsonTextWriter jsonWriter) { Log($"Dumping collection {collection}"); var collectionData = await proxy.GetCollectionData(collection); jsonWriter.WriteStartArray(); foreach (var item in collectionData) { using (var reader = new JsonTextReader(new StringReader(item))) { jsonWriter.WriteToken(reader); } } jsonWriter.WriteEndArray(); }
private async Task DumpPartition(Uri serviceName, Guid partitionId, IReliableServiceQuery proxy) { Log($"Dumping partition {serviceName}/{partitionId}"); var collections = await proxy.GetCollections(); if (collections.Count == 0) return; using (var fileStream = new FileStream(GetFileName(serviceName, partitionId), FileMode.Create)) using (var streamWriter = new StreamWriter(fileStream)) using (var jsonWriter = new JsonTextWriter(streamWriter)) { jsonWriter.Formatting = Formatting.Indented; jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("serviceName"); jsonWriter.WriteValue(serviceName.ToString()); jsonWriter.WritePropertyName("partitionId"); jsonWriter.WriteValue(partitionId.ToString()); jsonWriter.WritePropertyName("collections"); jsonWriter.WriteStartArray(); foreach (var collection in collections) { jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("name"); jsonWriter.WriteValue(collection.ToString()); jsonWriter.WritePropertyName("values"); try { await DumpCollection(collection, proxy, jsonWriter); } catch (Exception e) { Log($"Error dumping collection on partition {serviceName}/{partitionId}: {e.Message}"); } jsonWriter.WriteEndObject(); } jsonWriter.WriteEndArray(); jsonWriter.WriteEndObject(); } }