private async Task WriteOperationParameterAsync(ODataParameterWriter parameterWriter, IEdmFunctionParameter operationParameter, string paramName, object paramValue)
        {
            switch (operationParameter.Type.Definition.TypeKind)
            {
            case EdmTypeKind.Primitive:
            case EdmTypeKind.Complex:
                var value = GetPropertyValue(operationParameter.Type, paramValue);
                await parameterWriter.WriteValueAsync(paramName, value).ConfigureAwait(false);

                break;

            case EdmTypeKind.Collection:
                var collectionWriter = await parameterWriter.CreateCollectionWriterAsync(paramName).ConfigureAwait(false);

                await collectionWriter.WriteStartAsync(new ODataCollectionStart()).ConfigureAwait(false);

                foreach (var item in paramValue as IEnumerable)
                {
                    await collectionWriter.WriteItemAsync(item).ConfigureAwait(false);
                }
                await collectionWriter.WriteEndAsync().ConfigureAwait(false);

                break;

            default:
                throw new NotSupportedException(string.Format("Unable to write action parameter of a type {0}", operationParameter.Type.Definition.TypeKind));
            }
        }
示例#2
0
        private async Task WriteOperationParameterAsync(ODataParameterWriter parameterWriter, IEdmFunctionParameter operationParameter, string paramName, object paramValue)
        {
            if (operationParameter.Type.Definition.TypeKind == EdmTypeKind.Collection)
            {
                var collectionWriter = await parameterWriter.CreateCollectionWriterAsync(paramName);

                await collectionWriter.WriteStartAsync(new ODataCollectionStart());

                foreach (var item in paramValue as IEnumerable)
                {
                    await collectionWriter.WriteItemAsync(item);
                }
                await collectionWriter.WriteEndAsync();
            }
            else
            {
                await parameterWriter.WriteValueAsync(paramName, paramValue);
            }
        }
