Esempio n. 1
0
        private static MapValue TruncateParameters(MapValue parameters)
        {
            string[]   keys   = new string[parameters.Size()];
            AnyValue[] values = new AnyValue[keys.Length];

            int i = 0;

            foreach (string key in parameters.Keys)
            {
                keys[i]   = key.Length <= _maxParameterKeyLength ? key : key.Substring(0, _maxParameterKeyLength);
                values[i] = parameters.Get(key).map(_valueTruncater);
                i++;
            }

            return(VirtualValues.map(keys, values));
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void read(org.neo4j.bolt.messaging.BoltResponseMessageWriter messageWriter) throws java.io.IOException
        public virtual void Read(BoltResponseMessageWriter messageWriter)
        {
            try
            {
                _unpacker.unpackStructHeader();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int signature = (int) unpacker.unpackStructSignature();
                int signature = ( int )_unpacker.unpackStructSignature();
                BoltResponseMessage message = BoltResponseMessage.withSignature(signature);
                try
                {
                    switch (message.innerEnumValue)
                    {
                    case Org.Neo4j.Bolt.v1.messaging.BoltResponseMessage.InnerEnum.SUCCESS:
                        MapValue successMetadata = _unpacker.unpackMap();
                        messageWriter.Write(new SuccessMessage(successMetadata));
                        break;

                    case Org.Neo4j.Bolt.v1.messaging.BoltResponseMessage.InnerEnum.RECORD:
                        long length = _unpacker.unpackListHeader();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.values.AnyValue[] fields = new org.neo4j.values.AnyValue[(int) length];
                        AnyValue[] fields = new AnyValue[( int )length];
                        for (int i = 0; i < length; i++)
                        {
                            fields[i] = _unpacker.unpack();
                        }
                        messageWriter.Write(new RecordMessage(record(fields)));
                        break;

                    case Org.Neo4j.Bolt.v1.messaging.BoltResponseMessage.InnerEnum.IGNORED:
                        messageWriter.Write(IgnoredMessage.IGNORED_MESSAGE);
                        break;

                    case Org.Neo4j.Bolt.v1.messaging.BoltResponseMessage.InnerEnum.FAILURE:
                        MapValue failureMetadata = _unpacker.unpackMap();
                        string   code            = failureMetadata.ContainsKey("code") ? (( StringValue )failureMetadata.Get("code")).stringValue() : Org.Neo4j.Kernel.Api.Exceptions.Status_General.UnknownError.name();
                        string   msg             = failureMetadata.ContainsKey("message") ? (( StringValue )failureMetadata.Get("message")).stringValue() : "<No message supplied>";
                        messageWriter.Write(new FailureMessage(Neo4jError.codeFromString(code), msg));
                        break;

                    default:
                        throw new BoltIOException(Org.Neo4j.Kernel.Api.Exceptions.Status_Request.InvalidFormat, string.Format("Message 0x{0} is not supported.", signature.ToString("x")));
                    }
                }
                catch (System.ArgumentException)
                {
                    throw new BoltIOException(Org.Neo4j.Kernel.Api.Exceptions.Status_Request.InvalidFormat, string.Format("Message 0x{0} is not a valid message signature.", signature.ToString("x")));
                }
            }
            catch (PackStream.PackStreamException e)
            {
                throw new BoltIOException(Org.Neo4j.Kernel.Api.Exceptions.Status_Request.InvalidFormat, string.Format("Unable to read message type. Error was: {0}.", e.Message), e);
            }
        }