private void ExportDocuments(SmugglerOptions options, JsonTextWriter jsonWriter) { var lastEtag = Guid.Empty; int totalCount = 0; while (true) { RavenJArray documents = null; var request = CreateRequest("/docs?pageSize=128&etag=" + lastEtag); request.ExecuteRequest(reader => documents = RavenJArray.Load(new JsonTextReader(reader))); if (documents.Length == 0) { Console.WriteLine("Done with reading documents, total: {0}", totalCount); break; } var final = documents.Where(options.MatchFilters).ToList(); final.ForEach(item => item.WriteTo(jsonWriter)); totalCount += final.Count; Console.WriteLine("Reading batch of {0,3} documents, read so far: {1,10:#,#;;0}", documents.Length, totalCount); lastEtag = new Guid(documents.Last().Value <RavenJObject>("@metadata").Value <string>("@etag")); } }
protected override async Task <Etag> ExportAttachments(JsonTextWriter jsonWriter, Etag lastEtag, Etag maxEtag) { if (maxEtag != null) { throw new ArgumentException("We don't support maxEtag in SmugglerApi", "maxEtag"); } int totalCount = 0; while (true) { RavenJArray attachmentInfo = null; await commands.CreateRequest("/static/?pageSize=" + SmugglerOptions.BatchSize + "&etag=" + lastEtag, "GET") .ReadResponseJsonAsync() .ContinueWith(task => attachmentInfo = (RavenJArray)task.Result); if (attachmentInfo.Length == 0) { var databaseStatistics = await GetStats(); var lastEtagComparable = new ComparableByteArray(lastEtag); if (lastEtagComparable.CompareTo(databaseStatistics.LastAttachmentEtag) < 0) { lastEtag = EtagUtil.Increment(lastEtag, SmugglerOptions.BatchSize); ShowProgress("Got no results but didn't get to the last attachment etag, trying from: {0}", lastEtag); continue; } ShowProgress("Done with reading attachments, total: {0}", totalCount); return(lastEtag); } totalCount += attachmentInfo.Length; ShowProgress("Reading batch of {0,3} attachments, read so far: {1,10:#,#;;0}", attachmentInfo.Length, totalCount); foreach (var item in attachmentInfo) { ShowProgress("Downloading attachment: {0}", item.Value <string>("Key")); byte[] attachmentData = null; await commands.CreateRequest("/static/" + item.Value <string>("Key"), "GET") .ReadResponseBytesAsync() .ContinueWith(task => attachmentData = task.Result); new RavenJObject { { "Data", attachmentData }, { "Metadata", item.Value <RavenJObject>("Metadata") }, { "Key", item.Value <string>("Key") } } .WriteTo(jsonWriter); } lastEtag = Etag.Parse(attachmentInfo.Last().Value <string>("Etag")); } }
protected override async Task <Etag> ExportAttachments(JsonTextWriter jsonWriter, Etag lastEtag) { int totalCount = 0; while (true) { RavenJArray attachmentInfo = null; var request = CreateRequest("/static/?pageSize=" + SmugglerOptions.BatchSize + "&etag=" + lastEtag); request.ExecuteRequest(reader => attachmentInfo = RavenJArray.Load(new JsonTextReader(reader))); if (attachmentInfo.Length == 0) { var databaseStatistics = await GetStats(); var lastEtagComparable = new ComparableByteArray(lastEtag); if (lastEtagComparable.CompareTo(databaseStatistics.LastAttachmentEtag) < 0) { lastEtag = EtagUtil.Increment(lastEtag, SmugglerOptions.BatchSize); ShowProgress("Got no results but didn't get to the last attachment etag, trying from: {0}", lastEtag); continue; } ShowProgress("Done with reading attachments, total: {0}", totalCount); return(lastEtag); } totalCount += attachmentInfo.Length; ShowProgress("Reading batch of {0,3} attachments, read so far: {1,10:#,#;;0}", attachmentInfo.Length, totalCount); foreach (var item in attachmentInfo) { ShowProgress("Downloading attachment: {0}", item.Value <string>("Key")); byte[] attachmentData = null; var requestData = CreateRequest("/static/" + item.Value <string>("Key")); requestData.ExecuteRequest(reader => attachmentData = reader.ReadData()); new RavenJObject { { "Data", attachmentData }, { "Metadata", item.Value <RavenJObject>("Metadata") }, { "Key", item.Value <string>("Key") } } .WriteTo(jsonWriter); } lastEtag = Etag.Parse(attachmentInfo.Last().Value <string>("Etag")); } }
private void ExportAttachments(JsonTextWriter jsonWriter) { var lastEtag = Guid.Empty; int totalCount = 0; while (true) { RavenJArray attachmentInfo = null; var request = CreateRequest("/static/?pageSize=128&etag=" + lastEtag); request.ExecuteRequest(reader => attachmentInfo = RavenJArray.Load(new JsonTextReader(reader))); if (attachmentInfo.Length == 0) { Console.WriteLine("Done with reading attachments, total: {0}", totalCount); break; } totalCount += attachmentInfo.Length; Console.WriteLine("Reading batch of {0,3} attachments, read so far: {1,10:#,#;;0}", attachmentInfo.Length, totalCount); foreach (var item in attachmentInfo) { Console.WriteLine("Downloading attachment: {0}", item.Value <string>("Key")); byte[] attachmentData = null; var requestData = CreateRequest("/static/" + item.Value <string>("Key")); requestData.ExecuteRequest(reader => attachmentData = reader.ReadData()); new RavenJObject { { "Data", attachmentData }, { "Metadata", item.Value <RavenJObject>("Metadata") }, { "Key", item.Value <string>("Key") } } .WriteTo(jsonWriter); } lastEtag = new Guid(attachmentInfo.Last().Value <string>("Etag")); } }
protected override Guid ExportAttachments(JsonTextWriter jsonWriter, Guid lastEtag) { int totalCount = 0; while (true) { RavenJArray attachmentInfo = null; var request = CreateRequest("/static/?pageSize=" + smugglerOptions.BatchSize + "&etag=" + lastEtag); request.ExecuteRequest(reader => attachmentInfo = RavenJArray.Load(new JsonTextReader(reader))); if (attachmentInfo.Length == 0) { ShowProgress("Done with reading attachments, total: {0}", totalCount); return(lastEtag); } totalCount += attachmentInfo.Length; ShowProgress("Reading batch of {0,3} attachments, read so far: {1,10:#,#;;0}", attachmentInfo.Length, totalCount); foreach (var item in attachmentInfo) { ShowProgress("Downloading attachment: {0}", item.Value <string>("Key")); byte[] attachmentData = null; var requestData = CreateRequest("/static/" + item.Value <string>("Key")); requestData.ExecuteRequest(reader => attachmentData = reader.ReadData()); new RavenJObject { { "Data", attachmentData }, { "Metadata", item.Value <RavenJObject>("Metadata") }, { "Key", item.Value <string>("Key") } } .WriteTo(jsonWriter); } lastEtag = new Guid(attachmentInfo.Last().Value <string>("Etag")); } }