/// <summary>Writes a resource set and performs an action in-between.</summary> /// <param name="resourceSet">The resource set or collection to write.</param> /// <param name="nestedAction">The action to perform in-between writing the resource set.</param> /// <returns>This ODataWriter, allowing for chaining operations.</returns> public ODataWriter Write(ODataResourceSet resourceSet, Action nestedAction) { WriteStart(resourceSet); nestedAction(); WriteEnd(); return(this); }
/// <summary> /// Validates an <see cref="ODataResourceSet"/> to ensure all required information is specified and valid on the WriteEnd call. /// </summary> /// <param name="resourceSet">The resource set to validate.</param> /// <param name="writingRequest">Flag indicating whether the resource set is written as part of a request or a response.</param> internal static void ValidateResourceSetAtEnd(ODataResourceSet resourceSet, bool writingRequest) { Debug.Assert(resourceSet != null, "resourceSet != null"); // Verify next link if (resourceSet.NextPageLink != null) { // Check that NextPageLink is not set for requests if (writingRequest) { throw new ODataException(Strings.WriterValidationUtils_NextPageLinkInRequest); } } }
/// <summary> /// Asynchronously start writing an expanded resource set. /// </summary> /// <param name="expandedResourceSet">The expanded resource set to write.</param> /// <returns>A task instance that represents the asynchronous write operation.</returns> public abstract Task WriteStartAsync(ODataResourceSet expandedResourceSet);
/// <summary> /// Start writing an expanded resource set. /// </summary> /// <param name="expandedResourceSet">The expanded resource set to write.</param> public abstract void WriteStart(ODataResourceSet expandedResourceSet);
/// <summary> Asynchronously start writing a resource set. </summary> /// <returns>A task instance that represents the asynchronous write operation.</returns> /// <param name="resourceSet">The resource set or collection to write.</param> public abstract Task WriteStartAsync(ODataResourceSet resourceSet);
/// <summary>Writes a resource set.</summary> /// <param name="resourceSet">The resource set or collection to write.</param> /// <returns>This ODataWriter, allowing for chaining operations.</returns> public ODataWriter Write(ODataResourceSet resourceSet) { WriteStart(resourceSet); WriteEnd(); return(this); }
/// <summary>Starts the writing of a resource set.</summary> /// <param name="resourceSet">The resource set or collection to write.</param> public abstract void WriteStart(ODataResourceSet resourceSet);
/// <summary> Asynchronously start writing a resource set. </summary> /// <returns>A task instance that represents the asynchronous write operation.</returns> /// <param name="resourceSet">The resource set or collection to write.</param> public virtual Task WriteStartAsync(ODataResourceSet resourceSet) { return(TaskUtils.GetTaskForSynchronousOperation(() => this.WriteStart(resourceSet))); }
/// <summary> /// Provide additional serialization information to the <see cref="ODataWriter"/> for <paramref name="resourceSet"/>. /// </summary> /// <param name="resourceSet">The instance to set the serialization info.</param> /// <param name="serializationInfo">The serialization info to set.</param> public static void SetSerializationInfo(this ODataResourceSet resourceSet, ODataResourceSerializationInfo serializationInfo) { ExceptionUtils.CheckArgumentNotNull(resourceSet, "resourceSet"); resourceSet.SerializationInfo = serializationInfo; }
public void MaterializeEntityShouldWork() { var odataEntry = new OData.ODataResource() { Id = new Uri("http://www.odata.org/service.svc/entitySet(1)") }; odataEntry.Properties = new OData.ODataProperty[] { new OData.ODataProperty { Name = "keyProp", Value = 1 }, new OData.ODataProperty { Name = "colorProp", Value = new OData.ODataEnumValue("blue") }, new OData.ODataProperty { Name = "primitiveCollection", Value = new OData.ODataCollectionValue { TypeName = "Edm.Int32", Items = new List <object> { 1, 2, 3 } } }, new OData.ODataProperty { Name = "enumCollection", Value = new OData.ODataCollectionValue { TypeName = "color", Items = new List <OData.ODataEnumValue> { new OData.ODataEnumValue("white"), new OData.ODataEnumValue("blue") } } } }; var complexP = new OData.ODataNestedResourceInfo() { Name = "complexProp", IsCollection = false }; var complexResource = new OData.ODataResource { Properties = new OData.ODataProperty[] { new OData.ODataProperty { Name = "age", Value = 11 }, new OData.ODataProperty { Name = "name", Value = "June" } } }; var complexColP = new OData.ODataNestedResourceInfo { Name = "complexCollection", IsCollection = true }; var complexColResourceSet = new OData.ODataResourceSet(); var items = new List <OData.ODataResource> { new OData.ODataResource { Properties = new OData.ODataProperty[] { new OData.ODataProperty { Name = "name", Value = "Aug" }, new OData.ODataProperty { Name = "age", Value = 8 }, new OData.ODataProperty { Name = "color", Value = new OData.ODataEnumValue("white") } } }, new OData.ODataResource { Properties = new OData.ODataProperty[] { new OData.ODataProperty { Name = "name", Value = "Sep" }, new OData.ODataProperty { Name = "age", Value = 9 }, new OData.ODataProperty { Name = "color", Value = new OData.ODataEnumValue("blue") } } } }; var clientEdmModel = new ClientEdmModel(ODataProtocolVersion.V4); var context = new DataServiceContext(); var materializerEntry = MaterializerEntry.CreateEntry(odataEntry, OData.ODataFormat.Json, true, clientEdmModel); MaterializerNavigationLink.CreateLink(complexP, MaterializerEntry.CreateEntry(complexResource, OData.ODataFormat.Json, true, clientEdmModel)); MaterializerFeed.CreateFeed(complexColResourceSet, items); MaterializerNavigationLink.CreateLink(complexColP, complexColResourceSet); var materializerContext = new TestMaterializerContext() { Model = clientEdmModel, Context = context }; var adapter = new EntityTrackingAdapter(new TestEntityTracker(), MergeOption.OverwriteChanges, clientEdmModel, context); QueryComponents components = new QueryComponents(new Uri("http://foo.com/Service"), new Version(4, 0), typeof(EntityType), null, new Dictionary <Expression, Expression>()); var entriesMaterializer = new ODataEntriesEntityMaterializer(new OData.ODataResource[] { odataEntry }, materializerContext, adapter, components, typeof(EntityType), null, OData.ODataFormat.Json); var customersRead = new List <EntityType>(); while (entriesMaterializer.Read()) { customersRead.Add(entriesMaterializer.CurrentValue as EntityType); } customersRead.Should().HaveCount(1); customersRead[0].KeyProp.Should().Be(1); customersRead[0].ComplexProp.Should().Equals(new ComplexType { Age = 11, Name = "June" }); customersRead[0].ColorProp.Should().Equals(Color.Blue); customersRead[0].PrimitiveCollection.Should().Equals(new List <int> { 1, 2, 3 }); ComplexType complex1 = new ComplexType { Name = "Aug", Age = 8, Color = Color.White }; ComplexType complex2 = new ComplexType { Name = "Sep", Age = 9, Color = Color.Blue }; customersRead[0].ComplexCollection.Should().Equals(new List <ComplexType> { complex1, complex2 }); customersRead[0].EnumCollection.Should().Equals(new List <Color> { Color.White, Color.Blue }); }