예제 #1
0
        /// <summary>Initializes a new instance of the <see cref="T:Microsoft.Data.OData.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.BaseUri                      = other.BaseUri;
            this.DisableMessageStreamDisposal = other.DisableMessageStreamDisposal;
            this.format              = other.format;
            this.useFormat           = other.useFormat;
            this.Version             = other.Version;
            this.metadataDocumentUri = other.metadataDocumentUri;
            this.atomFormatStartEntryXmlCustomizationCallback = other.atomFormatStartEntryXmlCustomizationCallback;
            this.atomFormatEndEntryXmlCustomizationCallback   = other.atomFormatEndEntryXmlCustomizationCallback;
            this.JsonPCallback                    = other.JsonPCallback;
            this.shouldIncludeAnnotation          = other.shouldIncludeAnnotation;
            this.AutoComputePayloadMetadataInJson = other.AutoComputePayloadMetadataInJson;
            this.AutoGeneratedUrlsShouldPutKeyValueInDedicatedSegment = other.AutoGeneratedUrlsShouldPutKeyValueInDedicatedSegment;
            this.alwaysUseDefaultXmlNamespaceForRootElement           = other.alwaysUseDefaultXmlNamespaceForRootElement;
            this.UndeclaredPropertyBehaviorKinds = other.UndeclaredPropertyBehaviorKinds;

            // NOTE: writer behavior is immutable; copy by reference is ok.
            this.writerBehavior = other.writerBehavior;
        }
예제 #2
0
        /// <summary>
        /// Constructor to create default settings for OData writers.
        /// </summary>
        public ODataMessageWriterSettings()
        {
            // on writing the default value for 'CheckCharacters' is set to true so that we
            // produce valid Xml documents per default.
            this.CheckCharacters = true;

            // Create the default writer behavior
            this.writerBehavior = ODataWriterBehavior.DefaultBehavior;
        }
        /// <summary>
        /// Constructor to create default settings for OData writers.
        /// </summary>
        public ODataMessageWriterSettings()
        {
            // on writing the default value for 'CheckCharacters' is set to true so that we 
            // produce valid Xml documents per default.
            this.CheckCharacters = true;

            // Create the default writer behavior
            this.writerBehavior = ODataWriterBehavior.DefaultBehavior;
        }
예제 #4
0
 public void EnableWcfDataServicesClientBehavior(Func <ODataEntry, XmlWriter, XmlWriter> startEntryXmlCustomizationCallback, Action <ODataEntry, XmlWriter, XmlWriter> endEntryXmlCustomizationCallback, string odataNamespace, string typeScheme)
 {
     ExceptionUtils.CheckArgumentNotNull <string>(odataNamespace, "odataNamespace");
     ExceptionUtils.CheckArgumentNotNull <string>(typeScheme, "typeScheme");
     if (((startEntryXmlCustomizationCallback == null) && (endEntryXmlCustomizationCallback != null)) || ((startEntryXmlCustomizationCallback != null) && (endEntryXmlCustomizationCallback == null)))
     {
         throw new ODataException(Strings.ODataMessageWriterSettings_MessageWriterSettingsXmlCustomizationCallbacksMustBeSpecifiedBoth);
     }
     this.writerBehavior = ODataWriterBehavior.CreateWcfDataServicesClientBehavior(startEntryXmlCustomizationCallback, endEntryXmlCustomizationCallback, odataNamespace, typeScheme);
 }
예제 #5
0
 public void EnableWcfDataServicesClientBehavior(Func<ODataEntry, XmlWriter, XmlWriter> startEntryXmlCustomizationCallback, Action<ODataEntry, XmlWriter, XmlWriter> endEntryXmlCustomizationCallback, string odataNamespace, string typeScheme)
 {
     ExceptionUtils.CheckArgumentNotNull<string>(odataNamespace, "odataNamespace");
     ExceptionUtils.CheckArgumentNotNull<string>(typeScheme, "typeScheme");
     if (((startEntryXmlCustomizationCallback == null) && (endEntryXmlCustomizationCallback != null)) || ((startEntryXmlCustomizationCallback != null) && (endEntryXmlCustomizationCallback == null)))
     {
         throw new ODataException(Strings.ODataMessageWriterSettings_MessageWriterSettingsXmlCustomizationCallbacksMustBeSpecifiedBoth);
     }
     this.writerBehavior = ODataWriterBehavior.CreateWcfDataServicesClientBehavior(startEntryXmlCustomizationCallback, endEntryXmlCustomizationCallback, odataNamespace, typeScheme);
 }
