public async Task <IEnumerable <TResult> > LoadStartingWithAsync <TTransformer, TResult>(string keyPrefix, string matches = null, int start = 0, int pageSize = 25, string exclude = null, RavenPagingInformation pagingInformation = null, Action <ILoadConfiguration> configure = null, string skipAfter = null, CancellationToken token = new CancellationToken()) where TTransformer : AbstractTransformerCreationTask, new() { IncrementRequestCount(); var transformer = new TTransformer().TransformerName; var configuration = new RavenLoadConfiguration(); configure?.Invoke(configuration); var loadStartingWithOperation = new LoadStartingWithOperation(this); loadStartingWithOperation.WithStartWith(keyPrefix, matches, start, pageSize, exclude, pagingInformation, configure, skipAfter); loadStartingWithOperation.WithTransformer(transformer, configuration.TransformerParameters); var command = loadStartingWithOperation.CreateRequest(); if (command != null) { await RequestExecuter.ExecuteAsync(command, Context, token); } return(loadStartingWithOperation.GetTransformedDocuments <TResult>(command?.Result)); }
public async Task <T[]> LoadUsingTransformerInternalAsync <T>(string[] ids, KeyValuePair <string, Type>[] includes, string transformer, Dictionary <string, object> transformerParameters = null, CancellationToken token = default(CancellationToken)) { if (transformer == null) { throw new ArgumentNullException("transformer"); } if (ids.Length == 0) { return(new T[0]); } var loadTransformerOeration = new LoadTransformerOperation(this); loadTransformerOeration.ByIds(ids); loadTransformerOeration.WithTransformer(transformer, transformerParameters); loadTransformerOeration.WithIncludes(includes?.Select(x => x.Key).ToArray()); var command = loadTransformerOeration.CreateRequest(); if (command != null) { await RequestExecuter.ExecuteAsync(command, Context, token); loadTransformerOeration.SetResult(command.Result); } return(loadTransformerOeration.GetTransformedDocuments <T>(command?.Result)); }
private async Task <IAsyncEnumerator <StreamResult <T> > > StreamAsync <T>(long?fromEtag, string startsWith, string matches, int start, int pageSize, RavenPagingInformation pagingInformation = null, string skipAfter = null, string transformer = null, Dictionary <string, object> transformerParameters = null, CancellationToken token = default(CancellationToken)) { var streamOperation = new StreamOperation(this); var command = streamOperation.CreateRequest(fromEtag, startsWith, matches, start, pageSize, null, pagingInformation, skipAfter, transformer, transformerParameters); await RequestExecuter.ExecuteAsync(command, Context, token).ConfigureAwait(false); var result = streamOperation.SetResultAsync(command.Result); return(new YieldStream <T>(this, result, token)); }
public async Task <IAsyncEnumerator <StreamResult <T> > > StreamAsync <T>(IAsyncDocumentQuery <T> query, CancellationToken token = default(CancellationToken)) { var streamOperation = new StreamOperation(this); var command = streamOperation.CreateRequest((IRavenQueryInspector)query); await RequestExecuter.ExecuteAsync(command, Context, token).ConfigureAwait(false); var result = streamOperation.SetResultAsync(command.Result); var queryOperation = ((AsyncDocumentQuery <T>)query).InitializeQueryOperation(); queryOperation.DisableEntitiesTracking = true; return(new YieldStream <T>(this, result, token)); }
/// <summary> /// Begins the async save changes operation /// </summary> /// <returns></returns> public async Task SaveChangesAsync(CancellationToken token = default(CancellationToken)) { await asyncDocumentKeyGeneration.GenerateDocumentKeysForSaveChanges().WithCancellation(token).ConfigureAwait(false); var saveChangesOeration = new BatchOperation(this); var command = saveChangesOeration.CreateRequest(); if (command != null) { await RequestExecuter.ExecuteAsync(command, Context, token); saveChangesOeration.SetResult(command.Result); } }
/// <summary> /// Begins the async load operation /// </summary> /// <param name="id">The id.</param> /// <param name="token">The canecllation token.</param> /// <returns></returns> public async Task <T> LoadAsync <T>(string id, CancellationToken token = default(CancellationToken)) { var loadOeration = new LoadOperation(this); loadOeration.ById(id); var command = loadOeration.CreateRequest(); if (command != null) { await RequestExecuter.ExecuteAsync(command, Context, token); loadOeration.SetResult(command.Result); } return(loadOeration.GetDocument <T>()); }
public async Task <Operation> DeleteByIndexAsync <T>(string indexName, Expression <Func <T, bool> > expression) { var query = Query <T>(indexName).Where(expression); var indexQuery = new IndexQuery() { Query = query.ToString() }; var deleteByIndexOperation = new DeleteByIndexOperation(); var command = deleteByIndexOperation.CreateRequest(indexName, indexQuery, new QueryOperationOptions(), (DocumentStore)this.DocumentStore); if (command != null) { await RequestExecuter.ExecuteAsync(command, Context); return(new Operation(command.Result.OperationId)); } return(null); }
public async Task RefreshAsync <T>(T entity, CancellationToken token = default(CancellationToken)) { DocumentInfo documentInfo; if (DocumentsByEntity.TryGetValue(entity, out documentInfo) == false) { throw new InvalidOperationException("Cannot refresh a transient instance"); } IncrementRequestCount(); var command = new GetDocumentCommand { Ids = new[] { documentInfo.Id }, Context = this.Context }; await RequestExecuter.ExecuteAsync(command, Context, token); RefreshInternal(entity, command, documentInfo); }
public async Task <T[]> LoadAsyncInternal <T>(string[] ids, KeyValuePair <string, Type>[] includes, CancellationToken token = new CancellationToken()) { var loadOeration = new LoadOperation(this); loadOeration.ByIds(ids); loadOeration.WithIncludes(includes?.Select(x => x.Key).ToArray()); var command = loadOeration.CreateRequest(); if (command != null) { await RequestExecuter.ExecuteAsync(command, Context, token); loadOeration.SetResult(command.Result); } return(loadOeration.GetDocuments <T>()); }
private async Task <Stream> ConnectToServer(RequestExecuter requestExecuter) { var command = new GetTcpInfoCommand(); JsonOperationContext context; using (requestExecuter.ContextPool.AllocateOperationContext(out context)) { await requestExecuter.ExecuteAsync(command, context).ConfigureAwait(false); } var uri = new Uri(command.Result.Url); await _tcpClient.ConnectAsync(uri.Host, uri.Port).ConfigureAwait(false); _tcpClient.NoDelay = true; _tcpClient.SendBufferSize = 32 * 1024; _tcpClient.ReceiveBufferSize = 4096; var networkStream = _tcpClient.GetStream(); return(networkStream); }
public async Task <IEnumerable <T> > LoadStartingWithAsync <T>(string keyPrefix, string matches = null, int start = 0, int pageSize = 25, string exclude = null, RavenPagingInformation pagingInformation = null, string skipAfter = null, CancellationToken token = default(CancellationToken)) { IncrementRequestCount(); var loadStartingWithOperation = new LoadStartingWithOperation(this); loadStartingWithOperation.WithStartWith(keyPrefix, matches, start, pageSize, exclude, pagingInformation, skipAfter: skipAfter); var command = loadStartingWithOperation.CreateRequest(); if (command != null) { await RequestExecuter.ExecuteAsync(command, Context, token); loadStartingWithOperation.SetResult(command.Result); } return(loadStartingWithOperation.GetDocuments <T>()); }