/// <summary> /// Visits the children of the given payload element and replaces it with a copy if any child changes /// </summary> /// <param name="payloadElement">The payload element to potentially replace</param> /// <returns>The original element or a copy to replace it with</returns> public virtual ODataPayloadElement Visit(EmptyUntypedCollection payloadElement) { ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement"); if (this.alwaysReplace) { return(payloadElement.ReplaceWith(new EmptyUntypedCollection())); } return(payloadElement); }
/// <summary> /// Visits a payload element whose root is an EmptyUntypedCollection. /// </summary> /// <param name="expected">The root node of payload element being visited.</param> public void Visit(EmptyUntypedCollection expected) { ExceptionUtilities.CheckArgumentNotNull(expected, "expected"); var observed = this.GetNextObservedElement <EmptyUntypedCollection>(); using (this.Assert.WithMessage("Empty untyped collection did not match expectation")) { this.CompareAnnotations(expected.Annotations, observed.Annotations); } }
/// <summary> /// Visits the payload element and annotates it with metadata /// </summary> /// <param name="payloadElement">The payload element to visit</param> public override void Visit(EmptyUntypedCollection payloadElement) { // an empty entity set at the top level can appear as an untyped collection if (this.IsRootElement) { var entitySet = this.MetadataStack.Peek() as EntitySet; if (entitySet != null) { payloadElement.AddAnnotationIfNotExist(new EntitySetAnnotation() { EntitySet = entitySet }); return; } } this.VisitCollection(payloadElement); }
/// <summary> /// Replaces the empty collection property with a more specific type /// </summary> /// <param name="payloadElement">The payload element to potentially replace</param> /// <returns>The original element or a copy to replace it with</returns> public override ODataPayloadElement Visit(EmptyUntypedCollection payloadElement) { ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement"); var expectedTypeAnnotatation = payloadElement.Annotations.OfType <ExpectedPayloadElementTypeAnnotation>().SingleOrDefault(); if (expectedTypeAnnotatation != null && expectedTypeAnnotatation.ExpectedType == ODataPayloadElementType.LinkCollection) { var linkCollection = new LinkCollection(); linkCollection.InlineCount = payloadElement.InlineCount; linkCollection.NextLink = payloadElement.NextLink; return(payloadElement.ReplaceWith(linkCollection)); } var entitySetAnnotation = payloadElement.Annotations.OfType <EntitySetAnnotation>().SingleOrDefault(); if (entitySetAnnotation != null) { var entitySet = new EntitySetInstance(); entitySet.InlineCount = payloadElement.InlineCount; entitySet.NextLink = payloadElement.NextLink; return(payloadElement.ReplaceWith(entitySet)); } var functionAnnotation = payloadElement.Annotations.OfType <FunctionAnnotation>().SingleOrDefault(); if (functionAnnotation != null && expectedTypeAnnotatation != null) { if (expectedTypeAnnotatation.ExpectedType == ODataPayloadElementType.ComplexInstanceCollection) { return(payloadElement.ReplaceWith(new ComplexInstanceCollection())); } if (expectedTypeAnnotatation.ExpectedType == ODataPayloadElementType.PrimitiveCollection) { return(payloadElement.ReplaceWith(new PrimitiveCollection())); } } return(base.Visit(payloadElement)); }
/// <summary> /// Replaces the empty collection property with a more specific type /// </summary> /// <param name="payloadElement">The payload element to potentially replace</param> /// <returns>The original element or a copy to replace it with</returns> public override ODataPayloadElement Visit(EmptyUntypedCollection payloadElement) { ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement"); var expectedTypeAnnotatation = payloadElement.Annotations.OfType<ExpectedPayloadElementTypeAnnotation>().SingleOrDefault(); if (expectedTypeAnnotatation != null && expectedTypeAnnotatation.ExpectedType == ODataPayloadElementType.LinkCollection) { var linkCollection = new LinkCollection(); linkCollection.InlineCount = payloadElement.InlineCount; linkCollection.NextLink = payloadElement.NextLink; return payloadElement.ReplaceWith(linkCollection); } var entitySetAnnotation = payloadElement.Annotations.OfType<EntitySetAnnotation>().SingleOrDefault(); if (entitySetAnnotation != null) { var entitySet = new EntitySetInstance(); entitySet.InlineCount = payloadElement.InlineCount; entitySet.NextLink = payloadElement.NextLink; return payloadElement.ReplaceWith(entitySet); } var functionAnnotation = payloadElement.Annotations.OfType<FunctionAnnotation>().SingleOrDefault(); if (functionAnnotation != null && expectedTypeAnnotatation != null) { if (expectedTypeAnnotatation.ExpectedType == ODataPayloadElementType.ComplexInstanceCollection) { return payloadElement.ReplaceWith(new ComplexInstanceCollection()); } if (expectedTypeAnnotatation.ExpectedType == ODataPayloadElementType.PrimitiveCollection) { return payloadElement.ReplaceWith(new PrimitiveCollection()); } } return base.Visit(payloadElement); }
/// <summary> /// Visits a payload element whose root is a EmptyUntypedCollection. /// </summary> /// <param name="payloadElement">The root node of payload element being visited.</param> public void Visit(EmptyUntypedCollection payloadElement) { this.isRootElement = false; this.writer.StartArrayScope(); this.writer.EndScope(); }
/// <summary> /// Calls the base class method to process the empty (untyped) collection. /// </summary> /// <param name="payloadElement">The empty collection to process.</param> public override void Visit(EmptyUntypedCollection payloadElement) { base.Visit(payloadElement); }
/// <summary> /// Replaces the empty untyped collection with a more specific type /// </summary> /// <param name="payloadElement">The payload element to potentially replace</param> /// <returns>The original element or a copy to replace it with</returns> public override ODataPayloadElement Visit(EmptyUntypedCollection payloadElement) { // TODO: handle once service operations are implemented return payloadElement; }
/// <summary> /// Visits the payload element and throws not supported /// </summary> /// <param name="payloadElement">The payload element to visit</param> public override void Visit(EmptyUntypedCollection payloadElement) { throw new TaupoNotSupportedException("Should have been fixed in normalizer"); }
private bool TryGetCollectionType(JsonObject jsonObject, out ODataPayloadElement elem) { string typeName = this.GetMetadataPropertyValue(jsonObject, TypeFieldName); elem = null; // if this object has a property with.Name "results" and it is of type "JsonArray" // Example: // "results": [ // { ... }, // { ... } // ] // if it is EntitySet or ComplexCollection // EntitySets have "_Count" and "_Next". So process it before retrning. if (jsonObject.Properties.Any(prop => prop.Name == ResultsFieldName) && jsonObject.Properties.Where(prop => prop.Name == ResultsFieldName).Single().Value.JsonType == JsonValueType.JsonArray) { string nextLink = this.GetNextLink(jsonObject); string countField = this.GetInlineCount(jsonObject); ODataPayloadElementCollection coll = this.ConvertArray((JsonArray)jsonObject.Properties.Where(p => p.Name == ResultsFieldName).Single().Value, true); if (coll.ElementType == ODataPayloadElementType.EntitySetInstance) { EntitySetInstance entitySet = coll as EntitySetInstance; entitySet.NextLink = nextLink; if (countField == null) { entitySet.InlineCount = null; } else { entitySet.InlineCount = Convert.ToInt64(countField, CultureInfo.InvariantCulture); } elem = coll; } else if (coll.ElementType == ODataPayloadElementType.LinkCollection) { LinkCollection linkCollection = (LinkCollection)coll; linkCollection.InlineCount = Convert.ToInt64(countField, CultureInfo.InvariantCulture); linkCollection.NextLink = nextLink; elem = coll; } else if (coll.ElementType == ODataPayloadElementType.PrimitiveCollection) { if (typeName != null) { PrimitiveMultiValue primitiveMultiValue = new PrimitiveMultiValue(typeName, false, ((PrimitiveCollection)coll).ToArray()); elem = primitiveMultiValue; } else { elem = coll; } } else if (coll.ElementType == ODataPayloadElementType.ComplexInstanceCollection) { if (typeName != null) { ComplexMultiValue complexMultiValue = new ComplexMultiValue(typeName, false, ((ComplexInstanceCollection)coll).ToArray()); elem = complexMultiValue; } else { elem = coll; } } else { ExceptionUtilities.Assert(coll.ElementType == ODataPayloadElementType.EmptyUntypedCollection, "Collection type unhandled: {0}", coll.ElementType); string elementTypeName; if (ODataUtilities.TryGetMultiValueElementTypeName(typeName, out elementTypeName)) { ExceptionUtilities.CheckObjectNotNull(this.PrimitiveDataTypeConverter, "Cannot infer clr type from edm type without converter"); if (this.PrimitiveDataTypeConverter.ToClrType(elementTypeName) != null) { elem = new PrimitiveMultiValue(typeName, false); } else { elem = new ComplexMultiValue(typeName, false); } } else { EmptyUntypedCollection emptyCollection = (EmptyUntypedCollection)coll; if (countField != null) { emptyCollection.InlineCount = long.Parse(countField, CultureInfo.InvariantCulture); } if (nextLink != null) { emptyCollection.NextLink = nextLink; } elem = emptyCollection; } } return(true); } return(false); }
/// <summary> /// Visits the payload element /// </summary> /// <param name="payloadElement">The payload element to visit</param> public virtual void Visit(EmptyUntypedCollection payloadElement) { this.VisitCollection(payloadElement); }
/// <summary> /// Replaces the empty untyped collection with a more specific type /// </summary> /// <param name="payloadElement">The payload element to potentially replace</param> /// <returns>The original element or a copy to replace it with</returns> public override ODataPayloadElement Visit(EmptyUntypedCollection payloadElement) { // TODO: handle once service operations are implemented return(payloadElement); }
/// <summary> /// Visits a payload element whose root is an EmptyUntypedCollection. /// </summary> /// <param name="payloadElement">The root node of payload element being visited.</param> public void Visit(EmptyUntypedCollection payloadElement) { ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement"); var current = this.expectedValueStack.Peek(); var value = current as QueryCollectionValue; ExceptionUtilities.CheckObjectNotNull(value, "Value was not a collection. Value was: '{0}'", current.ToString()); this.parent.Assert.AreEqual(value.Elements.Count, 0, "Collection was unexpectly empty"); }