public RemoteBulkInsertOperation(BulkInsertOptions options, ServerClient client) { this.client = client; items = new BlockingCollection<RavenJObject>(options.BatchSize*8); string requestUrl = "/bulkInsert?"; if (options.CheckForUpdates) requestUrl += "checkForUpdates=true"; if (options.CheckReferencesInIndexes) requestUrl += "&checkReferencesInIndexes=true"; // this will force the HTTP layer to authenticate, meaning that our next request won't have to HttpJsonRequest req = client.CreateRequest("POST", requestUrl + "&no-op=for-auth-only", disableRequestCompression: true); req.ExecuteRequest(); httpJsonRequest = client.CreateRequest("POST", requestUrl, disableRequestCompression: true); // the request may take a long time to process, so we need to set a large timeout value httpJsonRequest.Timeout = TimeSpan.FromHours(6); nextTask = httpJsonRequest.GetRawRequestStream() .ContinueWith(task => { Stream requestStream = task.Result; while (true) { var batch = new List<RavenJObject>(); RavenJObject item; while (items.TryTake(out item, 200)) { if (item == null) // marker { FlushBatch(requestStream, batch); return; } batch.Add(item); if (batch.Count >= options.BatchSize) break; } FlushBatch(requestStream, batch); } }); }
public RemoteBulkInsertOperation(BulkInsertOptions options, ServerClient client) { this.options = options; this.client = client; items = new BlockingCollection<RavenJObject>(options.BatchSize*8); string requestUrl = "/bulkInsert?"; if (options.CheckForUpdates) requestUrl += "checkForUpdates=true"; if (options.CheckReferencesInIndexes) requestUrl += "&checkReferencesInIndexes=true"; var expect100Continue = client.Expect100Continue(); // this will force the HTTP layer to authenticate, meaning that our next request won't have to HttpJsonRequest req = client.CreateRequest("POST", requestUrl + "&op=generate-single-use-auth-token", disableRequestCompression: true); var token = req.ReadResponseJson(); httpJsonRequest = client.CreateRequest("POST", requestUrl, disableRequestCompression: true); // the request may take a long time to process, so we need to set a large timeout value httpJsonRequest.PrepareForLongRequest(); httpJsonRequest.AddOperationHeader("Single-Use-Auth-Token", token.Value<string>("Token")); nextTask = httpJsonRequest.GetRawRequestStream() .ContinueWith(task => { try { expect100Continue.Dispose(); } catch (Exception) { } WriteQueueToServer(task); }); }