/// <summary>Initializes a new instance of the <see cref="T:Microsoft.OData.Core.ODataMessageWriterSettings" /> class with specified settings.</summary>
        /// <param name="other">The specified settings.</param>
        public ODataMessageWriterSettings(ODataMessageWriterSettings other)
            : base(other)
        {
            ExceptionUtils.CheckArgumentNotNull(other, "other");

            this.acceptCharSets               = other.acceptCharSets;
            this.acceptMediaTypes             = other.acceptMediaTypes;
            this.PayloadBaseUri               = other.PayloadBaseUri;
            this.DisableMessageStreamDisposal = other.DisableMessageStreamDisposal;
            this.format                                     = other.format;
            this.useFormat                                  = other.useFormat;
            this.Version                                    = other.Version;
            this.JsonPCallback                              = other.JsonPCallback;
            this.shouldIncludeAnnotation                    = other.shouldIncludeAnnotation;
            this.AutoComputePayloadMetadataInJson           = other.AutoComputePayloadMetadataInJson;
            this.UseKeyAsSegment                            = other.UseKeyAsSegment;
            this.alwaysUseDefaultXmlNamespaceForRootElement = other.alwaysUseDefaultXmlNamespaceForRootElement;
            this.ODataUri                                   = other.ODataUri;

            // NOTE: writer behavior is immutable; copy by reference is ok.
            this.writerBehavior       = other.writerBehavior;
            this.EnableAtom           = other.EnableAtom;
            this.EnableFullValidation = other.EnableFullValidation;
            this.mediaTypeResolver    = other.mediaTypeResolver;
            this.ODataSimplified      = other.ODataSimplified;
        }
