private static void WriteOdataEntity(ITableEntity entity, TableOperationType operationType, OperationContext ctx, ODataWriter writer, TableRequestOptions options, bool ignoreEncryption) { ODataEntry entry = new ODataEntry() { Properties = GetPropertiesWithKeys(entity, ctx, operationType, options, ignoreEncryption), TypeName = "account.sometype" }; entry.SetAnnotation(new SerializationTypeNameAnnotation { TypeName = null }); writer.WriteStart(entry); writer.WriteEnd(); writer.Flush(); }
public void WritingResourceWithSameAndAllowedTypeAsEntitySetTypeWithOrWithoutDerivedTypeConstraintWorks() { Action <ODataMessageWriter> writeCustomersAction = (messageWriter) => { ODataWriter writer = messageWriter.CreateODataResourceSetWriter(this.edmCustomers, this.edmCustomerType); // entityset writer.WriteStart(new ODataResourceSet()); writer.WriteStart(this.odataCustomerResource); writer.WriteEnd(); writer.WriteStart(this.odataVipResource); writer.WriteEnd(); writer.WriteEnd(); }; // EntitySet doesn't have the derived type constraint. string customersActual = GetWriterOutput(this.edmModel, writeCustomersAction); Assert.Contains("/$metadata#Customers\",\"value\":[{\"Id\":7},{\"@odata.type\":\"#NS.VipCustomer\",\"Id\":8,", customersActual); // EntitySet has the derived type constraint. SetDerivedTypeAnnotation(this.edmModel, this.edmCustomers, "NS.VipCustomer"); string customersActualWithDerivedTypeConstraint = GetWriterOutput(this.edmModel, writeCustomersAction); Assert.Equal(customersActual, customersActualWithDerivedTypeConstraint); }
private void WriteFeed(ODataWriter writer, ODataFeed feed) { writer.WriteStart(feed); var annotation = feed.GetAnnotation <ODataFeedEntriesObjectModelAnnotation>(); if (annotation != null) { foreach (var entry in annotation) { this.WriteEntry(writer, entry); } } writer.WriteEnd(); }
private void WriteResourceSet(ODataWriter odataWriter, ResourceSetWrapper resourceSet) { odataWriter.WriteStart(resourceSet.ResourceSet); var resources = resourceSet.Resources; if (resources != null && resources.Count > 0) { foreach (var resource in resources) { WriteResource(odataWriter, resource); } } odataWriter.WriteEnd(); }
private void WriteResource(ODataWriter odataWriter, ResourceWrapper resource) { odataWriter.WriteStart(resource.Resource); var nestedResourceInfos = resource.NestedResourceInfos; if (nestedResourceInfos != null && nestedResourceInfos.Count > 0) { foreach (var nested in nestedResourceInfos) { WriteNestedResourceInfo(odataWriter, nested); } } odataWriter.WriteEnd(); }
private void WriteEntry(object graph, IEnumerable <ODataProperty> propertyBag, ODataWriter writer, ODataSerializerContext writeContext) { IEdmEntityType entityType = _edmEntityTypeReference.EntityDefinition(); EntityInstanceContext entityInstanceContext = new EntityInstanceContext { EdmModel = SerializerProvider.EdmModel, EntitySet = writeContext.EntitySet, EntityType = entityType, UrlHelper = writeContext.UrlHelper, PathHandler = writeContext.PathHandler, EntityInstance = graph, SkipExpensiveAvailabilityChecks = writeContext.SkipExpensiveAvailabilityChecks }; ODataEntry entry = new ODataEntry { TypeName = _edmEntityTypeReference.FullName(), Properties = propertyBag, Actions = CreateActions(entityInstanceContext) }; if (writeContext.EntitySet != null) { IEntitySetLinkBuilder linkBuilder = SerializerProvider.EdmModel.GetEntitySetLinkBuilder(writeContext.EntitySet); string idLink = linkBuilder.BuildIdLink(entityInstanceContext); if (idLink != null) { entry.Id = idLink; } Uri readLink = linkBuilder.BuildReadLink(entityInstanceContext); if (readLink != null) { entry.ReadLink = readLink; } Uri editLink = linkBuilder.BuildEditLink(entityInstanceContext); if (editLink != null) { entry.EditLink = editLink; } } writer.WriteStart(entry); WriteNavigationLinks(entityInstanceContext, writer, writeContext); writer.WriteEnd(); }
private void WriteFeed(IEnumerable enumerable, IEdmTypeReference feedType, ODataWriter writer, ODataSerializerContext writeContext) { IEdmEntityTypeReference elementType = null; if (feedType.IsCollection()) { IEdmTypeReference refer = feedType.AsCollection().ElementType(); if (refer.IsEntity()) { elementType = refer.AsEntity(); } } Debug.Assert(elementType != null); ODataFeed feed = CreateODataFeed(enumerable, feedType.AsCollection(), writeContext); Debug.Assert(feed != null); ODataEdmTypeSerializer entrySerializer = SerializerProvider.GetEdmTypeSerializer(elementType); Debug.Assert(entrySerializer is CustomEntrySerializer); // save this for later to support JSON odata.streaming. Uri nextPageLink = feed.NextPageLink; feed.NextPageLink = null; writer.WriteStart(feed); foreach (object entry in enumerable) { entrySerializer.WriteObjectInline(entry, elementType, writer, writeContext); } // Subtle and suprising behavior: If the NextPageLink property is set before calling WriteStart(feed), // the next page link will be written early in a manner not compatible with odata.streaming=true. Instead, if // the next page link is not set when calling WriteStart(feed) but is instead set later on that feed // object before calling WriteEnd(), the next page link will be written at the end, as required for // odata.streaming=true support. if (nextPageLink != null) { feed.NextPageLink = nextPageLink; } writer.WriteEnd(); }
public static void SetODataRequestContent(IODataRequestMessage requestMessage, IEdmModel model, IInventoryItem inventoryItem) { var setting = new ODataMessageWriterSettings(); setting.SetContentType(ODataFormat.Atom); ODataMessageWriter oDatamessageWriter = new ODataMessageWriter(requestMessage, setting, model); ODataWriter oDataEntrywriter = oDatamessageWriter.CreateODataEntryWriter(); oDataEntrywriter.WriteStart(new ODataEntry() { TypeName = TypeName, Properties = GetODataProperties(inventoryItem) }); oDataEntrywriter.WriteEnd(); }
private static void WriteEntry(ODataWriter writer, object entity, IEnumerable <string> projectedProperties) { var entry = new ODataResource() { Id = new Uri("http://temp.org/" + Guid.NewGuid()), SerializationInfo = MySerializationInfo }; entry.Properties = entity.GetType().GetProperties().Select(p => new ODataProperty() { Name = p.Name, Value = p.GetValue(entity, null) }); writer.WriteStart(entry); writer.WriteEnd(); }
private static void WriteOdataEntity(ITableEntity entity, TableOperationType operationType, OperationContext ctx, ODataWriter writer) { ODataEntry entry = new ODataEntry() { Properties = GetPropertiesWithKeys(entity, ctx) }; if (operationType != TableOperationType.Insert && operationType != TableOperationType.Retrieve) { entry.ETag = entity.ETag; } writer.WriteStart(entry); writer.WriteEnd(); writer.Flush(); }
private void WriteEntry(object graph, ODataWriter writer, ODataSerializerContext writeContext) { Contract.Assert(writeContext != null); IEdmEntityType entityType = EntityType.EntityDefinition(); EntityInstanceContext entityInstanceContext = new EntityInstanceContext(writeContext, entityType, graph); ODataEntry entry = CreateEntry(entityInstanceContext, writeContext); if (entry != null) { writer.WriteStart(entry); WriteNavigationLinks(entityInstanceContext, writer, writeContext); writer.WriteEnd(); } }
/// <summary> /// Writes an OData Feed with number <see cref="numberOfEntries"/> of entries <see cref="entry"/> /// </summary> /// <param name="writeStream"></param> /// <param name="edmModel"></param> /// <param name="numberOfEntries"></param> /// <param name="innerWrite"></param> /// <param name="entitySet"></param> /// <returns>The payload size</returns> protected Int64 WriteFeed(Stream writeStream, IEdmModel edmModel, long numberOfEntries, Action <ODataWriter> innerWrite, IEdmEntitySetBase entitySet) { using (var messageWriter = ODataMessageHelper.CreateMessageWriter(writeStream, edmModel)) { ODataWriter writer = messageWriter.CreateODataResourceSetWriter(entitySet); writer.WriteStart(new ODataResourceSet { Id = new Uri("http://www.odata.org/Perf.svc") }); for (long i = 0; i < numberOfEntries; ++i) { innerWrite(writer); } writer.WriteEnd(); writer.Flush(); } return(writeStream.Length); // return payload size }
private void WriteEntry(ODataWriter writer, Object entity, ref EntityPropertiesInfo entityPropertiesInfo) { if (entityPropertiesInfo.EdmEntityType == null) { entityPropertiesInfo = GetProperties(entity); } ODataResource entry = OeDataContext.CreateEntry(entity, entityPropertiesInfo.Structurals); writer.WriteStart(entry); foreach (PropertyInfo navigationProperty in entityPropertiesInfo.Navigations) { WriteNavigationProperty(writer, entity, navigationProperty); } writer.WriteEnd(); }
private void WriteEntry(ODataWriter writer, ODataResource entry) { writer.WriteStart(entry); var annotation = entry.GetAnnotation <ODataEntryNavigationLinksObjectModelAnnotation>(); ODataNestedResourceInfo navLink = null; if (annotation != null) { for (int i = 0; i < annotation.Count; ++i) { bool found = annotation.TryGetNavigationLinkAt(i, out navLink); ExceptionUtilities.Assert(found, "Navigation links should be ordered sequentially for writing"); this.WriteNavigationLink(writer, navLink); } } writer.WriteEnd(); }
private void WriteNestedResourceInfo(ODataWriter odataWriter, NestedResourceInfoWrapper nestedResourceInfo) { odataWriter.WriteStart(nestedResourceInfo.NestedResourceInfo); var nestedResource = nestedResourceInfo.nestedResource; if (nestedResource != null) { if (nestedResource is ResourceWrapper) { WriteResource(odataWriter, nestedResource as ResourceWrapper); } else { WriteResourceSet(odataWriter, nestedResource as ResourceSetWrapper); } } odataWriter.WriteEnd(); }
private void WriteEntry(object graph, ODataWriter writer, ODataSerializerContext writeContext) { Contract.Assert(writeContext != null); EntityInstanceContext entityInstanceContext = new EntityInstanceContext(writeContext, EntityType, graph); SelectExpandNode selectExpandNode = CreateSelectExpandNode(entityInstanceContext); if (selectExpandNode != null) { ODataEntry entry = CreateEntry(selectExpandNode, entityInstanceContext); if (entry != null) { writer.WriteStart(entry); WriteNavigationLinks(selectExpandNode.SelectedNavigationProperties, entityInstanceContext, writer); WriteExpandedNavigationProperties(selectExpandNode.ExpandedNavigationProperties, entityInstanceContext, writer); writer.WriteEnd(); } } }
private void WriteComplexProperties(IEnumerable <IEdmStructuralProperty> complexProperties, ResourceContext resourceContext, ODataWriter writer) { Contract.Assert(complexProperties != null); Contract.Assert(resourceContext != null); Contract.Assert(writer != null); foreach (IEdmStructuralProperty complexProperty in complexProperties) { ODataNestedResourceInfo nestedResourceInfo = new ODataNestedResourceInfo { IsCollection = complexProperty.Type.IsCollection(), Name = complexProperty.Name }; writer.WriteStart(nestedResourceInfo); WriteComplexAndExpandedNavigationProperty(complexProperty, null, resourceContext, writer); writer.WriteEnd(); } }
private static void WriteOdataEntity(ITableEntity entity, TableOperationType operationType, OperationContext ctx, ODataWriter writer) { ODataEntry entry = new ODataEntry() { Properties = GetPropertiesWithKeys(entity, ctx, operationType), TypeName = "account.sometype" }; if (operationType != TableOperationType.Insert && operationType != TableOperationType.Retrieve) { entry.ETag = entity.ETag; } entry.SetAnnotation(new SerializationTypeNameAnnotation { TypeName = null }); writer.WriteStart(entry); writer.WriteEnd(); writer.Flush(); }
public void WritingResourceAsAllowedTypeForSingletonWithOrWithoutDerivedTypeConstraintWorks() { Action <ODataMessageWriter> writeVipCustomerAction = (messageWriter) => { ODataWriter writer = messageWriter.CreateODataResourceWriter(this.edmMe, this.edmCustomerType); // Singleton writer.WriteStart(this.odataVipResource); writer.WriteEnd(); }; // Singleton doesn't have the derived type constraint. string vipCustomerActual = GetWriterOutput(this.edmModel, writeVipCustomerAction); Assert.Contains("/$metadata#Me\",\"@odata.type\":\"#NS.VipCustomer\",\"Id\":8,\"Vip\":\"Boss\"}", vipCustomerActual); // Singleton has the derived type constraint. SetDerivedTypeAnnotation(this.edmModel, this.edmMe, "NS.VipCustomer"); string vipCustomerActualWithDerivedTypeConstraint = GetWriterOutput(this.edmModel, writeVipCustomerAction); Assert.Equal(vipCustomerActual, vipCustomerActualWithDerivedTypeConstraint); }
public void WritingResourceWithSameTypeAsSingletonTypeWithOrWithoutDerivedTypeConstraintWorks() { Action <ODataMessageWriter> writeCustomerAction = (messageWriter) => { ODataWriter writer = messageWriter.CreateODataResourceWriter(this.edmMe, this.edmCustomerType); // Singleton writer.WriteStart(this.odataCustomerResource); writer.WriteEnd(); }; // Singleton doesn't have the derived type constraint. string customerActual = GetWriterOutput(this.edmModel, writeCustomerAction); Assert.Contains("/$metadata#Me\",\"Id\":7}", customerActual); // Singleton has the derived type constraint. SetDerivedTypeAnnotation(this.edmModel, this.edmMe, "NS.VipCustomer"); string customerActualWithDerivedTypeConstraint = GetWriterOutput(this.edmModel, writeCustomerAction); Assert.Equal(customerActual, customerActualWithDerivedTypeConstraint); }
public async Task SerializeAsync(OeEntryFactory entryFactory, Db.OeEntityAsyncEnumerator asyncEnumerator, Stream stream, long?count) { ODataResourceSet oDataResourceSet = new ODataResourceSet(); oDataResourceSet.Count = count; Writer.WriteStart(oDataResourceSet); while (await asyncEnumerator.MoveNextAsync().ConfigureAwait(false)) { Object value = asyncEnumerator.Current; ODataResource entry = CreateEntry(entryFactory, entryFactory.GetValue(value)); Writer.WriteStart(entry); foreach (OeEntryFactory navigationLink in entryFactory.NavigationLinks) { WriteNavigationLink(value, navigationLink); } Writer.WriteEnd(); } Writer.WriteEnd(); }
private void WriteNavigationLinks(EntityInstanceContext context, ODataWriter writer, ODataSerializerContext writeContext) { foreach (IEdmNavigationProperty navProperty in _edmEntityTypeReference.NavigationProperties()) { IEdmTypeReference propertyType = navProperty.Type; if (writeContext.EntitySet != null) { IEntitySetLinkBuilder linkBuilder = SerializerProvider.EdmModel.GetEntitySetLinkBuilder(writeContext.EntitySet); ODataNavigationLink navigationLink = new ODataNavigationLink { IsCollection = propertyType.IsCollection(), Name = navProperty.Name, Url = linkBuilder.BuildNavigationLink(context, navProperty) }; writer.WriteStart(navigationLink); writer.WriteEnd(); } } }
private void WriteExpandedNavigationProperties( IDictionary <IEdmNavigationProperty, SelectExpandClause> navigationPropertiesToExpand, ResourceContext resourceContext, ODataWriter writer) { Contract.Assert(navigationPropertiesToExpand != null); Contract.Assert(resourceContext != null); Contract.Assert(writer != null); foreach (KeyValuePair <IEdmNavigationProperty, SelectExpandClause> navPropertyToExpand in navigationPropertiesToExpand) { IEdmNavigationProperty navigationProperty = navPropertyToExpand.Key; ODataNestedResourceInfo navigationLink = CreateNavigationLink(navigationProperty, resourceContext); if (navigationLink != null) { writer.WriteStart(navigationLink); WriteComplexAndExpandedNavigationProperty(navPropertyToExpand.Key, navPropertyToExpand.Value, resourceContext, writer); writer.WriteEnd(); } } }
public void WritingResourceForEntityWorksWithoutDerivedTypeConstraintsButFailedWithConstraint() { Action <ODataMessageWriter> writeCustomersAction = (messageWriter) => { ODataWriter writer = messageWriter.CreateODataResourceWriter(this.edmCustomers, this.edmCustomerType); // entityset writer.WriteStart(this.odataNormalResource); writer.WriteEnd(); }; // EntitySet doesn't have the derived type constraint. string normalCustomerActual = GetWriterOutput(this.edmModel, writeCustomersAction); Assert.Contains("/$metadata#Customers/$entity\",\"@odata.type\":\"#NS.NormalCustomer\",\"Id\":9,\"Email\":\"[email protected]\"}", normalCustomerActual); // Negative test case -- EntitySet has the derived type constraint. SetDerivedTypeAnnotation(this.edmModel, this.edmCustomers, "NS.VipCustomer"); Action test = () => GetWriterOutput(this.edmModel, writeCustomersAction); var exception = Assert.Throws <ODataException>(test); Assert.Equal(Strings.WriterValidationUtils_ValueTypeNotAllowedInDerivedTypeConstraint("NS.NormalCustomer", "navigation source", "Customers"), exception.Message); }
private async Task WriteDynamicComplexPropertiesAsync(ResourceContext resourceContext, ODataWriter writer) { Contract.Assert(resourceContext != null); Contract.Assert(resourceContext.EdmModel != null); if (resourceContext.DynamicComplexProperties == null) { return; } foreach (var dynamicComplexProperty in resourceContext.DynamicComplexProperties) { // If the dynamic property is "null", it should be treated ahead by creating an ODataProperty with ODataNullValue. // However, it's safety here to skip the null dynamic property. if (String.IsNullOrEmpty(dynamicComplexProperty.Key) || dynamicComplexProperty.Value == null) { continue; } IEdmTypeReference edmTypeReference = resourceContext.SerializerContext.GetEdmType(dynamicComplexProperty.Value, dynamicComplexProperty.Value.GetType()); if (edmTypeReference.IsStructured() || (edmTypeReference.IsCollection() && edmTypeReference.AsCollection().ElementType().IsStructured())) { ODataNestedResourceInfo nestedResourceInfo = new ODataNestedResourceInfo { IsCollection = edmTypeReference.IsCollection(), Name = dynamicComplexProperty.Key, }; writer.WriteStart(nestedResourceInfo); await WriteDynamicComplexPropertyAsync(dynamicComplexProperty.Value, edmTypeReference, resourceContext, writer); writer.WriteEnd(); } } }
internal void WriteEntry(EntityDescriptor entityDescriptor, IEnumerable <LinkDescriptor> relatedLinks, ODataRequestMessageWrapper requestMessage) { ClientEdmModel model = ClientEdmModel.GetModel(this.requestInfo.MaxProtocolVersion); ClientTypeAnnotation clientTypeAnnotation = model.GetClientTypeAnnotation(model.GetOrCreateEdmType(entityDescriptor.Entity.GetType())); using (ODataMessageWriter writer = CreateMessageWriter(requestMessage, this.requestInfo)) { ODataWriter odataWriter = writer.CreateODataEntryWriter(); ODataEntry entry = new ODataEntry(); if (this.requestInfo.HasWritingEventHandlers) { entry.SetAnnotation <WritingEntityInfo>(new WritingEntityInfo(entityDescriptor.Entity, this.requestInfo)); } string serverTypeName = this.requestInfo.GetServerTypeName(entityDescriptor); if (clientTypeAnnotation.ElementTypeName != serverTypeName) { SerializationTypeNameAnnotation annotation = new SerializationTypeNameAnnotation { TypeName = serverTypeName }; entry.SetAnnotation <SerializationTypeNameAnnotation>(annotation); } entry.TypeName = clientTypeAnnotation.ElementTypeName; if (EntityStates.Modified == entityDescriptor.State) { entry.Id = entityDescriptor.GetLatestIdentity(); } if (entityDescriptor.IsMediaLinkEntry || clientTypeAnnotation.IsMediaLinkEntry) { entry.MediaResource = new ODataStreamReferenceValue(); } odataWriter.WriteStart(entry); if (EntityStates.Added == entityDescriptor.State) { this.WriteNavigationLink(entityDescriptor, relatedLinks, odataWriter); } entry.Properties = this.PopulateProperties(clientTypeAnnotation, entityDescriptor.Entity, null); odataWriter.WriteEnd(); } }
private static void WriteNavigationLinks(ODataWriter writer, object element, Uri parentEntryUri, IEdmEntityType parentEntityType, IEdmModel model, ODataVersion targetVersion, IEnumerable <string> expandedNavigationProperties) { foreach (var navigationProperty in parentEntityType.NavigationProperties()) { IEdmTypeReference propertyTypeReference = navigationProperty.Type; bool isCollection = navigationProperty.Type.IsCollection(); var navigationLink = new ODataNavigationLink { Url = new Uri(parentEntryUri, navigationProperty.Name), IsCollection = isCollection, Name = navigationProperty.Name, }; writer.WriteStart(navigationLink); if (expandedNavigationProperties.Contains(navigationProperty.Name)) { var propertyValue = DataContext.GetPropertyValue(element, navigationProperty.Name); if (propertyValue != null) { var propertyEntityType = propertyTypeReference.Definition as IEdmEntityType; IEdmEntitySet targetEntitySet = model.EntityContainer.EntitySets().Single(s => s.EntityType() == propertyEntityType); if (isCollection) { WriteFeed(writer, propertyValue as IEnumerable, targetEntitySet, model, targetVersion, Enumerable.Empty <string>()); } else { WriteEntry(writer, propertyValue, targetEntitySet, model, targetVersion, Enumerable.Empty <string>()); } } } writer.WriteEnd(); } }
private void WriteExpandedNavigationProperties( IDictionary <IEdmNavigationProperty, SelectExpandClause> navigationPropertiesToExpand, EntityInstanceContext entityInstanceContext, ODataWriter writer) { Contract.Assert(navigationPropertiesToExpand != null); Contract.Assert(entityInstanceContext != null); Contract.Assert(writer != null); foreach (KeyValuePair <IEdmNavigationProperty, SelectExpandClause> navigationPropertyToExpand in navigationPropertiesToExpand) { IEdmNavigationProperty navigationProperty = navigationPropertyToExpand.Key; ODataNavigationLink navigationLink = CreateNavigationLink(navigationProperty, entityInstanceContext); if (navigationLink != null) { writer.WriteStart(navigationLink); WriteExpandedNavigationProperty(navigationPropertyToExpand, entityInstanceContext, writer); writer.WriteEnd(); } } }
private void WriteFeed(object graph, ODataWriter writer, ODataSerializerWriteContext writeContext) { ODataSerializer entrySerializer = SerializerProvider.GetEdmTypeSerializer(_edmCollectionType.ElementType()); if (entrySerializer == null) { throw Error.NotSupported(SRResources.TypeCannotBeSerialized, _edmCollectionType.ElementType(), typeof(ODataMediaTypeFormatter).Name); } Contract.Assert(entrySerializer.ODataPayloadKind == ODataPayloadKind.Entry); IEnumerable enumerable = graph as IEnumerable; // Data to serialize if (enumerable != null) { ODataFeed feed = new ODataFeed(); // TODO: Bug 467590: remove the hardcoded feed id. Get support for it from the model builder ? feed.Id = FeedNamespace + _edmCollectionType.FullName(); // If we have more OData format specific information apply it now. ODataResult odataFeedAnnotations = graph as ODataResult; if (odataFeedAnnotations != null) { feed.Count = odataFeedAnnotations.Count; feed.NextPageLink = odataFeedAnnotations.NextPageLink; } writer.WriteStart(feed); foreach (object entry in enumerable) { entrySerializer.WriteObjectInline(entry, writer, writeContext); } writer.WriteEnd(); } }
private void WriteEntry(object graph, IEnumerable <ODataProperty> propertyBag, ODataWriter writer, ODataSerializerContext writeContext) { IEdmEntityType entityType = _edmEntityTypeReference.EntityDefinition(); EntityInstanceContext entityInstanceContext = new EntityInstanceContext(SerializerProvider.EdmModel, writeContext.EntitySet, entityType, writeContext.UrlHelper, graph); ODataEntry entry = new ODataEntry { TypeName = _edmEntityTypeReference.FullName(), Properties = propertyBag, }; if (writeContext.EntitySet != null) { IEntitySetLinkBuilder linkBuilder = SerializerProvider.EdmModel.GetEntitySetLinkBuilder(writeContext.EntitySet); string idLink = linkBuilder.BuildIdLink(entityInstanceContext); if (idLink != null) { entry.Id = idLink; } Uri readLink = linkBuilder.BuildReadLink(entityInstanceContext); if (readLink != null) { entry.ReadLink = readLink; } Uri editLink = linkBuilder.BuildEditLink(entityInstanceContext); if (editLink != null) { entry.EditLink = editLink; } } writer.WriteStart(entry); WriteNavigationLinks(entityInstanceContext, writer, writeContext); writer.WriteEnd(); }
private void WriteEntry(ODataWriter writer, ODataItem[] itemsToWrite, ref int currentIdx) { if (currentIdx < itemsToWrite.Length) { ODataEntry entry = (ODataEntry)itemsToWrite[currentIdx++]; writer.WriteStart(entry); while (currentIdx < itemsToWrite.Length) { if (itemsToWrite[currentIdx] is ODataNavigationLink) { this.WriteLink(writer, itemsToWrite, ref currentIdx); } else if (itemsToWrite[currentIdx] is ODataNavigationLinkEnd) { currentIdx++; writer.WriteEnd(); return; } else { break; } } writer.WriteEnd(); } }
private void WriteLink(ODataWriter writer, ODataItem[] itemsToWrite, ref int currentIdx) { if (currentIdx < itemsToWrite.Length) { ODataNavigationLink link = (ODataNavigationLink)itemsToWrite[currentIdx++]; writer.WriteStart(link); if (currentIdx < itemsToWrite.Length) { if (itemsToWrite[currentIdx] is ODataEntry) { this.WriteEntry(writer, itemsToWrite, ref currentIdx); } else if (itemsToWrite[currentIdx] is ODataFeed) { this.WriteFeed(writer, itemsToWrite, ref currentIdx); } } writer.WriteEnd(); } }
private void WriteFeed(ODataWriter writer, ODataItem[] itemsToWrite, ref int currentIdx) { if (currentIdx < itemsToWrite.Length) { ODataFeed feed = (ODataFeed)itemsToWrite[currentIdx++]; writer.WriteStart(feed); while (currentIdx < itemsToWrite.Length && itemsToWrite[currentIdx] is ODataEntry) { this.WriteEntry(writer, itemsToWrite, ref currentIdx); } writer.WriteEnd(); } }