/// <summary> /// Parse the constant entity node. /// </summary> /// <param name="nodeIn">The input constant node.</param> /// <returns>The parsed object.</returns> private object ParseEntity(ConstantNode nodeIn) { ODataMessageReaderSettings settings = new ODataMessageReaderSettings(); InMemoryMessage message = new InMemoryMessage() { Stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(nodeIn.LiteralText)), }; var resourceType = (nodeIn.TypeReference as IEdmStructuredTypeReference).Definition as IEdmStructuredType; using ( ODataMessageReader reader = new ODataMessageReader(message as IODataRequestMessage, settings, this.UriParser.Model)) { if (nodeIn.LiteralText.Contains("@odata.id")) { ODataEntityReferenceLink referenceLink = reader.ReadEntityReferenceLink(); var queryContext = new QueryContext(this.UriParser.ServiceRoot, referenceLink.Url, this.DataSource.Model, this.UriParser.Container); var target = queryContext.ResolveQuery(this.DataSource); return(target); } var entityType = resourceType as IEdmEntityType; var entryReader = reader.CreateODataUriParameterResourceReader( entityType == null ? null : new EdmEntitySet(new EdmEntityContainer("NS", "Test"), "TestType", entityType), resourceType); return(ODataObjectModelConverter.ReadEntityOrEntityCollection(entryReader, false)); } }
/// <summary> /// Parse the constant entity collection node. /// </summary> /// <param name="nodeIn">The input constant node.</param> /// <returns>The parsed object.</returns> private object ParseEntityCollection(ConstantNode nodeIn) { ODataMessageReaderSettings settings = new ODataMessageReaderSettings(); InMemoryMessage message = new InMemoryMessage() { Stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(nodeIn.LiteralText)), }; var resourceType = ((nodeIn.TypeReference.Definition as IEdmCollectionType).ElementType as IEdmStructuredTypeReference) .Definition as IEdmStructuredType; object list = null; MethodInfo addMethod = null; using ( ODataMessageReader reader = new ODataMessageReader(message as IODataRequestMessage, settings, this.UriParser.Model)) { if (nodeIn.LiteralText.Contains("@odata.id")) { ODataEntityReferenceLinks referenceLinks = reader.ReadEntityReferenceLinks(); foreach (var referenceLink in referenceLinks.Links) { var queryContext = new QueryContext(this.UriParser.ServiceRoot, referenceLink.Url, this.DataSource.Model, this.UriParser.Container); var target = queryContext.ResolveQuery(this.DataSource); if (list == null) { // create the list. This would require the first type is not derived type. Type listType = typeof(List <>).MakeGenericType(target.GetType()); addMethod = listType.GetMethod("Add"); list = Activator.CreateInstance(listType); } addMethod.Invoke(list, new[] { target }); } return(list); } var entityType = resourceType as IEdmEntityType; var feedReader = reader.CreateODataUriParameterResourceSetReader( entityType == null ? null : new EdmEntitySet(new EdmEntityContainer("NS", "Test"), "TestType", entityType), resourceType); return(ODataObjectModelConverter.ReadEntityOrEntityCollection(feedReader, true)); } }
/// <summary> /// Parse the constant entity node. /// </summary> /// <param name="nodeIn">The input constant node.</param> /// <returns>The parsed object.</returns> private object ParseEntity(ConstantNode nodeIn) { ODataMessageReaderSettings settings = new ODataMessageReaderSettings(); InMemoryMessage message = new InMemoryMessage() { Stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(nodeIn.LiteralText)), }; var entityType = (nodeIn.TypeReference as IEdmEntityTypeReference).Definition as IEdmEntityType; using ( ODataMessageReader reader = new ODataMessageReader(message as IODataRequestMessage, settings, this.UriParser.Model)) { if (nodeIn.LiteralText.Contains("@odata.id")) { ODataEntityReferenceLink referenceLink = reader.ReadEntityReferenceLink(); var queryContext = new QueryContext(this.UriParser.ServiceRoot, referenceLink.Url, this.DataSource.Model); var target = queryContext.ResolveQuery(this.DataSource); return(target); } var entryReader = reader.CreateODataEntryReader( new EdmEntitySet(new EdmEntityContainer("NS", "Test"), "TestType", entityType), entityType); ODataEntry entry = null; while (entryReader.Read()) { if (entryReader.State == ODataReaderState.EntryEnd) { entry = entryReader.Item as ODataEntry; } } return(ODataObjectModelConverter.ConvertPropertyValue(entry)); } }