/// <summary> /// Begins the async batch operation /// </summary> /// <param name="commandDatas">The command data.</param> /// <returns></returns> public Task <BatchResult[]> BatchAsync(ICommandData[] commandDatas) { var metadata = new RavenJObject(); var req = jsonRequestFactory.CreateHttpJsonRequest(this, url + "/bulk_docs", "POST", metadata, credentials, convention); var jArray = new RavenJArray(commandDatas.Select(x => x.ToJson())); return(req.WriteAsync(jArray.ToString(Formatting.None)) .ContinueWith(writeTask => req.ReadResponseStringAsync()) .ContinueWith(task => { string response; try { response = task.Result.Result; } catch (WebException e) { var httpWebResponse = e.Response as HttpWebResponse; if (httpWebResponse == null || httpWebResponse.StatusCode != HttpStatusCode.Conflict) { throw; } throw ThrowConcurrencyException(e); } return JsonConvert.DeserializeObject <BatchResult[]>(response, new JsonToJsonConverter()); })); }
/// <summary> /// Begins the async batch operation /// </summary> /// <param name="commandDatas">The command data.</param> /// <returns></returns> public Task <BatchResult[]> BatchAsync(ICommandData[] commandDatas) { var metadata = new RavenJObject(); AddTransactionInformation(metadata); var req = jsonRequestFactory.CreateHttpJsonRequest(this, url + "/bulk_docs", "POST", metadata, credentials, convention); var jArray = new RavenJArray(commandDatas.Select(x => x.ToJson())); var data = Encoding.UTF8.GetBytes(jArray.ToString(Formatting.None)); return(Task.Factory.FromAsync(req.BeginWrite, req.EndWrite, data, null) .ContinueWith(writeTask => Task.Factory.FromAsync <string>(req.BeginReadResponseString, req.EndReadResponseString, null)) .Unwrap() .ContinueWith(task => { string response; try { response = task.Result; } catch (WebException e) { var httpWebResponse = e.Response as HttpWebResponse; if (httpWebResponse == null || httpWebResponse.StatusCode != HttpStatusCode.Conflict) { throw; } throw ThrowConcurrencyException(e); } return JsonConvert.DeserializeObject <BatchResult[]>(response, new JsonToJsonConverter()); })); }
private BatchResult[] DirectBatch(IEnumerable <ICommandData> commandDatas, string operationUrl) { var metadata = new RavenJObject(); AddTransactionInformation(metadata); var req = jsonRequestFactory.CreateHttpJsonRequest(this, operationUrl + "/bulk_docs", "POST", metadata, credentials, convention); req.AddOperationHeaders(OperationsHeaders); var jArray = new RavenJArray(commandDatas.Select(x => x.ToJson())); req.Write(jArray.ToString(Formatting.None)); string response; try { response = req.ReadResponseString(); } catch (WebException e) { var httpWebResponse = e.Response as HttpWebResponse; if (httpWebResponse == null || httpWebResponse.StatusCode != HttpStatusCode.Conflict) { throw; } throw ThrowConcurrencyException(e); } return(JsonConvert.DeserializeObject <BatchResult[]>(response, Default.Converters)); }
/// <summary> /// Begins the async batch operation /// </summary> /// <param name="commandDatas">The command data.</param> /// <returns></returns> public Task <BatchResult[]> BatchAsync(ICommandData[] commandDatas) { var metadata = new RavenJObject(); AddTransactionInformation(metadata); var req = jsonRequestFactory.CreateHttpJsonRequest(this, url + "/bulk_docs", "POST", metadata, credentials, convention); var jArray = new RavenJArray(commandDatas.Select(x => x.ToJson())); var data = jArray.ToString(Formatting.None); return(Task.Factory.FromAsync(req.BeginWrite, req.EndWrite, data, null) .ContinueWith(writeTask => req.ReadResponseJsonAsync()) .Unwrap() .ContinueWith(task => { RavenJArray response; try { response = (RavenJArray)task.Result; } catch (AggregateException e) { var we = e.ExtractSingleInnerException() as WebException; if (we == null) { throw; } var httpWebResponse = we.Response as HttpWebResponse; if (httpWebResponse == null || httpWebResponse.StatusCode != HttpStatusCode.Conflict) { throw; } throw ThrowConcurrencyException(we); } return convention.CreateSerializer().Deserialize <BatchResult[]>(new RavenJTokenReader(response)); })); }
/// <summary> /// Begins the async batch operation /// </summary> /// <param name="commandDatas">The command data.</param> /// <returns></returns> public Task<BatchResult[]> BatchAsync(ICommandData[] commandDatas) { var metadata = new RavenJObject(); AddTransactionInformation(metadata); var req = jsonRequestFactory.CreateHttpJsonRequest(new CreateHttpJsonRequestParams(this, url + "/bulk_docs", "POST", metadata, credentials, convention)); var jArray = new RavenJArray(commandDatas.Select(x => x.ToJson())); var data = jArray.ToString(Formatting.None); return Task.Factory.FromAsync(req.BeginWrite, req.EndWrite, data, null) .ContinueWith(writeTask => req.ReadResponseJsonAsync()) .Unwrap() .ContinueWith(task => { RavenJArray response; try { response = (RavenJArray)task.Result; } catch (AggregateException e) { var we = e.ExtractSingleInnerException() as WebException; if (we == null) throw; var httpWebResponse = we.Response as HttpWebResponse; if (httpWebResponse == null || httpWebResponse.StatusCode != HttpStatusCode.Conflict) throw; throw ThrowConcurrencyException(we); } return convention.CreateSerializer().Deserialize<BatchResult[]>(new RavenJTokenReader(response)); }); }
/// <summary> /// Begins the async batch operation /// </summary> /// <param name="commandDatas">The command data.</param> /// <returns></returns> public Task<BatchResult[]> BatchAsync(ICommandData[] commandDatas) { var metadata = new RavenJObject(); AddTransactionInformation(metadata); var req = jsonRequestFactory.CreateHttpJsonRequest(this, url + "/bulk_docs", "POST", metadata, credentials, convention); var jArray = new RavenJArray(commandDatas.Select(x => x.ToJson())); var data = jArray.ToString(Formatting.None); return Task.Factory.FromAsync(req.BeginWrite, req.EndWrite, data, null) .ContinueWith(writeTask => req.ReadResponseStringAsync()) .Unwrap() .ContinueWith(task => { string response; try { response = task.Result; } catch (WebException e) { var httpWebResponse = e.Response as HttpWebResponse; if (httpWebResponse == null || httpWebResponse.StatusCode != HttpStatusCode.Conflict) throw; throw ThrowConcurrencyException(e); } return JsonConvert.DeserializeObject<BatchResult[]>(response, new JsonToJsonConverter()); }); }