예제 #6
0
 public ODataMessageWriterSettings(ODataMessageWriterSettings settings)
 {
     ExceptionUtils.CheckArgumentNotNull <ODataMessageWriterSettings>(settings, "settings");
     this.acceptCharSets               = settings.acceptCharSets;
     this.acceptMediaTypes             = settings.acceptMediaTypes;
     this.BaseUri                      = settings.BaseUri;
     this.CheckCharacters              = settings.CheckCharacters;
     this.DisableMessageStreamDisposal = settings.DisableMessageStreamDisposal;
     this.format         = settings.format;
     this.Indent         = settings.Indent;
     this.messageQuotas  = new ODataMessageQuotas(settings.MessageQuotas);
     this.useFormat      = settings.useFormat;
     this.Version        = settings.Version;
     this.writerBehavior = settings.writerBehavior;
 }
예제 #7
0
 public ODataMessageWriterSettings(ODataMessageWriterSettings settings)
 {
     ExceptionUtils.CheckArgumentNotNull<ODataMessageWriterSettings>(settings, "settings");
     this.acceptCharSets = settings.acceptCharSets;
     this.acceptMediaTypes = settings.acceptMediaTypes;
     this.BaseUri = settings.BaseUri;
     this.CheckCharacters = settings.CheckCharacters;
     this.DisableMessageStreamDisposal = settings.DisableMessageStreamDisposal;
     this.format = settings.format;
     this.Indent = settings.Indent;
     this.messageQuotas = new ODataMessageQuotas(settings.MessageQuotas);
     this.useFormat = settings.useFormat;
     this.Version = settings.Version;
     this.writerBehavior = settings.writerBehavior;
 }
예제 #8
0
        public void EnableWcfDataServicesClientBehavior(
            Func <ODataEntry, XmlWriter, XmlWriter> startEntryXmlCustomizationCallback,
            Action <ODataEntry, XmlWriter, XmlWriter> endEntryXmlCustomizationCallback,
            string odataNamespace,
            string typeScheme)
        {
            ExceptionUtils.CheckArgumentNotNull(odataNamespace, "odataNamespace");
            ExceptionUtils.CheckArgumentNotNull(typeScheme, "typeScheme");

            this.SetAtomEntryXmlCustomization(startEntryXmlCustomizationCallback, endEntryXmlCustomizationCallback);

            this.writerBehavior = ODataWriterBehavior.CreateWcfDataServicesClientBehavior(
                odataNamespace,
                typeScheme);
        }
예제 #9
0
 private static string CreateDateTimeStringValue(object propertyValue, ODataWriterBehavior writerBehavior)
 {
     if (propertyValue == null)
     {
         propertyValue = DateTimeOffset.Now;
     }
     if (propertyValue is DateTime)
     {
         propertyValue = new DateTimeOffset((DateTime) propertyValue);
     }
     if (propertyValue is DateTimeOffset)
     {
         return ODataAtomConvert.ToAtomString((DateTimeOffset) propertyValue);
     }
     return EpmWriterUtils.GetPropertyValueAsText(propertyValue);
 }
예제 #10
0
 private static DateTimeOffset CreateDateTimeValue(object propertyValue, SyndicationItemProperty targetProperty, ODataWriterBehavior writerBehavior)
 {
     DateTimeOffset offset;
     DateTime time;
     if (propertyValue == null)
     {
         return DateTimeOffset.Now;
     }
     if (propertyValue is DateTimeOffset)
     {
         return (DateTimeOffset) propertyValue;
     }
     if (propertyValue is DateTime)
     {
         return new DateTimeOffset((DateTime) propertyValue);
     }
     string input = propertyValue as string;
     if (input == null)
     {
         DateTimeOffset offset2;
         try
         {
             offset2 = new DateTimeOffset(Convert.ToDateTime(propertyValue, CultureInfo.InvariantCulture));
         }
         catch (Exception exception)
         {
             if (!ExceptionUtils.IsCatchableExceptionType(exception))
             {
                 throw;
             }
             throw new ODataException(Microsoft.Data.OData.Strings.EpmSyndicationWriter_DateTimePropertyCanNotBeConverted(targetProperty.ToString()));
         }
         return offset2;
     }
     if (DateTimeOffset.TryParse(input, out offset))
     {
         return offset;
     }
     if (!DateTime.TryParse(input, out time))
     {
         throw new ODataException(Microsoft.Data.OData.Strings.EpmSyndicationWriter_DateTimePropertyCanNotBeConverted(targetProperty.ToString()));
     }
     return new DateTimeOffset(time);
 }