Ejemplo n.º 2
0
 /// <summary>Initializes a new instance of the <see cref="T:Microsoft.OData.Core.ODataMessageWriterSettings" /> class with default settings. </summary>
 public ODataMessageWriterSettings()
     : base()
 {
     // Create the default writer behavior
     this.writerBehavior       = ODataWriterBehavior.DefaultBehavior;
     this.EnableAtom           = false;
     this.EnableFullValidation = true;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Validates that the expected property allows null value.
        /// </summary>
        /// <param name="expectedPropertyTypeReference">The expected property type or null if we don't have any.</param>
        /// <param name="propertyName">The name of the property.</param>
        /// <param name="writerBehavior">The <see cref="ODataWriterBehavior"/> instance controlling the behavior of the writer.</param>
        /// <param name="model">The model to use to get the OData version.</param>
        /// <param name="bypassValidation">Bypass the validation if it is true.</param>
        internal static void ValidateNullPropertyValue(IEdmTypeReference expectedPropertyTypeReference, string propertyName, ODataWriterBehavior writerBehavior, IEdmModel model, bool bypassValidation = false)
        {
            Debug.Assert(writerBehavior != null, "writerBehavior != null");
            Debug.Assert(model != null, "For null validation, model is required.");

            if (bypassValidation)
            {
                return;
            }

            if (expectedPropertyTypeReference != null)
            {
                if (expectedPropertyTypeReference.IsNonEntityCollectionType())
                {
                    throw new ODataException(Strings.WriterValidationUtils_CollectionPropertiesMustNotHaveNullValue(propertyName));
                }

                if (expectedPropertyTypeReference.IsODataPrimitiveTypeKind())
                {
                    // WCF DS allows null values for non-nullable primitive types, so we need to check for a knob which enables this behavior.
                    // See the description of ODataWriterBehavior.AllowNullValuesForNonNullablePrimitiveTypes for more details.
                    if (!expectedPropertyTypeReference.IsNullable && !writerBehavior.AllowNullValuesForNonNullablePrimitiveTypes)
                    {
                        throw new ODataException(Strings.WriterValidationUtils_NonNullablePropertiesMustNotHaveNullValue(propertyName, expectedPropertyTypeReference.ODataFullName()));
                    }
                }
                else if (expectedPropertyTypeReference.IsODataEnumTypeKind() && !expectedPropertyTypeReference.IsNullable)
                {
                    throw new ODataException(Strings.WriterValidationUtils_NonNullablePropertiesMustNotHaveNullValue(propertyName, expectedPropertyTypeReference.ODataFullName()));
                }
                else if (expectedPropertyTypeReference.IsStream())
                {
                    throw new ODataException(Strings.WriterValidationUtils_StreamPropertiesMustNotHaveNullValue(propertyName));
                }
                else if (expectedPropertyTypeReference.IsODataComplexTypeKind())
                {
                    if (ValidationUtils.ShouldValidateComplexPropertyNullValue(model))
                    {
                        IEdmComplexTypeReference complexTypeReference = expectedPropertyTypeReference.AsComplex();
                        if (!complexTypeReference.IsNullable)
                        {
                            throw new ODataException(Strings.WriterValidationUtils_NonNullablePropertiesMustNotHaveNullValue(propertyName, expectedPropertyTypeReference.ODataFullName()));
                        }
                    }
                }
            }
        }
        /// <summary>Initializes a new instance of the <see cref="T:Microsoft.OData.Core.ODataMessageWriterSettings" /> class with specified settings.</summary>
        /// <param name="other">The specified settings.</param>
        public ODataMessageWriterSettings(ODataMessageWriterSettings other)
            : base(other)
        {
            ExceptionUtils.CheckArgumentNotNull(other, "other");

            this.acceptCharSets = other.acceptCharSets;
            this.acceptMediaTypes = other.acceptMediaTypes;
            this.PayloadBaseUri = other.PayloadBaseUri;
            this.DisableMessageStreamDisposal = other.DisableMessageStreamDisposal;
            this.format = other.format;
            this.useFormat = other.useFormat;
            this.Version = other.Version;
            this.JsonPCallback = other.JsonPCallback;
            this.shouldIncludeAnnotation = other.shouldIncludeAnnotation;
            this.AutoComputePayloadMetadataInJson = other.AutoComputePayloadMetadataInJson;
            this.UseKeyAsSegment = other.UseKeyAsSegment;
            this.alwaysUseDefaultXmlNamespaceForRootElement = other.alwaysUseDefaultXmlNamespaceForRootElement;
            this.ODataUri = other.ODataUri;

            // NOTE: writer behavior is immutable; copy by reference is ok.
            this.writerBehavior = other.writerBehavior;
            this.EnableAtom = other.EnableAtom;
            this.EnableFullValidation = other.EnableFullValidation;
            this.mediaTypeResolver = other.mediaTypeResolver;
        }
 /// <summary>Initializes a new instance of the <see cref="T:Microsoft.OData.Core.ODataMessageWriterSettings" /> class with default settings. </summary>
 public ODataMessageWriterSettings()
     : base()
 {
     // Create the default writer behavior
     this.writerBehavior = ODataWriterBehavior.DefaultBehavior;
     this.EnableAtom = false;
     this.EnableFullValidation = true;
     this.mediaTypeResolver = null;
 }
 /// <summary>Enables the WCF data services client behavior.</summary>
 public void EnableWcfDataServicesClientBehavior()
 {
     this.writerBehavior = ODataWriterBehavior.CreateWcfDataServicesClientBehavior();
 }
 /// <summary>Specifies whether the WCF data services server behavior is enabled.</summary>
 public void EnableODataServerBehavior()
 {
     // We have to reset the ATOM entry XML customization since in the server behavior no atom entry customization is used.
     this.writerBehavior = ODataWriterBehavior.CreateODataServerBehavior();
 }
 /// <summary>Enables the <see cref="T:Microsoft.OData.Core.ODataMessageWriterSettings" /> default behavior.</summary>
 public void EnableDefaultBehavior()
 {
     this.writerBehavior = ODataWriterBehavior.DefaultBehavior;
 }
 /// <summary>
 /// Validates that the expected property allows null value.
 /// </summary>
 /// <param name="expectedPropertyTypeReference">The expected property type or null if we don't have any.</param>
 /// <param name="propertyName">The name of the property.</param>
 /// <param name="writerBehavior">The <see cref="ODataWriterBehavior"/> instance controlling the behavior of the writer.</param>
 /// <param name="model">The model to use to get the OData version.</param>
 public void ValidateNullPropertyValue(IEdmTypeReference expectedPropertyTypeReference, string propertyName, ODataWriterBehavior writerBehavior, IEdmModel model)
 {
 }
Ejemplo n.º 10
0
 /// <summary>Enables the WCF data services client behavior.</summary>
 public void EnableWcfDataServicesClientBehavior()
 {
     this.writerBehavior = ODataWriterBehavior.CreateWcfDataServicesClientBehavior();
 }
Ejemplo n.º 11
0
 /// <summary>Specifies whether the WCF data services server behavior is enabled.</summary>
 public void EnableODataServerBehavior()
 {
     // We have to reset the ATOM entry XML customization since in the server behavior no atom entry customization is used.
     this.writerBehavior = ODataWriterBehavior.CreateODataServerBehavior();
 }
Ejemplo n.º 12
0
 /// <summary>Enables the <see cref="T:Microsoft.OData.Core.ODataMessageWriterSettings" /> default behavior.</summary>
 public void EnableDefaultBehavior()
 {
     this.writerBehavior = ODataWriterBehavior.DefaultBehavior;
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Validates a null collection item against the expected type.
 /// </summary>
 /// <param name="expectedItemType">The expected item type or null if no expected item type exists.</param>
 /// <param name="writerBehavior">The <see cref="ODataWriterBehavior"/> instance controlling the behavior of the writer.</param>
 internal static void ValidateNullCollectionItem(IEdmTypeReference expectedItemType, ODataWriterBehavior writerBehavior)
 {
     if (expectedItemType != null)
     {
         if (expectedItemType.IsODataPrimitiveTypeKind())
         {
             // WCF DS allows null values for non-nullable primitive types, so we need to check for a knob which enables this behavior.
             // See the description of ODataWriterBehavior.AllowNullValuesForNonNullablePrimitiveTypes for more details.
             if (!expectedItemType.IsNullable && !writerBehavior.AllowNullValuesForNonNullablePrimitiveTypes)
             {
                 throw new ODataException(Strings.ValidationUtils_NullCollectionItemForNonNullableType(expectedItemType.FullName()));
             }
         }
     }
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Validates a null collection item against the expected type.
 /// </summary>
 /// <param name="expectedItemType">The expected item type or null if no expected item type exists.</param>
 /// <param name="writerBehavior">The <see cref="ODataWriterBehavior"/> instance controlling the behavior of the writer.</param>
 internal static void ValidateNullCollectionItem(IEdmTypeReference expectedItemType, ODataWriterBehavior writerBehavior)
 {
     if (expectedItemType != null)
     {
         if (expectedItemType.IsODataPrimitiveTypeKind())
         {
             // WCF DS allows null values for non-nullable primitive types, so we need to check for a knob which enables this behavior.
             // See the description of ODataWriterBehavior.AllowNullValuesForNonNullablePrimitiveTypes for more details.
             if (!expectedItemType.IsNullable && !writerBehavior.AllowNullValuesForNonNullablePrimitiveTypes)
             {
                 throw new ODataException(Strings.ValidationUtils_NullCollectionItemForNonNullableType(expectedItemType.ODataFullName()));
             }
         }
     }
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Validates that the expected property allows null value.
        /// </summary>
        /// <param name="expectedPropertyTypeReference">The expected property type or null if we don't have any.</param>
        /// <param name="propertyName">The name of the property.</param>
        /// <param name="writerBehavior">The <see cref="ODataWriterBehavior"/> instance controlling the behavior of the writer.</param>
        /// <param name="model">The model to use to get the OData version.</param>
        /// <param name="bypassValidation">Bypass the validation if it is true.</param>
        internal static void ValidateNullPropertyValue(IEdmTypeReference expectedPropertyTypeReference, string propertyName, ODataWriterBehavior writerBehavior, IEdmModel model, bool bypassValidation = false)
        {
            Debug.Assert(writerBehavior != null, "writerBehavior != null");
            Debug.Assert(model != null, "For null validation, model is required.");

            if (bypassValidation)
            {
                return;
            }
            
            if (expectedPropertyTypeReference != null)
            {
                if (expectedPropertyTypeReference.IsNonEntityCollectionType())
                {
                    throw new ODataException(Strings.WriterValidationUtils_CollectionPropertiesMustNotHaveNullValue(propertyName));
                }

                if (expectedPropertyTypeReference.IsODataPrimitiveTypeKind())
                {
                    // WCF DS allows null values for non-nullable primitive types, so we need to check for a knob which enables this behavior.
                    // See the description of ODataWriterBehavior.AllowNullValuesForNonNullablePrimitiveTypes for more details.
                    if (!expectedPropertyTypeReference.IsNullable && !writerBehavior.AllowNullValuesForNonNullablePrimitiveTypes)
                    {
                        throw new ODataException(Strings.WriterValidationUtils_NonNullablePropertiesMustNotHaveNullValue(propertyName, expectedPropertyTypeReference.ODataFullName()));
                    }
                }
                else if (expectedPropertyTypeReference.IsODataEnumTypeKind() && !expectedPropertyTypeReference.IsNullable)
                {
                    throw new ODataException(Strings.WriterValidationUtils_NonNullablePropertiesMustNotHaveNullValue(propertyName, expectedPropertyTypeReference.ODataFullName()));
                }
                else if (expectedPropertyTypeReference.IsStream())
                {
                    throw new ODataException(Strings.WriterValidationUtils_StreamPropertiesMustNotHaveNullValue(propertyName));
                }
                else if (expectedPropertyTypeReference.IsODataComplexTypeKind())
                {
                    if (ValidationUtils.ShouldValidateComplexPropertyNullValue(model))
                    {
                        IEdmComplexTypeReference complexTypeReference = expectedPropertyTypeReference.AsComplex();
                        if (!complexTypeReference.IsNullable)
                        {
                            throw new ODataException(Strings.WriterValidationUtils_NonNullablePropertiesMustNotHaveNullValue(propertyName, expectedPropertyTypeReference.ODataFullName()));
                        }
                    }
                }
            }
        }
Ejemplo n.º 16
0
            /// <summary>
            /// Constructor to create a new entry scope.
            /// </summary>
            /// <param name="entry">The entry for the new scope.</param>
            /// <param name="serializationInfo">The serialization info for the current entry.</param>
            /// <param name="navigationSource">The navigation source we are going to write entities for.</param>
            /// <param name="entityType">The entity type for the entries in the feed to be written (or null if the entity set base type should be used).</param>
            /// <param name="skipWriting">true if the content of the scope to create should not be written.</param>
            /// <param name="writingResponse">true if we are writing a response, false if it's a request.</param>
            /// <param name="writerBehavior">The <see cref="ODataWriterBehavior"/> instance controlling the behavior of the writer.</param>
            /// <param name="selectedProperties">The selected properties of this scope.</param>
            /// <param name="odataUri">The ODataUri info of this scope.</param>
            /// <param name="enableValidation">Enable validation or not.</param>
            internal EntryScope(ODataEntry entry, ODataFeedAndEntrySerializationInfo serializationInfo, IEdmNavigationSource navigationSource, IEdmEntityType entityType, bool skipWriting, bool writingResponse, ODataWriterBehavior writerBehavior, SelectedPropertiesNode selectedProperties, ODataUri odataUri, bool enableValidation = true)
                : base(WriterState.Entry, entry, navigationSource, entityType, skipWriting, selectedProperties, odataUri)
            {
                Debug.Assert(writerBehavior != null, "writerBehavior != null");

                if (entry != null)
                {
                    this.duplicatePropertyNamesChecker = new DuplicatePropertyNamesChecker(writerBehavior.AllowDuplicatePropertyNames, writingResponse, !enableValidation);
                }

                this.serializationInfo = serializationInfo;
            }
Ejemplo n.º 17
0
 /// <summary>
 /// Validates that the expected property allows null value.
 /// </summary>
 /// <param name="expectedPropertyTypeReference">The expected property type or null if we don't have any.</param>
 /// <param name="propertyName">The name of the property.</param>
 /// <param name="writerBehavior">The <see cref="ODataWriterBehavior"/> instance controlling the behavior of the writer.</param>
 /// <param name="model">The model to use to get the OData version.</param>
 public void ValidateNullPropertyValue(IEdmTypeReference expectedPropertyTypeReference, string propertyName, ODataWriterBehavior writerBehavior, IEdmModel model)
 {
 }
 /// <summary>Initializes a new instance of the <see cref="T:Microsoft.OData.Core.ODataMessageWriterSettings" /> class with default settings. </summary>
 public ODataMessageWriterSettings()
 {
     // Create the default writer behavior
     this.writerBehavior = ODataWriterBehavior.DefaultBehavior;
     this.EnableFullValidation = true;
 }