public static void ExportData(ExportSpec exportSpec) { using (var streamWriter = new StreamWriter(new GZipStream(File.Create(exportSpec.File), CompressionMode.Compress))) { var jsonWriter = new JsonTextWriter(streamWriter) { Formatting = Formatting.Indented }; jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("Indexes"); jsonWriter.WriteStartArray(); using (var webClient = new WebClient()) { webClient.UseDefaultCredentials = true; webClient.Credentials = CredentialCache.DefaultNetworkCredentials; int totalCount = 0; while (true) { var documents = GetString(webClient.DownloadData(exportSpec.InstanceUrl + "indexes?pageSize=128&start=" + totalCount)); var array = RavenJArray.Parse(documents); if (array.Length == 0) { Console.WriteLine("Done with reading indexes, total: {0}", totalCount); break; } totalCount += array.Length; Console.WriteLine("Reading batch of {0,3} indexes, read so far: {1,10:#,#}", array.Length, totalCount); foreach (RavenJToken item in array) { item.WriteTo(jsonWriter); } } } jsonWriter.WriteEndArray(); jsonWriter.WritePropertyName("Docs"); jsonWriter.WriteStartArray(); if (!exportSpec.ExportIndexesOnly) { ExportDocuments(exportSpec, jsonWriter); } jsonWriter.WriteEndArray(); jsonWriter.WritePropertyName("Attachments"); jsonWriter.WriteStartArray(); if (exportSpec.IncludeAttachments) { ExportAttachments(jsonWriter, exportSpec); } jsonWriter.WriteEndArray(); jsonWriter.WriteEndObject(); streamWriter.Flush(); } }
private static void ExportDocuments(ExportSpec exportSpec, JsonTextWriter jsonWriter) { using (var webClient = new WebClient()) { webClient.UseDefaultCredentials = true; webClient.Credentials = CredentialCache.DefaultNetworkCredentials; var lastEtag = Guid.Empty; int totalCount = 0; while (true) { var documents = GetString(webClient.DownloadData(exportSpec.InstanceUrl + "docs?pageSize=128&etag=" + lastEtag)); var array = RavenJArray.Parse(documents); if (array.Length == 0) { Console.WriteLine("Done with reading documents, total: {0}", totalCount); break; } totalCount += array.Length; Console.WriteLine("Reading batch of {0,3} documents, read so far: {1,10:#,#;;0}", array.Length, totalCount); foreach (RavenJToken item in array) { item.WriteTo(jsonWriter); } lastEtag = new Guid(array.Last().Value <RavenJObject>("@metadata").Value <string>("@etag")); } } }
public static void ExportData(ExportSpec exportSpec) { using (var streamWriter = new StreamWriter(new GZipStream(File.Create(exportSpec.File), CompressionMode.Compress))) { var jsonWriter = new JsonTextWriter(streamWriter) { Formatting = Formatting.Indented }; jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("Indexes"); jsonWriter.WriteStartArray(); using (var webClient = new WebClient()) { webClient.UseDefaultCredentials = true; webClient.Credentials = CredentialCache.DefaultNetworkCredentials; int totalCount = 0; while (true) { var documents = GetString(webClient.DownloadData(exportSpec.InstanceUrl + "indexes?pageSize=128&start=" + totalCount)); var array = RavenJArray.Parse(documents); if (array.Length == 0) { Console.WriteLine("Done with reading indexes, total: {0}", totalCount); break; } totalCount += array.Length; Console.WriteLine("Reading batch of {0,3} indexes, read so far: {1,10:#,#;;0}", array.Length, totalCount); foreach (RavenJToken item in array) { item.WriteTo(jsonWriter); } } } jsonWriter.WriteEndArray(); jsonWriter.WritePropertyName("Docs"); jsonWriter.WriteStartArray(); if (!exportSpec.ExportIndexesOnly) { ExportDocuments(exportSpec, jsonWriter); } jsonWriter.WriteEndArray(); jsonWriter.WritePropertyName("Attachments"); jsonWriter.WriteStartArray(); if (exportSpec.IncludeAttachments) { ExportAttachments(jsonWriter, exportSpec); } jsonWriter.WriteEndArray(); jsonWriter.WriteEndObject(); streamWriter.Flush(); } }
static void ExportAttachments(JsonTextWriter jsonWriter, ExportSpec exportSpec) { using (var webClient = new WebClient()) { webClient.UseDefaultCredentials = true; webClient.Credentials = CredentialCache.DefaultNetworkCredentials; var lastEtag = Guid.Empty; int totalCount = 0; while (true) { var attachmentInfo = GetString(webClient.DownloadData(exportSpec.InstanceUrl + "/static/?pageSize=128&etag=" + lastEtag)); var array = RavenJArray.Parse(attachmentInfo); if (array.Length == 0) { Console.WriteLine("Done with reading attachments, total: {0}", totalCount); break; } totalCount += array.Length; Console.WriteLine("Reading batch of {0,3} attachments, read so far: {1,10:#,#;;0}", array.Length, totalCount); foreach (var item in array) { Console.WriteLine("Downloading attachment: {0}", item.Value <string>("Key")); var attachmentData = webClient.DownloadData(exportSpec.InstanceUrl + "/static/" + item.Value <string>("Key")); new RavenJObject { { "Data", attachmentData }, { "Metadata", item.Value <RavenJObject>("Metadata") }, { "Key", item.Value <string>("Key") } } .WriteTo(jsonWriter); } lastEtag = new Guid(array.Last().Value <string>("Etag")); } } }
static void ExportAttachments(JsonTextWriter jsonWriter, ExportSpec exportSpec) { using (var webClient = new WebClient()) { webClient.UseDefaultCredentials = true; webClient.Credentials = CredentialCache.DefaultNetworkCredentials; var lastEtag = Guid.Empty; int totalCount = 0; while (true) { var attachmentInfo = GetString(webClient.DownloadData(exportSpec.InstanceUrl + "/static/?pageSize=128&etag=" + lastEtag)); var array = RavenJArray.Parse(attachmentInfo); if (array.Length == 0) { Console.WriteLine("Done with reading attachments, total: {0}", totalCount); break; } totalCount += array.Length; Console.WriteLine("Reading batch of {0,3} attachments, read so far: {1,10:#,#}", array.Length, totalCount); foreach (var item in array) { Console.WriteLine("Downloading attachment: {0}", item.Value<string>("Key")); var attachmentData = webClient.DownloadData(exportSpec.InstanceUrl + "/static/" + item.Value<string>("Key")); new RavenJObject { {"Data", attachmentData}, {"Metadata", item.Value<RavenJObject>("Metadata")}, {"Key", item.Value<string>("Key")} } .WriteTo(jsonWriter); } lastEtag = new Guid(array.Last().Value<string>("Etag")); } } }
private static void ExportDocuments(ExportSpec exportSpec, JsonTextWriter jsonWriter) { using (var webClient = new WebClient()) { webClient.UseDefaultCredentials = true; webClient.Credentials = CredentialCache.DefaultNetworkCredentials; var lastEtag = Guid.Empty; int totalCount = 0; while (true) { var documents = GetString(webClient.DownloadData(exportSpec.InstanceUrl + "docs?pageSize=128&etag=" + lastEtag)); var array = RavenJArray.Parse(documents); if (array.Length == 0) { Console.WriteLine("Done with reading documents, total: {0}", totalCount); break; } totalCount += array.Length; Console.WriteLine("Reading batch of {0,3} documents, read so far: {1,10:#,#}", array.Length, totalCount); foreach (RavenJToken item in array) { item.WriteTo(jsonWriter); } lastEtag = new Guid(array.Last().Value<RavenJObject>("@metadata").Value<string>("@etag")); } } }