コード例 #1
0
        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)));
            }
        }
コード例 #2
0
ファイル: Transaction.cs プロジェクト: wangwe/Dgraph-dotnet
        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)));
            }
        }
コード例 #3
0
        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)));
            }
        }
コード例 #4
0
        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)));
            }
        }
コード例 #5
0
ファイル: TerminalAdapter.cs プロジェクト: zaitsevyan/Theseus
        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();
            }
        }
コード例 #6
0
        internal Response Query(Api.Request req)
        {
            AssertNotDisposed();

            return(connections.Values.ElementAt(rnd.Next(connections.Count)).Query(req));
        }
コード例 #7
0
        public async Task <Response> Query(Api.Request req)
        {
            AssertNotDisposed();

            return(await connections[GetNextConnection()].Query(req));
        }
コード例 #8
0
        public async Task <Response> Query(Api.Request req)
        {
            AssertNotDisposed();

            return(await connection.QueryAsync(req));
        }
コード例 #9
0
        public async Task <Response> Mutate(Api.Request mut)
        {
            AssertNotDisposed();

            return(await connection.QueryAsync(mut));
        }
コード例 #10
0
ファイル: Connection.cs プロジェクト: jefer94/Dgraph-dotnet
        public Response Query(Api.Request req)
        {
            AssertNotDisposed();

            return(connection.Query(req));
        }
コード例 #11
0
ファイル: TerminalAdapter.cs プロジェクト: zaitsevyan/Theseus
 public override void Process(Request request, Response response)
 {
     base.Process(request, response);
     Console.WriteLine(response.Info);
 }
コード例 #12
0
        public async Task <Response> Mutate(Api.Request mut)
        {
            AssertNotDisposed();

            return(await connections[GetNextConnection()].Mutate(mut));
        }
コード例 #13
0
ファイル: Adapter.cs プロジェクト: zaitsevyan/Theseus
 /// <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)
 {
 }