public T[] LoadInternal <T>(string[] ids, KeyValuePair <string, Type>[] includes, string transformer, Dictionary <string, object> transformerParameters = null) { 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) { RequestExecuter.Execute(command, Context); loadTransformerOeration.SetResult(command.Result); } return(loadTransformerOeration.GetTransformedDocuments <T>(command?.Result)); }
public Client(IHttpClientFactory clientFactory, IRequestGenerator requestGenerator, Options options) { _options = options; IRequestExecuter requestExecuter = new RequestExecuter( clientFactory.CreateHttpClient(new HttpClientOptions { AddTokenToRequests = true, TokenRetriever = () => _options.AccessToken, ReadRequestsPerSecond = options.ReadRequestsPerSecond, WriteRequestsPerSecond = options.WriteRequestsPerSecond, }), clientFactory.CreateHttpClient(new HttpClientOptions())); if (options.AutoRetry) { requestExecuter = new AutoRetryRequestExecuter(requestExecuter) { NumberOfRetries = options.NumberOfRetries }; } RequestGenerator = requestGenerator; Core = new Core(requestExecuter, requestGenerator.Core, options); Business = new Business(requestExecuter, requestGenerator, options); }
public TResult[] LoadStartingWith <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) 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) { RequestExecuter.Execute(command, Context); } return(loadStartingWithOperation.GetTransformedDocuments <TResult>(command?.Result)); }
public Business(RequestExecuter requestExecuter, IRequestGenerator requestGenerator, Options options) { Info = new Info(requestExecuter, requestGenerator.Business.TeamInfo, options); Members = new Members(requestExecuter, requestGenerator.Business.TeamMembers, options); Reports = new Reports(requestExecuter, requestGenerator.Business.Reports, options); AuditLog = new AuditLog(requestExecuter, requestGenerator.Business.AuditLog, options); }
public Core(RequestExecuter requestExecuter, ICoreRequestGenerator requestGenerator, Options options) { OAuth2 = new OAuth2(requestExecuter, requestGenerator.OAuth2, options); Accounts = new Accounts(requestExecuter, requestGenerator.Accounts); Metadata = new Metadata(requestExecuter, requestGenerator.Metadata, options); FileOperations = new FileOperations(requestExecuter, requestGenerator.FileOperations, options); }
/// <summary> /// Gets the document URL for the specified entity. /// </summary> /// <param name="entity">The entity.</param> /// <returns></returns> public string GetDocumentUrl(object entity) { DocumentInfo document; if (DocumentsByEntity.TryGetValue(entity, out document) == false) { throw new InvalidOperationException("Could not figure out identifier for transient instance"); } return(RequestExecuter.UrlFor(document.Id)); }
/// <summary> /// Saves all the changes to the Raven server. /// </summary> public void SaveChanges() { var saveChangesOperation = new BatchOperation(this); var command = saveChangesOperation.CreateRequest(); if (command != null) { RequestExecuter.Execute(command, Context); saveChangesOperation.SetResult(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); } }
public T[] LoadInternal <T>(string[] ids) { var loadOeration = new LoadOperation(this); loadOeration.ByIds(ids); var command = loadOeration.CreateRequest(); if (command != null) { RequestExecuter.Execute(command, Context); loadOeration.SetResult(command.Result); } return(loadOeration.GetDocuments <T>()); }
private bool HasEtagInDatabaseDocumentResponse(string url, string databaseName, JsonOperationContext context) { var command = new GetDatabaseDocumentTestCommand(); using (var requestExecuter = new RequestExecuter(url, databaseName, null)) { requestExecuter.Execute(command, context); } var result = command.Result; BlittableJsonReaderObject metadata; var hasMetadataProperty = result.TryGet("@metadata", out metadata); long etag; var hasEtagProperty = metadata.TryGet("@etag", out etag); return(hasMetadataProperty && hasEtagProperty && etag > 0); }
public IEnumerator <StreamResult <T> > Stream <T>(IDocumentQuery <T> query) { var streamOperation = new StreamOperation(this); var command = streamOperation.CreateRequest((IRavenQueryInspector)query); RequestExecuter.Execute(command, Context); using (var result = streamOperation.SetResult(command.Result)) { while (result.MoveNext()) { var res = result.Current; var stremResult = CreateStreamResult <T>(res); yield return(stremResult); } } }
/// <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 T[] LoadInternal <T>(string[] ids, KeyValuePair <string, Type>[] includes) { var loadOeration = new LoadOperation(this); loadOeration.ByIds(ids); loadOeration.WithIncludes(includes?.Select(x => x.Key).ToArray()); var command = loadOeration.CreateRequest(); if (command != null) { RequestExecuter.Execute(command, Context); loadOeration.SetResult(command.Result); } return(loadOeration.GetDocuments <T>()); }
private IEnumerator <StreamResult <T> > Stream <T>(long?fromEtag, string startsWith, string matches, int start, int pageSize, RavenPagingInformation pagingInformation, string skipAfter, string transformer, Dictionary <string, object> transformerParameters) { var streamOperation = new StreamOperation(this); var command = streamOperation.CreateRequest(fromEtag, startsWith, matches, start, pageSize, null, pagingInformation, skipAfter, transformer, transformerParameters); RequestExecuter.Execute(command, Context); using (var result = streamOperation.SetResult(command.Result)) { while (result.MoveNext()) { var res = result.Current; var stremResult = CreateStreamResult <T>(res); yield return(stremResult); } } }
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>()); }
public T[] LoadStartingWith <T>(string keyPrefix, string matches = null, int start = 0, int pageSize = 25, string exclude = null, RavenPagingInformation pagingInformation = null, string skipAfter = null) { IncrementRequestCount(); var loadStartingWithOperation = new LoadStartingWithOperation(this); loadStartingWithOperation.WithStartWith(keyPrefix, matches, start, pageSize, exclude, pagingInformation, skipAfter: skipAfter); var command = loadStartingWithOperation.CreateRequest(); if (command != null) { RequestExecuter.Execute(command, Context); loadStartingWithOperation.SetResult(command.Result); } return(loadStartingWithOperation.GetDocuments <T>()); }
public Operation DeleteByIndex <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) { RequestExecuter.Execute(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); }
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); }
/// <summary> /// Refreshes the specified entity from Raven server. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entity">The entity.</param> public void Refresh <T>(T entity) { 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 }; RequestExecuter.Execute(command, Context); RefreshInternal(entity, command, documentInfo); }
/// <summary> /// Loads the specified entity with the specified id. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="id">The id.</param> /// <returns></returns> public T Load <T>(string id) { if (id == null) { return(default(T)); } var loadOeration = new LoadOperation(this); loadOeration.ById(id); var command = loadOeration.CreateRequest(); if (command != null) { RequestExecuter.Execute(command, Context); loadOeration.SetResult(command.Result); } return(loadOeration.GetDocument <T>()); }
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>()); }
public TcpBulkInsertOperation(string database, IDocumentStore store, RequestExecuter requestExecuter, CancellationTokenSource cts) { _throttlingEvent.Set(); _jsonOperationContext = new JsonOperationContext(1024 * 1024, 16 * 1024); _cts = cts ?? new CancellationTokenSource(); _tcpClient = new TcpClient(); _store = store; _entityToBlittable = new EntityToBlittable(null); var connectToServerTask = ConnectToServer(requestExecuter); _sentAccumulator = 0; _getServerResponseTask = connectToServerTask.ContinueWith(task => { ReadServerResponses(task.Result); }); _writeToServerTask = connectToServerTask.ContinueWith(task => { WriteToServer(database, task.Result); }); }
public void Admin_databases_endpoint_should_refuse_document_with_lower_etag_with_concurrency_Exception() { using (var store = GetDocumentStore()) { using (var session = store.OpenSession()) { session.Load <object>("users/1");// just waiting for the db to load } TransactionOperationContext context; using (Server.ServerStore.ContextPool.AllocateOperationContext(out context)) { var getCommand = new GetDatabaseDocumentTestCommand(); using (var requestExecuter = new RequestExecuter(store.Url, store.DefaultDatabase, null)) { requestExecuter.Execute(getCommand, context); var putCommand = new PutDatabaseDocumentTestCommand(getCommand.Result); var exception = Assert.Throws <InternalServerErrorException>(() => requestExecuter.Execute(putCommand, context)); Assert.Contains("ConcurrencyException", exception.Message); } } } }
public Reports(RequestExecuter requestExecuter, IReportsRequestGenerator requestGenerator, Options options) { _requestGenerator = requestGenerator; _options = options; _requestExecuter = requestExecuter; }
public Members(RequestExecuter requestExecuter, ITeamMembersRequestGenerator requestGenerator, Options options) { _requestGenerator = requestGenerator; _options = options; _requestExecuter = requestExecuter; }
public Info(RequestExecuter requestExecuter, ITeamInfoRequestGenerator requestGenerator, Options options) { _requestGenerator = requestGenerator; _options = options; _requestExecuter = requestExecuter; }
public Metadata(RequestExecuter requestExecuter, IMetadataRequestGenerator requestGenerator, Options options) { _requestExecuter = requestExecuter; _requestGenerator = requestGenerator; _options = options; }
/// <summary> /// Initializes a new instance of the <see cref="DocumentSession"/> class. /// </summary> public DocumentSession(string dbName, DocumentStore documentStore, Guid id, RequestExecuter requestExecuter) : base(dbName, documentStore, requestExecuter, id) { }