예제 #11
0
        /// <summary>
        /// Copy constructor to create a copy of the settings for OData writers.
        /// </summary>
        /// <param name="settings">Settings to create a copy from</param>
        public ODataMessageWriterSettings(ODataMessageWriterSettings settings)
        {
            ExceptionUtils.CheckArgumentNotNull(settings, "settings");

            this.acceptCharSets               = settings.acceptCharSets;
            this.acceptMediaTypes             = settings.acceptMediaTypes;
            this.BaseUri                      = settings.BaseUri;
            this.CheckCharacters              = settings.CheckCharacters;
            this.DisableMessageStreamDisposal = settings.DisableMessageStreamDisposal;
            this.format        = settings.format;
            this.Indent        = settings.Indent;
            this.messageQuotas = new ODataMessageQuotas(settings.MessageQuotas);
            this.useFormat     = settings.useFormat;
            this.Version       = settings.Version;
            this.atomFormatStartEntryXmlCustomizationCallback = settings.atomFormatStartEntryXmlCustomizationCallback;
            this.atomFormatEndEntryXmlCustomizationCallback   = settings.atomFormatEndEntryXmlCustomizationCallback;

            // NOTE: writer behavior is immutable; copy by reference is ok.
            this.writerBehavior = settings.writerBehavior;
        }
 /// <summary>
 /// Enables the default behavior of the OData library.
 /// </summary>
 public void EnableDefaultBehavior()
 {
     // We have to reset the ATOM entry XML customization since in the default behavior no atom entry customization is used.
     this.SetAtomEntryXmlCustomization(null, null);
     this.writerBehavior = ODataWriterBehavior.DefaultBehavior;
 }
예제 #13
0
            /// <summary>
            /// Constructor to create a new entry scope.
            /// </summary>
            /// <param name="entry">The entry for the new scope.</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>
            internal EntryScope(ODataEntry entry, bool skipWriting, bool writingResponse, ODataWriterBehavior writerBehavior)
                : base(WriterState.Entry, entry, skipWriting)
            {
                DebugUtils.CheckNoExternalCallers();
                Debug.Assert(writerBehavior != null, "writerBehavior != null");

                if (entry != null)
                {
                    this.duplicatePropertyNamesChecker = new DuplicatePropertyNamesChecker(writerBehavior.AllowDuplicatePropertyNames, writingResponse);
                }
            }
예제 #14
0
        /// <summary>
        /// Validates that the expected property allows null value.
        /// </summary>
        /// <param name="expectedProperty">The metadata for the expected 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 data service version.</param>
        internal static void ValidateNullPropertyValue(IEdmProperty expectedProperty, ODataWriterBehavior writerBehavior, IEdmModel model)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(writerBehavior != null, "writerBehavior != null");
            Debug.Assert(model != null, "For null validation, model is required.");

            if (expectedProperty != null)
            {
                IEdmTypeReference propertyTypeReference = expectedProperty.Type;
                if (propertyTypeReference.IsNonEntityODataCollectionTypeKind())
                {
                    throw new ODataException(Strings.WriterValidationUtils_CollectionPropertiesMustNotHaveNullValue(expectedProperty.Name));
                }

                if (propertyTypeReference.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 (!propertyTypeReference.IsNullable && !writerBehavior.AllowNullValuesForNonNullablePrimitiveTypes)
                    {
                        throw new ODataException(Strings.WriterValidationUtils_NonNullablePropertiesMustNotHaveNullValue(expectedProperty.Name, expectedProperty.Type.ODataFullName()));
                    }
                }
                else if (propertyTypeReference.IsStream())
                {
                    throw new ODataException(Strings.WriterValidationUtils_StreamPropertiesMustNotHaveNullValue(expectedProperty.Name));
                }
                else if (propertyTypeReference.IsODataComplexTypeKind())
                {
                    if (ValidationUtils.ShouldValidateComplexPropertyNullValue(model))
                    {
                        IEdmComplexTypeReference complexTypeReference = propertyTypeReference.AsComplex();
                        if (!complexTypeReference.IsNullable)
                        {
                            throw new ODataException(Strings.WriterValidationUtils_NonNullablePropertiesMustNotHaveNullValue(expectedProperty.Name, expectedProperty.Type.ODataFullName()));
                        }
                    }
                }
            }
        }
