public FluentResults.Result <string> QueryWithVars(string queryString, Dictionary <string, string> varMap) { AssertNotDisposed(); if (transactionState != TransactionState.OK) { return(Results.Fail <string>(new TransactionFinished(transactionState.ToString()))); } try { Api.Request request = new Api.Request(); request.Query = queryString; request.Vars.Add(varMap); request.StartTs = context.StartTs; request.LinRead = context.LinRead; lastQueryResponse = client.Query(request); var err = MergeContext(lastQueryResponse.Txn); if (err.IsSuccess) { return(Results.Ok <string>(lastQueryResponse.Json.ToStringUtf8())); } else { return(err.ConvertToResultWithValueType <string>()); } } catch (RpcException rpcEx) { return(Results.Fail <string>(new FluentResults.ExceptionalError(rpcEx))); } }
public async Task <FluentResults.Result <string> > QueryWithVars(string queryString, Dictionary <string, string> varMap) { AssertNotDisposed(); if (TransactionState != TransactionState.OK) { return(Results.Fail <string>(new TransactionFinished(TransactionState.ToString()))); } try { Api.Request request = new Api.Request(); request.Query = queryString; request.Vars.Add(varMap); request.StartTs = Context.StartTs; var queryResponse = await Client.Query(request); var err = MergeContext(queryResponse.Txn); if (err.IsSuccess) { return(Results.Ok <string>(queryResponse.Json.ToStringUtf8())); } else { return(err.ToResult <string>()); } } catch (RpcException rpcEx) { return(Results.Fail <string>(new FluentResults.ExceptionalError(rpcEx))); } }
public async Task <FluentResults.Result <Response> > QueryWithVars( string queryString, Dictionary <string, string> varMap, CallOptions?options = null ) { AssertNotDisposed(); if (TransactionState != TransactionState.OK) { return(Results.Fail <Response>( new TransactionNotOK(TransactionState.ToString()))); } try { Api.Request request = new Api.Request(); request.Query = queryString; request.Vars.Add(varMap); request.StartTs = Context.StartTs; request.Hash = Context.Hash; request.ReadOnly = ReadOnly; request.BestEffort = BestEffort; var response = await Client.DgraphExecute( async (dg) => Results.Ok <Response>( new Response(await dg.QueryAsync( request, options ?? new CallOptions(null, null, default(CancellationToken))) )), (rpcEx) => Results.Fail <Response>(new FluentResults.ExceptionalError(rpcEx)) ); if (response.IsFailed) { return(response); } var err = MergeContext(response.Value.DgraphResponse.Txn); if (err.IsSuccess) { return(response); } else { return(err.ToResult <Response>()); } } catch (Exception ex) { return(Results.Fail <Response>(new FluentResults.ExceptionalError(ex))); } }
internal async Task <FluentResults.Result <IDictionary <string, string> > > Mutate(Api.Mutation mutation) { AssertNotDisposed(); if (TransactionState != TransactionState.OK) { return(Results.Fail <IDictionary <string, string> >(new TransactionFinished(TransactionState.ToString()))); } if (mutation.Del.Count == 0 && mutation.DeleteJson.Length == 0 && mutation.Set.Count == 0 && mutation.SetJson.Length == 0) { return(Results.Ok <IDictionary <string, string> >(new Dictionary <string, string>())); } HasMutated = true; try { Api.Request req = new Api.Request(); req.Mutations.Add(mutation); req.StartTs = Context.StartTs; var response = await Client.Mutate(req); if (mutation.CommitNow) { TransactionState = TransactionState.Committed; } var err = MergeContext(response.Txn); if (err.IsFailed) { return(err.ToResult <IDictionary <string, string> >()); } return(Results.Ok <IDictionary <string, string> >(response.Uids)); } catch (RpcException rpcEx) { // From Dgraph code txn.go // // Since a mutation error occurred, the txn should no longer be used // (some mutations could have applied but not others, but we don't know // which ones). Discarding the transaction enforces that the user // cannot use the txn further. await Discard(); // Ignore error - user should see the original error. TransactionState = TransactionState.Error; // overwrite the aborted value return(Results.Fail <IDictionary <string, string> >(new FluentResults.ExceptionalError(rpcEx))); } }
public override void Start(CancellationToken token) { try { base.Start(token); using (var abort = token.Register(Thread.CurrentThread.Abort)) { while (true) { var command = Console.ReadLine(); var message = new Request(Sender, command); Manager.Process(this, message); } } } catch (ThreadAbortException) { //It is OK. } finally { Finish(); } }
internal Response Query(Api.Request req) { AssertNotDisposed(); return(connections.Values.ElementAt(rnd.Next(connections.Count)).Query(req)); }
public async Task <Response> Query(Api.Request req) { AssertNotDisposed(); return(await connections[GetNextConnection()].Query(req)); }
public async Task <Response> Query(Api.Request req) { AssertNotDisposed(); return(await connection.QueryAsync(req)); }
public async Task <Response> Mutate(Api.Request mut) { AssertNotDisposed(); return(await connection.QueryAsync(mut)); }
public Response Query(Api.Request req) { AssertNotDisposed(); return(connection.Query(req)); }
public override void Process(Request request, Response response) { base.Process(request, response); Console.WriteLine(response.Info); }
public async Task <Response> Mutate(Api.Request mut) { AssertNotDisposed(); return(await connections[GetNextConnection()].Mutate(mut)); }
/// <summary> /// Process the response. /// </summary> /// <param name="request">Initial request.</param> /// <param name="response">Processed response.</param> /// <summary>It will not be called, if response is null or empty</summary> public virtual void Process(Request request, Response response) { }