Example #1
0
        protected OrientdbResponse <T> StreamToTypedResponse <T>(
            OrientdbResponse <Stream> streamResponse,
            ITransportRequestState requestState,
            byte[] readBytes
            )
        {
            //set response
            if (typeof(T) == typeof(string) || typeof(T) == typeof(byte[]))
            {
                OrientdbResponse <T> clone = OrientdbResponse.CloneFrom(streamResponse, default(T));
                SetStringOrByteResult(clone, readBytes);
                return(clone);
            }
            OrientdbResponse <T> typedResponse = OrientdbResponse.CloneFrom(streamResponse, default(T));

            using (streamResponse.Response)
            {
                Func <IOrientdbResponse, Stream, object> deserializationState = requestState.ResponseCreationOverride;
                var customConverter = deserializationState as Func <IOrientdbResponse, Stream, T>;
                if (customConverter != null)
                {
                    T t = customConverter(typedResponse, streamResponse.Response);
                    typedResponse.Response = t;
                    return(typedResponse);
                }
                var deserialized = _serializer.Deserialize <T>(streamResponse.Response);
                typedResponse.Response = deserialized;
                return(typedResponse);
            }
        }
        protected OrientdbResponse <T> HandleAuthenticationException <T>(TransportRequestState <T> requestState,
                                                                         OrientdbAuthenticationException exception)
        {
            if (requestState.ClientSettings.ThrowOnOrientdbServerExceptions)
            {
                throw exception.ToElasticsearchServerException();
            }

            OrientdbResponse <T> response = OrientdbResponse.CloneFrom(exception.Response, default(T));

            response.Request       = requestState.PostData;
            response.RequestUrl    = requestState.Path;
            response.RequestMethod = requestState.Method;
            return(response);
        }
Example #3
0
        private OrientdbResponse <T> ReturnTypedResponse <T>(
            TransportRequestState <T> requestState,
            OrientdbResponse <Stream> streamResponse,
            out OrientdbServerError error)
        {
            error = null;

            // Read to memory stream if needed
            bool hasResponse = streamResponse.Response != null;
            bool forceRead   = _settings.KeepRawResponse || typeof(T) == typeof(string) || typeof(T) == typeof(byte[]);

            byte[] bytes = null;
            if (hasResponse && forceRead)
            {
                MemoryStream ms = _memoryStreamProvider.New();
                streamResponse.Response.CopyTo(ms);
                bytes = ms.ToArray();
                streamResponse.Response.Close();
                streamResponse.Response          = ms;
                streamResponse.Response.Position = 0;
            }
            // Set rawresponse if needed
            if (_settings.KeepRawResponse)
            {
                streamResponse.ResponseRaw = bytes;
            }

            bool isValidResponse = IsValidResponse(requestState, streamResponse);

            if (isValidResponse)
            {
                return(StreamToTypedResponse <T>(streamResponse, requestState, bytes));
            }

            // If error read error
            error = GetErrorFromStream <T>(streamResponse.Response);
            OrientdbResponse <T> typedResponse = OrientdbResponse.CloneFrom(streamResponse, default(T));

            SetStringOrByteResult(typedResponse, bytes);
            return(typedResponse);
        }
Example #4
0
        private OrientdbResponse <T> ReturnStreamOrVoidResponse <T>(
            TransportRequestState <T> requestState, OrientdbResponse <Stream> streamResponse)
        {
            // If the response never recieved a status code and has a caught exception make sure we throw it
            if (streamResponse.HttpStatusCode.GetValueOrDefault(-1) <= 0 && streamResponse.OriginalException != null)
            {
                throw streamResponse.OriginalException;
            }

            // If the user explicitly wants a stream returned the undisposed stream
            if (typeof(Stream).IsAssignableFrom(typeof(T)))
            {
                return(streamResponse as OrientdbResponse <T>);
            }

            if (!typeof(VoidResponse).IsAssignableFrom(typeof(T)))
            {
                return(null);
            }

            OrientdbResponse <VoidResponse> voidResponse = OrientdbResponse.CloneFrom <VoidResponse>(streamResponse, null);

            return(voidResponse as OrientdbResponse <T>);
        }