예제 #15
0
 /// <summary>
 /// Enables the behavior of the WCF Data Services server.
 /// </summary>
 /// <param name="usesV1Provider">true if the server uses a V1 provider; otherwise false.</param>
 public void EnableWcfDataServicesServerBehavior(bool usesV1Provider)
 {
     // We have to reset the ATOM entry XML customization since in the server behavior no atom entry customization is used.
     this.SetAtomEntryXmlCustomization(null, null);
     this.writerBehavior = ODataWriterBehavior.CreateWcfDataServicesServerBehavior(usesV1Provider);
 }
예제 #16
0
 public void EnableDefaultBehavior()
 {
     this.writerBehavior = ODataWriterBehavior.DefaultBehavior;
 }
예제 #17
0
 public ODataMessageWriterSettings()
 {
     this.CheckCharacters = true;
     this.writerBehavior = ODataWriterBehavior.DefaultBehavior;
 }
예제 #18
0
 internal EntryScope(ODataEntry entry, bool skipWriting, bool writingResponse, ODataWriterBehavior writerBehavior) : base(ODataWriterCore.WriterState.Entry, entry, skipWriting)
 {
     if (entry != null)
     {
         this.duplicatePropertyNamesChecker = new Microsoft.Data.OData.DuplicatePropertyNamesChecker(writerBehavior.AllowDuplicatePropertyNames, writingResponse);
     }
 }
예제 #19
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)
        {
            DebugUtils.CheckNoExternalCallers();

            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()));
                    }
                }
            }
        }
예제 #20
0
 public void EnableWcfDataServicesServerBehavior(bool usesV1Provider)
 {
     this.writerBehavior = ODataWriterBehavior.CreateWcfDataServicesServerBehavior(usesV1Provider);
 }
예제 #21
0
 internal static void ValidateNullCollectionItem(IEdmTypeReference expectedItemType, ODataWriterBehavior writerBehavior)
 {
     if (((expectedItemType != null) && expectedItemType.IsODataPrimitiveTypeKind()) && (!expectedItemType.IsNullable && !writerBehavior.AllowNullValuesForNonNullablePrimitiveTypes))
     {
         throw new ODataException(Microsoft.Data.OData.Strings.ValidationUtils_NullCollectionItemForNonNullableType(expectedItemType.ODataFullName()));
     }
 }
예제 #22
0
 internal static void ValidateNullPropertyValue(IEdmProperty expectedProperty, ODataWriterBehavior writerBehavior, IEdmModel model)
 {
     if (expectedProperty != null)
     {
         IEdmTypeReference type = expectedProperty.Type;
         if (type.IsNonEntityODataCollectionTypeKind())
         {
             throw new ODataException(Microsoft.Data.OData.Strings.WriterValidationUtils_CollectionPropertiesMustNotHaveNullValue(expectedProperty.Name));
         }
         if (type.IsODataPrimitiveTypeKind())
         {
             if (!type.IsNullable && !writerBehavior.AllowNullValuesForNonNullablePrimitiveTypes)
             {
                 throw new ODataException(Microsoft.Data.OData.Strings.WriterValidationUtils_NonNullablePropertiesMustNotHaveNullValue(expectedProperty.Name, expectedProperty.Type.ODataFullName()));
             }
         }
         else
         {
             if (type.IsStream())
             {
                 throw new ODataException(Microsoft.Data.OData.Strings.WriterValidationUtils_StreamPropertiesMustNotHaveNullValue(expectedProperty.Name));
             }
             if ((type.IsODataComplexTypeKind() && ValidationUtils.ShouldValidateComplexPropertyNullValue(model)) && !type.AsComplex().IsNullable)
             {
                 throw new ODataException(Microsoft.Data.OData.Strings.WriterValidationUtils_NonNullablePropertiesMustNotHaveNullValue(expectedProperty.Name, expectedProperty.Type.ODataFullName()));
             }
         }
     }
 }
