示例#1
0
        public dynamic Objectify(JsonElement graphsonObject, GraphSONReader reader)
        {
            var x = reader.ToObject(graphsonObject.GetProperty("x"));
            var y = reader.ToObject(graphsonObject.GetProperty("y"));

            return(new MyType(x, y));
        }
示例#2
0
        public dynamic Objectify(JToken graphsonObject, GraphSONReader reader)
        {
            var x = reader.ToObject(graphsonObject["x"]);
            var y = reader.ToObject(graphsonObject["y"]);

            return(new MyType(x, y));
        }
示例#3
0
        public void HandleReceived(ResponseMessage <JToken> received)
        {
            var receivedData = typeof(T) == typeof(JToken)
                ? new[] { received.Result.Data }
                : _graphSONReader.ToObject(received.Result.Data);

            foreach (var d in receivedData)
            {
                if (received.Result.Meta.ContainsKey(Tokens.ArgsSideEffectKey))
                {
                    if (_aggregator == null)
                    {
                        _aggregator =
                            new AggregatorFactory().GetAggregatorFor(
                                (string)received.Result.Meta[Tokens.ArgsAggregateTo]);
                    }
                    _aggregator.Add(d);
                    _isAggregatingSideEffects = true;
                }
                else
                {
                    _result.Add(d);
                }
            }
        }
示例#4
0
        private async Task <GremlinResponse <T> > ReceiveAsync <T>()
        {
            ResponseStatus status;
            IAggregator    aggregator = null;
            var            isAggregatingSideEffects = false;
            var            result      = new List <T>();
            List <int>     statusCodes = new List <int>();
            List <Dictionary <string, object> > attributes = new List <Dictionary <string, object> >();

            do
            {
                var received = await _webSocketConnection.ReceiveMessageAsync().ConfigureAwait(false);

                var receivedMsg = _messageSerializer.DeserializeMessage <ResponseMessage <JToken> >(received);

                status = receivedMsg.Status;
                status.ThrowIfStatusIndicatesError();

                if (status.Code == ResponseStatusCode.Authenticate)
                {
                    await AuthenticateAsync().ConfigureAwait(false);
                }
                else
                {
                    statusCodes.Add((int)status.Code);
                    attributes.Add(status.Attributes);
                    if (status.Code != ResponseStatusCode.NoContent)
                    {
                        var receivedData = _graphSONReader.ToObject(receivedMsg.Result.Data);
                        foreach (var d in receivedData)
                        {
                            if (receivedMsg.Result.Meta.ContainsKey(Tokens.ArgsSideEffectKey))
                            {
                                if (aggregator == null)
                                {
                                    aggregator =
                                        new AggregatorFactory().GetAggregatorFor(
                                            (string)receivedMsg.Result.Meta[Tokens.ArgsAggregateTo]);
                                }
                                aggregator.Add(d);
                                isAggregatingSideEffects = true;
                            }
                            else
                            {
                                result.Add(d);
                            }
                        }
                    }
                }
            } while (status.Code == ResponseStatusCode.PartialContent || status.Code == ResponseStatusCode.Authenticate);

            List <T> resultsToReturn = isAggregatingSideEffects
                ? new List <T> {
                (T)aggregator.GetAggregatedResult()
            }
                : result;

            return(new GremlinResponse <T>(resultsToReturn, attributes, statusCodes));
        }
        public void HandleReceived(ResponseMessage received)
        {
            var receivedData = typeof(T) == typeof(JsonElement)
                ? new[] { received.Result.Data }
                : _graphSONReader.ToObject(received.Result.Data);

            foreach (var d in receivedData)
            {
                _result.Add(d);
            }
        }
示例#6
0
        private async Task <IReadOnlyCollection <T> > ReceiveAsync <T>()
        {
            ResponseStatus status;
            IAggregator    aggregator = null;
            var            isAggregatingSideEffects = false;
            var            result = new List <T>();

            do
            {
                var received = await _webSocketConnection.ReceiveMessageAsync().ConfigureAwait(false);

                var receivedMsg = _messageSerializer.DeserializeMessage <ResponseMessage <JToken> >(received);

                status = receivedMsg.Status;
                status.ThrowIfStatusIndicatesError();

                if (status.Code == ResponseStatusCode.Authenticate)
                {
                    await AuthenticateAsync().ConfigureAwait(false);
                }
                else if (status.Code != ResponseStatusCode.NoContent)
                {
                    var receivedData = _graphSONReader.ToObject(receivedMsg.Result.Data);
                    foreach (var d in receivedData)
                    {
                        if (receivedMsg.Result.Meta.ContainsKey(Tokens.ArgsSideEffectKey))
                        {
                            if (aggregator == null)
                            {
                                aggregator =
                                    new AggregatorFactory().GetAggregatorFor(
                                        (string)receivedMsg.Result.Meta[Tokens.ArgsAggregateTo]);
                            }
                            aggregator.Add(d);
                            isAggregatingSideEffects = true;
                        }
                        else
                        {
                            result.Add(d);
                        }
                    }
                }
            } while (status.Code == ResponseStatusCode.PartialContent || status.Code == ResponseStatusCode.Authenticate);

            if (isAggregatingSideEffects)
            {
                return new List <T> {
                           (T)aggregator.GetAggregatedResult()
                }
            }
            ;
            return(result);
        }