コード例 #1
0
        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);
            });
        }