예제 #23
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)
        {
            DebugUtils.CheckNoExternalCallers();

            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()));
                    }
                }
            }
        }
예제 #24
0
 internal static void ValidateNullPropertyValue(IEdmProperty expectedProperty, ODataWriterBehavior writerBehavior, IEdmModel model)
 {
     if (expectedProperty != null)
     {
         IEdmTypeReference type = expectedProperty.Type;
         if (type.IsNonEntityODataCollectionTypeKind())
         {
             throw new ODataException(Microsoft.Data.OData.Strings.WriterValidationUtils_CollectionPropertiesMustNotHaveNullValue(expectedProperty.Name));
         }
         if (type.IsODataPrimitiveTypeKind())
         {
             if (!type.IsNullable && !writerBehavior.AllowNullValuesForNonNullablePrimitiveTypes)
             {
                 throw new ODataException(Microsoft.Data.OData.Strings.WriterValidationUtils_NonNullablePropertiesMustNotHaveNullValue(expectedProperty.Name, expectedProperty.Type.ODataFullName()));
             }
         }
         else
         {
             if (type.IsStream())
             {
                 throw new ODataException(Microsoft.Data.OData.Strings.WriterValidationUtils_StreamPropertiesMustNotHaveNullValue(expectedProperty.Name));
             }
             if ((type.IsODataComplexTypeKind() && ValidationUtils.ShouldValidateComplexPropertyNullValue(model)) && !type.AsComplex().IsNullable)
             {
                 throw new ODataException(Microsoft.Data.OData.Strings.WriterValidationUtils_NonNullablePropertiesMustNotHaveNullValue(expectedProperty.Name, expectedProperty.Type.ODataFullName()));
             }
         }
     }
 }
 /// <summary>
 /// Enables the behavior of the WCF Data Services server.
 /// </summary>
 /// <param name="usesV1Provider">true if the server uses a V1 provider; otherwise false.</param>
 public void EnableWcfDataServicesServerBehavior(bool usesV1Provider)
 {
     // We have to reset the ATOM entry XML customization since in the server behavior no atom entry customization is used.
     this.SetAtomEntryXmlCustomization(null, null);
     this.writerBehavior = ODataWriterBehavior.CreateWcfDataServicesServerBehavior(usesV1Provider);
 }
        public void EnableWcfDataServicesClientBehavior(
            Func<ODataEntry, XmlWriter, XmlWriter> startEntryXmlCustomizationCallback,
            Action<ODataEntry, XmlWriter, XmlWriter> endEntryXmlCustomizationCallback,
            string odataNamespace, 
            string typeScheme)
        {
            ExceptionUtils.CheckArgumentNotNull(odataNamespace, "odataNamespace");
            ExceptionUtils.CheckArgumentNotNull(typeScheme, "typeScheme");

            this.SetAtomEntryXmlCustomization(startEntryXmlCustomizationCallback, endEntryXmlCustomizationCallback);

            this.writerBehavior = ODataWriterBehavior.CreateWcfDataServicesClientBehavior(
                odataNamespace,
                typeScheme);
        }