示例#3
0
        private async Task WriteOperationParameterAsync(ODataParameterWriter parameterWriter, IEdmOperationParameter operationParameter, string paramName, object paramValue)
        {
            switch (operationParameter.Type.Definition.TypeKind)
            {
            case EdmTypeKind.Primitive:
                var value = GetPropertyValue(operationParameter.Type, paramValue, null);
                await parameterWriter.WriteValueAsync(paramName, value).ConfigureAwait(false);

                break;

            case EdmTypeKind.Enum:
                await parameterWriter.WriteValueAsync(paramName, new ODataEnumValue(paramValue.ToString())).ConfigureAwait(false);

                break;

            case EdmTypeKind.Untyped:
                await parameterWriter.WriteValueAsync(paramName, new ODataUntypedValue { RawValue = paramValue.ToString() }).ConfigureAwait(false);

                break;

            case EdmTypeKind.Entity:
            {
                var entryWriter = await parameterWriter.CreateResourceWriterAsync(paramName).ConfigureAwait(false);

                var paramValueDict = paramValue.ToDictionary(TypeCache);
                var contentId      = _deferredBatchWriter?.Value.GetContentId(paramValueDict, null);

                var typeName = operationParameter.Type.Definition.FullTypeName();
                if (paramValueDict.ContainsKey("@odata.type") && paramValueDict["@odata.type"] is string)
                {
                    typeName = paramValueDict["@odata.type"] as string;
                    paramValueDict.Remove("@odata.type");
                }

                var entryDetails = _session.Metadata.ParseEntryDetails(typeName, paramValueDict, contentId);
                var entry        = CreateODataEntry(typeName, entryDetails.Properties, null);

                RegisterRootEntry(entry);
                await WriteEntryPropertiesAsync(entryWriter, entry, entryDetails.Links).ConfigureAwait(false);

                UnregisterRootEntry(entry);
            }
            break;

            case EdmTypeKind.Complex:
            {
                var entryWriter = await parameterWriter.CreateResourceWriterAsync(paramName).ConfigureAwait(false);

                var paramValueDict = paramValue.ToDictionary(TypeCache);

                var typeName = operationParameter.Type.Definition.FullTypeName();
                if (paramValueDict.ContainsKey("@odata.type") && paramValueDict["@odata.type"] is string)
                {
                    typeName = paramValueDict["@odata.type"] as string;
                    paramValueDict.Remove("@odata.type");
                }

                var entry = CreateODataEntry(typeName, paramValueDict, null);

                RegisterRootEntry(entry);
                await WriteEntryPropertiesAsync(entryWriter, entry, new Dictionary <string, List <ReferenceLink> >()).ConfigureAwait(false);

                UnregisterRootEntry(entry);
            }
            break;

            case EdmTypeKind.Collection:
                var collectionType = operationParameter.Type.Definition as IEdmCollectionType;
                var elementType    = collectionType.ElementType;
                if (elementType.Definition.TypeKind == EdmTypeKind.Entity)
                {
                    var feedWriter = await parameterWriter.CreateResourceSetWriterAsync(paramName).ConfigureAwait(false);

                    var feed = new ODataResourceSet();
                    await feedWriter.WriteStartAsync(feed).ConfigureAwait(false);

                    foreach (var item in (IEnumerable)paramValue)
                    {
                        var feedEntry = CreateODataEntry(elementType.Definition.FullTypeName(), item.ToDictionary(TypeCache), null);

                        RegisterRootEntry(feedEntry);
                        await feedWriter.WriteStartAsync(feedEntry).ConfigureAwait(false);

                        await feedWriter.WriteEndAsync().ConfigureAwait(false);

                        UnregisterRootEntry(feedEntry);
                    }
                    await feedWriter.WriteEndAsync().ConfigureAwait(false);
                }
                else
                {
                    var collectionWriter = await parameterWriter.CreateCollectionWriterAsync(paramName).ConfigureAwait(false);

                    await collectionWriter.WriteStartAsync(new ODataCollectionStart()).ConfigureAwait(false);

                    foreach (var item in (IEnumerable)paramValue)
                    {
                        await collectionWriter.WriteItemAsync(item).ConfigureAwait(false);
                    }
                    await collectionWriter.WriteEndAsync().ConfigureAwait(false);
                }
                break;

            default:
                throw new NotSupportedException($"Unable to write action parameter of a type {operationParameter.Type.Definition.TypeKind}");
            }
        }
        private async Task WriteOperationParameterAsync(ODataParameterWriter parameterWriter, IEdmOperationParameter operationParameter, string paramName, object paramValue)
        {
            switch (operationParameter.Type.Definition.TypeKind)
            {
            case EdmTypeKind.Primitive:
            case EdmTypeKind.Complex:
                var value = GetPropertyValue(operationParameter.Type, paramValue, null);
                await parameterWriter.WriteValueAsync(paramName, value).ConfigureAwait(false);

                break;

            case EdmTypeKind.Enum:
                await parameterWriter.WriteValueAsync(paramName, new ODataEnumValue(paramValue.ToString())).ConfigureAwait(false);

                break;

            case EdmTypeKind.Untyped:
                await parameterWriter.WriteValueAsync(paramName, new ODataUntypedValue { RawValue = paramValue.ToString() }).ConfigureAwait(false);

                break;

            case EdmTypeKind.Entity:
                var entryWriter = await parameterWriter.CreateResourceWriterAsync(paramName).ConfigureAwait(false);

                var entry = CreateODataEntry(operationParameter.Type.Definition.FullTypeName(), paramValue.ToDictionary(), null);

                RegisterRootEntry(entry);
                await entryWriter.WriteStartAsync(entry).ConfigureAwait(false);

                await entryWriter.WriteEndAsync().ConfigureAwait(false);

                UnregisterRootEntry(entry);

                break;

            case EdmTypeKind.Collection:
                var collectionType = operationParameter.Type.Definition as IEdmCollectionType;
                var elementType    = collectionType.ElementType;
                if (elementType.Definition.TypeKind == EdmTypeKind.Entity)
                {
                    var feedWriter = await parameterWriter.CreateResourceSetWriterAsync(paramName).ConfigureAwait(false);

                    var feed = new ODataResourceSet();
                    await feedWriter.WriteStartAsync(feed).ConfigureAwait(false);

                    foreach (var item in (IEnumerable)paramValue)
                    {
                        var feedEntry = CreateODataEntry(elementType.Definition.FullTypeName(), item.ToDictionary(), null);

                        RegisterRootEntry(feedEntry);
                        await feedWriter.WriteStartAsync(feedEntry).ConfigureAwait(false);

                        await feedWriter.WriteEndAsync().ConfigureAwait(false);

                        UnregisterRootEntry(feedEntry);
                    }
                    await feedWriter.WriteEndAsync().ConfigureAwait(false);
                }
                else
                {
                    var collectionWriter = await parameterWriter.CreateCollectionWriterAsync(paramName).ConfigureAwait(false);

                    await collectionWriter.WriteStartAsync(new ODataCollectionStart()).ConfigureAwait(false);

                    foreach (var item in (IEnumerable)paramValue)
                    {
                        await collectionWriter.WriteItemAsync(item).ConfigureAwait(false);
                    }
                    await collectionWriter.WriteEndAsync().ConfigureAwait(false);
                }
                break;

            default:
                throw new NotSupportedException($"Unable to write action parameter of a type {operationParameter.Type.Definition.TypeKind}");
            }
        }
