Пример #1
0
        public async Task <ODataResponse> GetResponseAsync(IODataResponseMessageAsync responseMessage, bool includeResourceTypeInEntryProperties = false)
#endif
        {
            var readerSettings = new ODataMessageReaderSettings();

            readerSettings.MessageQuotas.MaxReceivedMessageSize = Int32.MaxValue;
            using (var messageReader = new ODataMessageReader(responseMessage, readerSettings, _model))
            {
                var payloadKind = messageReader.DetectPayloadKind();
                if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Error))
                {
                    return(ODataResponse.FromStatusCode(responseMessage.StatusCode));
                }
                else if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Value))
                {
                    if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Collection))
                    {
                        throw new NotImplementedException();
                    }
                    else
                    {
#if SILVERLIGHT
                        var text = Utils.StreamToString(responseMessage.GetStream());
#else
                        var text = Client.Utils.StreamToString(await responseMessage.GetStreamAsync());
#endif
                        return(ODataResponse.FromFeed(new[] { new Dictionary <string, object>()
                                                              {
                                                                  { FluentCommand.ResultLiteral, text }
                                                              } }));
                    }
                }
                else if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Batch))
                {
                    return(await ReadResponse(messageReader.CreateODataBatchReader(), includeResourceTypeInEntryProperties));
                }
                else if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Feed))
                {
                    return(ReadResponse(messageReader.CreateODataFeedReader(), includeResourceTypeInEntryProperties));
                }
                else if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Collection))
                {
                    return(ReadResponse(messageReader.CreateODataCollectionReader(), includeResourceTypeInEntryProperties));
                }
                else if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Property))
                {
                    var property = messageReader.ReadProperty();
                    return(ODataResponse.FromFeed(new[] { new Dictionary <string, object>()
                                                          {
                                                              { property.Name ?? FluentCommand.ResultLiteral, GetPropertyValue(property.Value) }
                                                          } }));
                }
                else
                {
                    return(ReadResponse(messageReader.CreateODataEntryReader(), includeResourceTypeInEntryProperties));
                }
            }
        }
        public async Task <ODataResponse> GetResponseAsync(IODataResponseMessageAsync responseMessage)
#endif
        {
            var readerSettings = new ODataMessageReaderSettings();

            readerSettings.MessageQuotas.MaxReceivedMessageSize = Int32.MaxValue;
            using (var messageReader = new ODataMessageReader(responseMessage, readerSettings, _model))
            {
                var payloadKind = messageReader.DetectPayloadKind();
                if (payloadKind.Any(x => x.PayloadKind != ODataPayloadKind.Property))
                {
                    _hasResponse = true;
                }

                if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Error))
                {
                    return(ODataResponse.FromStatusCode(responseMessage.StatusCode));
                }
                else if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Value))
                {
                    if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Collection))
                    {
                        throw new NotImplementedException();
                    }
                    else
                    {
#if SILVERLIGHT
                        var stream = responseMessage.GetStream();
#else
                        var stream = await responseMessage.GetStreamAsync();
#endif
                        return(ODataResponse.FromValueStream(stream, responseMessage is ODataBatchOperationResponseMessage));
                    }
                }
                else if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Batch))
                {
                    return(await ReadResponse(messageReader.CreateODataBatchReader()));
                }
                else if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Feed))
                {
                    return(ReadResponse(messageReader.CreateODataFeedReader()));
                }
                else if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Collection))
                {
                    return(ReadResponse(messageReader.CreateODataCollectionReader()));
                }
                else if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Property))
                {
                    var property = messageReader.ReadProperty();
                    if (property.Value != null && (property.Value.GetType() != typeof(string) || !string.IsNullOrEmpty(property.Value.ToString())))
                    {
                        _hasResponse = true;
                    }

                    if (_hasResponse)
                    {
                        return(ODataResponse.FromProperty(property.Name, GetPropertyValue(property.Value)));
                    }
                    else
                    {
                        return(ODataResponse.EmptyFeed);
                    }
                }
                else
                {
                    return(ReadResponse(messageReader.CreateODataEntryReader()));
                }
            }
        }
        public async Task<ODataResponse> GetResponseAsync(IODataResponseMessageAsync responseMessage)