예제 #27
0
 /// <summary>Initializes a new instance of the <see cref="T:Microsoft.Data.OData.ODataMessageWriterSettings" /> class with default settings. </summary>
 public ODataMessageWriterSettings()
     : base()
 {
     // Create the default writer behavior
     this.writerBehavior = ODataWriterBehavior.DefaultBehavior;
 }
        /// <summary>
        /// Copy constructor to create a copy of the settings for OData writers.
        /// </summary>
        /// <param name="settings">Settings to create a copy from</param>
        public ODataMessageWriterSettings(ODataMessageWriterSettings settings)
        {
            ExceptionUtils.CheckArgumentNotNull(settings, "settings");

            this.acceptCharSets = settings.acceptCharSets;
            this.acceptMediaTypes = settings.acceptMediaTypes;
            this.BaseUri = settings.BaseUri;
            this.CheckCharacters = settings.CheckCharacters;
            this.DisableMessageStreamDisposal = settings.DisableMessageStreamDisposal;
            this.format = settings.format;
            this.Indent = settings.Indent;
            this.messageQuotas = new ODataMessageQuotas(settings.MessageQuotas);
            this.useFormat = settings.useFormat;
            this.Version = settings.Version;
            this.atomFormatStartEntryXmlCustomizationCallback = settings.atomFormatStartEntryXmlCustomizationCallback;
            this.atomFormatEndEntryXmlCustomizationCallback = settings.atomFormatEndEntryXmlCustomizationCallback;

            // NOTE: writer behavior is immutable; copy by reference is ok.
            this.writerBehavior = settings.writerBehavior;
        }
예제 #29
0
 internal AtomEntryScope(ODataEntry entry, bool skipWriting, bool writingResponse, ODataWriterBehavior writerBehavior) : base(entry, skipWriting, writingResponse, writerBehavior)
 {
 }
예제 #30
0
 internal EntryScope(ODataEntry entry, bool skipWriting, bool writingResponse, ODataWriterBehavior writerBehavior) : base(ODataWriterCore.WriterState.Entry, entry, skipWriting)
 {
     if (entry != null)
     {
         this.duplicatePropertyNamesChecker = new Microsoft.Data.OData.DuplicatePropertyNamesChecker(writerBehavior.AllowDuplicatePropertyNames, writingResponse);
     }
 }
예제 #31
0
 /// <summary>
 /// Constructor to create a new entry scope.
 /// </summary>
 /// <param name="entry">The entry for the new scope.</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>
 internal AtomEntryScope(ODataEntry entry, bool skipWriting, bool writingResponse, ODataWriterBehavior writerBehavior)
     : base(entry, skipWriting, writingResponse, writerBehavior)
 {
     DebugUtils.CheckNoExternalCallers();
 }
예제 #32
0
        private static DateTimeOffset CreateDateTimeValue(object propertyValue, SyndicationItemProperty targetProperty, ODataWriterBehavior writerBehavior)
        {
            Debug.Assert(
                writerBehavior.FormatBehaviorKind != ODataBehaviorKind.WcfDataServicesClient,
                "CreateDateTimeValue should not be used in WCF DS client mode.");

            if (propertyValue == null)
            {
                return DateTimeOffset.Now;
            }

            if (propertyValue is DateTimeOffset)
            {
                return (DateTimeOffset)propertyValue;
            }

            if (propertyValue is DateTime)
            {
                // DateTimeOffset takes care of DateTimes of Unspecified kind so we won't end up 
                // with datetime without timezone info mapped to atom:updated or atom:published element.
                return new DateTimeOffset((DateTime)propertyValue);
            }

            string stringValue = propertyValue as string;
            if (stringValue != null)
            {
                DateTimeOffset date;
                if (!DateTimeOffset.TryParse(stringValue, out date))
                {
                    DateTime result;
                    if (!DateTime.TryParse(stringValue, out result))
                    {
                        throw new ODataException(o.Strings.EpmSyndicationWriter_DateTimePropertyCanNotBeConverted(targetProperty.ToString()));
                    }

                    return new DateTimeOffset(result);
                }

                return date;
            }

            try
            {
                return new DateTimeOffset(Convert.ToDateTime(propertyValue, CultureInfo.InvariantCulture));
            }
            catch (Exception e)
            {
                if (!ExceptionUtils.IsCatchableExceptionType(e))
                {
                    throw;
                }

                throw new ODataException(o.Strings.EpmSyndicationWriter_DateTimePropertyCanNotBeConverted(targetProperty.ToString()));
            }
        }
예제 #33
0
 /// <summary>
 /// Enables the default behavior of the OData library.
 /// </summary>
 public void EnableDefaultBehavior()
 {
     // We have to reset the ATOM entry XML customization since in the default behavior no atom entry customization is used.
     this.SetAtomEntryXmlCustomization(null, null);
     this.writerBehavior = ODataWriterBehavior.DefaultBehavior;
 }