示例#5
0
        private async Task WriteOperationParameterAsync(ODataParameterWriter parameterWriter, IEdmOperationParameter operationParameter, string paramName, object paramValue)
        {
            switch (operationParameter.Type.Definition.TypeKind)
            {
            case EdmTypeKind.Primitive:
            case EdmTypeKind.Complex:
                await parameterWriter.WriteValueAsync(paramName, paramValue);

                break;

            case EdmTypeKind.Enum:
                await parameterWriter.WriteValueAsync(paramName, new ODataEnumValue(paramValue.ToString()));

                break;

            case EdmTypeKind.Entity:
                var entryWriter = await parameterWriter.CreateEntryWriterAsync(paramName);

                var entry = CreateODataEntry(operationParameter.Type.Definition.FullTypeName(), paramValue.ToDictionary());
                await entryWriter.WriteStartAsync(entry);

                await entryWriter.WriteEndAsync();

                break;

            case EdmTypeKind.Collection:
                var collectionType = operationParameter.Type.Definition as IEdmCollectionType;
                var elementType    = collectionType.ElementType;
                if (elementType.Definition.TypeKind == EdmTypeKind.Entity)
                {
                    var feedWriter = await parameterWriter.CreateFeedWriterAsync(paramName);

                    var feed = new ODataFeed();
                    await feedWriter.WriteStartAsync(feed);

                    foreach (var item in paramValue as IEnumerable)
                    {
                        var feedEntry = CreateODataEntry(elementType.Definition.FullTypeName(), item.ToDictionary());

                        await feedWriter.WriteStartAsync(feedEntry);

                        await feedWriter.WriteEndAsync();
                    }
                    await feedWriter.WriteEndAsync();
                }
                else
                {
                    var collectionWriter = await parameterWriter.CreateCollectionWriterAsync(paramName);

                    await collectionWriter.WriteStartAsync(new ODataCollectionStart());

                    foreach (var item in paramValue as IEnumerable)
                    {
                        await collectionWriter.WriteItemAsync(item);
                    }
                    await collectionWriter.WriteEndAsync();
                }
                break;

            default:
                throw new NotSupportedException(string.Format("Unable to write action parameter of a type {0}", operationParameter.Type.Definition.TypeKind));
            }
        }