Exemplo n.º 1
0
        protected override async Task <Stream> WriteStreamContentAsync(Stream stream, bool writeAsText)
        {
            var message = new ODataRequestMessage();

            using (var messageWriter = new ODataMessageWriter(message, GetWriterSettings(ODataFormat.RawValue), _model))
            {
                var value = writeAsText ? (object)Utils.StreamToString(stream) : Utils.StreamToByteArray(stream);
                await messageWriter.WriteValueAsync(value);

                return(await message.GetStreamAsync());
            }
        }
Exemplo n.º 2
0
        public override async Task StartBatchAsync()
        {
            _requestMessage = new ODataRequestMessage()
            {
                Url = _session.Settings.BaseUri
            };
            _messageWriter = new ODataMessageWriter(_requestMessage);
            _batchWriter   = await _messageWriter.CreateODataBatchWriterAsync().ConfigureAwait(false);

            await _batchWriter.WriteStartBatchAsync().ConfigureAwait(false);

            this.HasOperations = true;
        }
Exemplo n.º 3
0
        public override async Task StartBatchAsync()
        {
            _requestMessage = new ODataRequestMessage()
            {
                Url = new Uri(_session.Settings.UrlBase)
            };
            _messageWriter = new ODataMessageWriter(_requestMessage);
#if SILVERLIGHT
            _batchWriter = _messageWriter.CreateODataBatchWriter();
            _batchWriter.WriteStartBatch();
#else
            _batchWriter = await _messageWriter.CreateODataBatchWriterAsync();

            await _batchWriter.WriteStartBatchAsync();
#endif
        }
Exemplo n.º 4
0
#pragma warning disable 1998
        public override async Task StartBatchAsync()
        {
            _requestMessage = new ODataRequestMessage()
            {
                Url = _session.Settings.BaseUri
            };
            _messageWriter = new ODataMessageWriter(_requestMessage);
#if SILVERLIGHT
            _batchWriter = _messageWriter.CreateODataBatchWriter();
            _batchWriter.WriteStartBatch();
#else
            _batchWriter = await _messageWriter.CreateODataBatchWriterAsync();

            await _batchWriter.WriteStartBatchAsync();
#endif
            this.HasOperations = true;
        }
        protected override async Task <Stream> WriteLinkContentAsync(string linkIdent)
        {
            var message = new ODataRequestMessage();

            using (var messageWriter = new ODataMessageWriter(message, GetWriterSettings(), _model))
            {
                var link = new ODataEntityReferenceLink {
                    Url = Utils.CreateAbsoluteUri(_session.Settings.UrlBase, linkIdent)
                };
                messageWriter.WriteEntityReferenceLink(link);

#if SILVERLIGHT
                return(message.GetStream());
#else
                return(await message.GetStreamAsync());
#endif
            }
        }
Exemplo n.º 6
0
        protected override async Task <Stream> WriteActionContentAsync(string actionName, IDictionary <string, object> parameters)
        {
            var message = new ODataRequestMessage();

            using (var messageWriter = new ODataMessageWriter(message, GetWriterSettings(), _model))
            {
                var action = _model.SchemaElements
                             .Where(x => x.SchemaElementKind == EdmSchemaElementKind.EntityContainer)
                             .SelectMany(x => (x as IEdmEntityContainer).FunctionImports())
                             .BestMatch(x => x.Name, actionName, _session.Pluralizer);
                var parameterWriter = messageWriter.CreateODataParameterWriter(action);

                parameterWriter.WriteStart();

                foreach (var parameter in parameters)
                {
                    var actionParameter = action.Parameters.BestMatch(x => x.Name, parameter.Key, _session.Pluralizer);
                    if (actionParameter == null)
                    {
                        throw new UnresolvableObjectException(parameter.Key, string.Format("Parameter [{0}] not found for action [{1}]", parameter.Key, actionName));
                    }

                    if (actionParameter.Type.Definition.TypeKind == EdmTypeKind.Collection)
                    {
                        var collectionWriter = parameterWriter.CreateCollectionWriter(parameter.Key);
                        collectionWriter.WriteStart(new ODataCollectionStart());
                        foreach (var item in parameter.Value as IEnumerable)
                        {
                            collectionWriter.WriteItem(item);
                        }
                        collectionWriter.WriteEnd();
                    }
                    else
                    {
                        parameterWriter.WriteValue(parameter.Key, parameter.Value);
                    }
                }

                parameterWriter.WriteEnd();
                return(await message.GetStreamAsync());
            }
        }
        protected override async Task <Stream> WriteActionContentAsync(string actionName, IDictionary <string, object> parameters)
        {
            var message = new ODataRequestMessage();

            using (var messageWriter = new ODataMessageWriter(message, GetWriterSettings(), _model))
            {
                var action = _model.SchemaElements
                             .Where(x => x.SchemaElementKind == EdmSchemaElementKind.EntityContainer)
                             .SelectMany(x => (x as IEdmEntityContainer).FunctionImports())
                             .BestMatch(x => x.Name, actionName, _session.Pluralizer);
                var parameterWriter = messageWriter.CreateODataParameterWriter(action);

                parameterWriter.WriteStart();

                foreach (var parameter in parameters)
                {
                    if (!(parameter.Value is string) && parameter.Value is IEnumerable)
                    {
                        var collectionWriter = parameterWriter.CreateCollectionWriter(parameter.Key);
                        collectionWriter.WriteStart(new ODataCollectionStart());
                        foreach (var item in parameter.Value as IEnumerable)
                        {
                            collectionWriter.WriteItem(item);
                        }
                        collectionWriter.WriteEnd();
                    }
                    else
                    {
                        parameterWriter.WriteValue(parameter.Key, parameter.Value);
                    }
                }

                parameterWriter.WriteEnd();
                return(await message.GetStreamAsync());
            }
        }