internal string GetEntryTypeNameForWriting(ODataEntry entry)
        {
            Debug.Assert(entry != null, "entry != null");

            SerializationTypeNameAnnotation typeNameAnnotation = entry.GetAnnotation<SerializationTypeNameAnnotation>();
            if (typeNameAnnotation != null)
            {
                return typeNameAnnotation.TypeName;
            }

            return entry.TypeName;
        }
        internal string GetEntryTypeNameForWriting(ODataEntry entry)
        {
            Debug.Assert(entry != null, "entry != null");

            SerializationTypeNameAnnotation typeNameAnnotation = entry.GetAnnotation <SerializationTypeNameAnnotation>();

            if (typeNameAnnotation != null)
            {
                return(typeNameAnnotation.TypeName);
            }

            return(entry.TypeName);
        }
            /// <summary>
            /// Visits an entry item.
            /// </summary>
            /// <param name="entry">The entry to visit.</param>
            protected override ODataPayloadElement VisitEntry(ODataEntry entry)
            {
                ODataPayloadElement payloadElement = base.VisitEntry(entry);
                ODataEntryPayloadOrderObjectModelAnnotation payloadOrderEntryAnnotation = entry.GetAnnotation<ODataEntryPayloadOrderObjectModelAnnotation>();
                if (payloadOrderEntryAnnotation != null)
                {
                    PayloadOrderODataPayloadElementAnnotation payloadOrderElementAnnotation = new PayloadOrderODataPayloadElementAnnotation();
                    payloadOrderElementAnnotation.PayloadItems.AddRange(payloadOrderEntryAnnotation.PayloadItems);
                    payloadElement.Add(payloadOrderElementAnnotation);
                }

                return payloadElement;
            }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a new instance of MaterializerEntry.
        /// </summary>
        /// <param name="entry">The entry.</param>
        /// <param name="format">The format the entry was read in.</param>
        /// <param name="isTracking">True if the contents of the entry will be tracked in the context, otherwise False.</param>
        /// <param name="model">The client model.</param>
        private MaterializerEntry(ODataEntry entry, ODataFormat format, bool isTracking, ClientEdmModel model)
        {
            Debug.Assert(entry != null, "entry != null");

            this.entry = entry;
            this.Format = format;
            this.entityDescriptor = new EntityDescriptor(model);
#pragma warning disable 618
            this.isAtomOrTracking = isTracking || this.Format == ODataFormat.Atom;
#pragma warning restore 618
            string serverTypeName = this.Entry.TypeName;
            SerializationTypeNameAnnotation serializationTypeNameAnnotation = entry.GetAnnotation<SerializationTypeNameAnnotation>();
            if (serializationTypeNameAnnotation != null)
            {
                // If the annotation has a value use it. Otherwise, in JSON-Light, the types can be inferred from the
                // context URI even if they are not present on the wire, so just use the type name from the entry.
                if (serializationTypeNameAnnotation.TypeName != null || this.Format != ODataFormat.Json)
                {
                    serverTypeName = serializationTypeNameAnnotation.TypeName;
                }
            }

            this.entityDescriptor.ServerTypeName = serverTypeName;
        }
        [Fact] // Issue 984: Redundant type name serialization in OData JSON light minimal metadata mode
        public void AddTypeNameAnnotationAsNeeded_AddsAnnotationWithNullValue_IfTypeOfPathMatchesEntryType()
        {
            // Arrange
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            ODataEntry entry = new ODataEntry
            {
                TypeName = model.SpecialCustomer.FullName()
            };

            // Act
            ODataEntityTypeSerializer.AddTypeNameAnnotationAsNeeded(entry, model.SpecialCustomer, ODataMetadataLevel.MinimalMetadata);

            // Assert
            SerializationTypeNameAnnotation annotation = entry.GetAnnotation<SerializationTypeNameAnnotation>();
            Assert.NotNull(annotation); // Guard
            Assert.Null(annotation.TypeName);
        }
        public void AddTypeNameAnnotationAsNeeded_AddsAnnotation_IfTypeOfPathDoesNotMatchEntryType()
        {
            // Arrange
            string expectedTypeName = "TypeName";
            ODataEntry entry = new ODataEntry
            {
                TypeName = expectedTypeName
            };

            // Act
            ODataEntityTypeSerializer.AddTypeNameAnnotationAsNeeded(entry, _customerType.EntityDefinition(), ODataMetadataLevel.MinimalMetadata);

            // Assert
            SerializationTypeNameAnnotation annotation = entry.GetAnnotation<SerializationTypeNameAnnotation>();
            Assert.NotNull(annotation); // Guard
            Assert.Equal(expectedTypeName, annotation.TypeName);
        }
 private void WriteEntry(ODataWriter writer, Lazy<ODataReader> lazyReader, ODataEntry entry)
 {
     this.WriteStart(writer, entry);
     var annotation = entry.GetAnnotation<ODataEntryNavigationLinksObjectModelAnnotation>();
     ODataNavigationLink 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, lazyReader, navLink);
         }
     }
     
     this.WriteEnd(writer, ODataReaderState.EntryEnd);
     this.Read(lazyReader);
 }
            /// <summary>
            /// Visits an entry item.
            /// </summary>
            /// <param name="entry">The entry item to visit.</param>
            /// <returns>An ODataPayloadElement representing the entry.</returns>
            protected override ODataPayloadElement VisitEntry(ODataEntry entry)
            {
                ExceptionUtilities.CheckArgumentNotNull(entry, "entry");

                EntityInstance entity = (EntityInstance)base.VisitEntry(entry);

                var atomMetadata = entry.GetAnnotation<AtomEntryMetadata>();
                if (atomMetadata != null)
                {
                    ConvertAtomEntryMetadata(atomMetadata, entity);
                }

                return entity;
            }
        public void AddTypeNameAnnotationAsNeeded_DoesNotAddAnnotation_InDefaultMetadataMode()
        {
            // Arrange
            ODataEntry entry = new ODataEntry();

            // Act
            ODataEntityTypeSerializer.AddTypeNameAnnotationAsNeeded(entry, null, ODataMetadataLevel.Default);

            // Assert
            Assert.Null(entry.GetAnnotation<SerializationTypeNameAnnotation>());
        }
 /// <summary>
 /// Visits an entry item.
 /// </summary>
 /// <param name="entry">The entry to visit.</param>
 protected override void VisitEntry(ODataEntry entry)
 {
     this.VisitAtomMetadata(entry.GetAnnotation<AtomEntryMetadata>());
     base.VisitEntry(entry);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Gets an entry for a given ODataEntry.
 /// </summary>
 /// <param name="entry">The ODataEntry.</param>
 /// <returns>The materializer entry</returns>
 public static MaterializerEntry GetEntry(ODataEntry entry)
 {
     return entry.GetAnnotation<MaterializerEntry>();
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Creates the materializer entry.
        /// </summary>
        /// <param name="entry">The entry.</param>
        /// <param name="format">The format the entry was read in.</param>
        /// <param name="isTracking">True if the contents of the entry will be tracked in the context, otherwise False.</param>
        /// <param name="model">The client model.</param>
        /// <returns>A new materializer entry.</returns>
        public static MaterializerEntry CreateEntry(ODataEntry entry, ODataFormat format, bool isTracking, ClientEdmModel model)
        {
            Debug.Assert(entry.GetAnnotation<MaterializerEntry>() == null, "MaterializerEntry has already been created.");

            MaterializerEntry materializerEntry = new MaterializerEntry(entry, format, isTracking, model);
            entry.SetAnnotation<MaterializerEntry>(materializerEntry);

            return materializerEntry;
        }