예제 #34
0
 public ODataMessageWriterSettings()
 {
     this.CheckCharacters = true;
     this.writerBehavior  = ODataWriterBehavior.DefaultBehavior;
 }
예제 #35
0
        private static string CreateDateTimeStringValue(object propertyValue, ODataWriterBehavior writerBehavior)
        {
            Debug.Assert(
                writerBehavior.FormatBehaviorKind == ODataBehaviorKind.WcfDataServicesClient,
                "CreateDateTimeStringValue should only be used in WCF DS client mode.");

            if (propertyValue == null)
            {
                propertyValue = DateTimeOffset.Now;
            }

            if (propertyValue is DateTime)
            {
                // DateTimeOffset takes care of DateTimes of Unspecified kind so we won't end up 
                // with datetime without timezone info mapped to atom:updated or atom:published element.
                propertyValue = new DateTimeOffset((DateTime)propertyValue);
            }

            // For DateTimeOffset values we need to use the ATOM format when translating them
            // to strings since the value will be used in ATOM metadata.
            if (propertyValue is DateTimeOffset)
            {
                return ODataAtomConvert.ToAtomString((DateTimeOffset)propertyValue);
            }

            return EpmWriterUtils.GetPropertyValueAsText(propertyValue);
        }
예제 #36
0
 public void EnableDefaultBehavior()
 {
     this.writerBehavior = ODataWriterBehavior.DefaultBehavior;
 }
예제 #37
0
 internal static void ValidateNullCollectionItem(IEdmTypeReference expectedItemType, ODataWriterBehavior writerBehavior)
 {
     if (((expectedItemType != null) && expectedItemType.IsODataPrimitiveTypeKind()) && (!expectedItemType.IsNullable && !writerBehavior.AllowNullValuesForNonNullablePrimitiveTypes))
     {
         throw new ODataException(Microsoft.Data.OData.Strings.ValidationUtils_NullCollectionItemForNonNullableType(expectedItemType.ODataFullName()));
     }
 }
예제 #38
0
 public void EnableWcfDataServicesServerBehavior(bool usesV1Provider)
 {
     this.writerBehavior = ODataWriterBehavior.CreateWcfDataServicesServerBehavior(usesV1Provider);
 }
예제 #39
0
        /// <summary>
        /// Validates that the expected property allows null value.
        /// </summary>
        /// <param name="expectedProperty">The metadata for the expected 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 data service version.</param>
        internal static void ValidateNullPropertyValue(IEdmProperty expectedProperty, ODataWriterBehavior writerBehavior, IEdmModel model)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(writerBehavior != null, "writerBehavior != null");
            Debug.Assert(model != null, "For null validation, model is required.");

            if (expectedProperty != null)
            {
                IEdmTypeReference propertyTypeReference = expectedProperty.Type;
                if (propertyTypeReference.IsNonEntityODataCollectionTypeKind())
                {
                    throw new ODataException(Strings.WriterValidationUtils_CollectionPropertiesMustNotHaveNullValue(expectedProperty.Name));
                }

                if (propertyTypeReference.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 (!propertyTypeReference.IsNullable && !writerBehavior.AllowNullValuesForNonNullablePrimitiveTypes)
                    {
                        throw new ODataException(Strings.WriterValidationUtils_NonNullablePropertiesMustNotHaveNullValue(expectedProperty.Name, expectedProperty.Type.ODataFullName()));
                    }
                }
                else if (propertyTypeReference.IsStream())
                {
                    throw new ODataException(Strings.WriterValidationUtils_StreamPropertiesMustNotHaveNullValue(expectedProperty.Name));
                }
                else if (propertyTypeReference.IsODataComplexTypeKind())
                {
                    if (ValidationUtils.ShouldValidateComplexPropertyNullValue(model))
                    {
                        IEdmComplexTypeReference complexTypeReference = propertyTypeReference.AsComplex();
                        if (!complexTypeReference.IsNullable)
                        {
                            throw new ODataException(Strings.WriterValidationUtils_NonNullablePropertiesMustNotHaveNullValue(expectedProperty.Name, expectedProperty.Type.ODataFullName()));
                        }
                    }
                }
            }
        }