#endif
        {
            var readerSettings = new ODataMessageReaderSettings();
            readerSettings.MessageQuotas.MaxReceivedMessageSize = Int32.MaxValue;
            using (var messageReader = new ODataMessageReader(responseMessage, readerSettings, _model))
            {
                var payloadKind = messageReader.DetectPayloadKind();
                if (payloadKind.Any(x => x.PayloadKind != ODataPayloadKind.Property))
                    _hasResponse = true;

                if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Error))
                {
                    return ODataResponse.FromStatusCode(responseMessage.StatusCode);
                }
                else if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Value))
                {
                    if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Collection))
                    {
                        throw new NotImplementedException();
                    }
                    else
                    {
#if SILVERLIGHT
                        var stream = responseMessage.GetStream();
#else
                        var stream = await responseMessage.GetStreamAsync();
#endif
                        return ODataResponse.FromValueStream(stream);
                    }
                }
                else if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Batch))
                {
                    return await ReadResponse(messageReader.CreateODataBatchReader());
                }
                else if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Feed))
                {
                    return ReadResponse(messageReader.CreateODataFeedReader());
                }
                else if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Collection))
                {
                    return ReadResponse(messageReader.CreateODataCollectionReader());
                }
                else if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Property))
                {
                    var property = messageReader.ReadProperty();
                    if (property.Value != null && (property.Value.GetType() != typeof(string) || !string.IsNullOrEmpty(property.Value.ToString())))
                        _hasResponse = true;

                    if (_hasResponse)
                    {
                        return ODataResponse.FromProperty(property.Name, GetPropertyValue(property.Value));
                    }
                    else
                    {
                        return ODataResponse.EmptyFeed;
                    }
                }
                else
                {
                    return ReadResponse(messageReader.CreateODataEntryReader());
                }
            }
        }
        public async Task<ODataResponse> GetResponseAsync(IODataResponseMessageAsync responseMessage, bool includeResourceTypeInEntryProperties = false)
#endif
        {
            var readerSettings = new ODataMessageReaderSettings();
            readerSettings.MessageQuotas.MaxReceivedMessageSize = Int32.MaxValue;
            using (var messageReader = new ODataMessageReader(responseMessage, readerSettings, _model))
            {
                var payloadKind = messageReader.DetectPayloadKind();
                if (payloadKind.Any(x => x.PayloadKind != ODataPayloadKind.Property))
                    _hasResponse = true;

                if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Error))
                {
                    return ODataResponse.FromStatusCode(responseMessage.StatusCode);
                }
                else if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Value))
                {
                    if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Collection))
                    {
                        throw new NotImplementedException();
                    }
                    else
                    {
#if SILVERLIGHT
                        var text = Utils.StreamToString(responseMessage.GetStream());
#else
                        var text = Client.Utils.StreamToString(await responseMessage.GetStreamAsync());
#endif
                        return ODataResponse.FromFeed(new[] { new Dictionary<string, object>()
                        {
                            { FluentCommand.ResultLiteral, text }
                        } });
                    }
                }
                else if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Batch))
                {
                    return await ReadResponse(messageReader.CreateODataBatchReader(), includeResourceTypeInEntryProperties);
                }
                else if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Feed))
                {
                    return ReadResponse(messageReader.CreateODataFeedReader(), includeResourceTypeInEntryProperties);
                }
                else if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Collection))
                {
                    return ReadResponse(messageReader.CreateODataCollectionReader(), includeResourceTypeInEntryProperties);
                }
                else if (payloadKind.Any(x => x.PayloadKind == ODataPayloadKind.Property))
                {
                    var property = messageReader.ReadProperty();
                    if (property.Value != null && (property.Value.GetType() != typeof (string) || !string.IsNullOrEmpty(property.Value.ToString())))
                        _hasResponse = true;

                    if (_hasResponse)
                    {
                        return ODataResponse.FromFeed(new[] { new Dictionary<string, object>()
                        {
                            { property.Name ?? FluentCommand.ResultLiteral, GetPropertyValue(property.Value) }
                        } });
                    }
                    else
                    {
                        return ODataResponse.FromFeed(new Dictionary<string, object>[] {});
                    }
                }
                else
                {
                    return ReadResponse(messageReader.CreateODataEntryReader(), includeResourceTypeInEntryProperties);
                }
            }
        }