public GetRequest CreateRequest(JsonOperationContext ctx) { var queryBuilder = new StringBuilder("?"); _includes.ApplyIfNotNull(include => queryBuilder.AppendFormat("&include={0}", include)); bool hasItems = false; foreach (var id in _ids) { if (_session.IsLoadedOrDeleted(id)) { _alreadyInSession.Add(id); } else { hasItems = true; queryBuilder.AppendFormat("&id={0}", Uri.EscapeDataString(id)); } } if (hasItems == false) { // no need to hit the server Result = _loadOperation.GetDocuments <T>(); return(null); } return(new GetRequest { Url = "/docs", Query = queryBuilder.ToString() }); }
/// <summary> /// Loads the specified entities with the specified ids. /// </summary> /// <param name="ids">The ids.</param> public Dictionary <string, T> Load <T>(IEnumerable <string> ids) { var loadOperation = new LoadOperation(this); LoadInternal(ids.ToArray(), loadOperation); return(loadOperation.GetDocuments <T>()); }
private void HandleResponse(GetDocumentResult loadResult) { _loadOperation.SetResult(loadResult); if (RequiresRetry == false) { Result = _loadOperation.GetDocuments <T>(); } }
public async Task <Dictionary <string, T> > LoadAsync <T>(IEnumerable <string> ids, CancellationToken token = default(CancellationToken)) { var loadOperation = new LoadOperation(this); await LoadAsyncInternal(ids.ToArray(), null, loadOperation, token).ConfigureAwait(false); return(loadOperation.GetDocuments <T>()); }
public GetRequest CreateRequest(JsonOperationContext ctx) { var idsToCheckOnServer = _ids.Where(id => _session.IsLoadedOrDeleted(id) == false); var queryBuilder = new StringBuilder("?"); _includes.ApplyIfNotNull(include => queryBuilder.AppendFormat("&include={0}", include)); var hasItems = idsToCheckOnServer.ApplyIfNotNull(id => queryBuilder.AppendFormat("&id={0}", Uri.EscapeDataString(id))); if (hasItems == false) { // no need to hit the server Result = _loadOperation.GetDocuments <T>(); return(null); } return(new GetRequest { Url = "/docs", Query = queryBuilder.ToString() }); }
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>()); }
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>()); }
public Dictionary <string, T> LoadInternal <T>(string[] ids, string[] includes) { var loadOperation = new LoadOperation(this); loadOperation.ByIds(ids); loadOperation.WithIncludes(includes); var command = loadOperation.CreateRequest(); if (command != null) { RequestExecutor.Execute(command, Context, sessionInfo: SessionInfo); loadOperation.SetResult(command.Result); } return(loadOperation.GetDocuments <T>()); }
public async Task <T[]> LoadAsync <T>(IEnumerable <string> ids, CancellationToken token = default(CancellationToken)) { var loadOeration = new LoadOperation(this); loadOeration.ByIds(ids); var command = loadOeration.CreateRequest(); if (command != null) { await RequestExecuter.ExecuteAsync(command, Context, token); loadOeration.SetResult(command.Result); } return(loadOeration.GetDocuments <T>()); }
public async Task <Dictionary <string, T> > LoadAsyncInternal <T>(string[] ids, string[] includes, CancellationToken token = new CancellationToken()) { var loadOperation = new LoadOperation(this); loadOperation.ByIds(ids); loadOperation.WithIncludes(includes?.ToArray()); var command = loadOperation.CreateRequest(); if (command != null) { await RequestExecutor.ExecuteAsync(command, Context, token, SessionInfo).ConfigureAwait(false); loadOperation.SetResult(command.Result); } return(loadOperation.GetDocuments <T>()); }
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>()); }