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 + "&no-op=for-auth-only", disableRequestCompression: true); req.PrepareForLongRequest(); 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.PrepareForLongRequest(); nextTask = httpJsonRequest.GetRawRequestStream() .ContinueWith(task => { try { expect100Continue.Dispose(); } catch (Exception) { } WriteQueueToServer(task); }); }
private async Task StartBulkInsertAsync(BulkInsertOptions options) { #if !SILVERLIGHT var expect100Continue = operationClient.Expect100Continue(); #endif var operationUrl = CreateOperationUrl(options); var token = await GetToken(operationUrl); try { token = await ValidateThatWeCanUseAuthenticateTokens(operationUrl, token); } catch (Exception e) { throw new InvalidOperationException( "Could not authenticate token for bulk insert, if you are using ravendb in IIS make sure you have Anonymous Authentication enabled in the IIS configuration", e); } operationRequest = CreateOperationRequest(operationUrl, token); var stream = await operationRequest.GetRawRequestStream(); #if !SILVERLIGHT try { if (expect100Continue != null) { expect100Continue.Dispose(); } } catch { } #endif var cancellationToken = CreateCancellationToken(); await Task.Factory.StartNew(() => WriteQueueToServer(stream, options, cancellationToken), TaskCreationOptions.LongRunning); }
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); }); }