/// <summary>
        /// Writes the metadata properties for an entry which can only occur at the start.
        /// </summary>
        /// <param name="entryState">The entry state for which to write the metadata properties.</param>
        internal void WriteEntryStartMetadataProperties(IODataJsonLightWriterEntryState entryState)
        {
            Debug.Assert(entryState != null, "entryState != null");

            ODataEntry entry = entryState.Entry;

            // Write the "@odata.type": "typename"
            string typeName = this.JsonLightOutputContext.TypeNameOracle.GetEntryTypeNameForWriting(entryState.GetOrCreateTypeContext(this.Model, this.WritingResponse).ExpectedEntityTypeName, entry);
            if (typeName != null)
            {
                this.ODataAnnotationWriter.WriteODataTypeInstanceAnnotation(typeName);
            }

            // Write the "@odata.id": "Entity Id"
            Uri id;
            if (entry.MetadataBuilder.TryGetIdForSerialization(out id))
            {
                this.ODataAnnotationWriter.WriteInstanceAnnotationName(ODataAnnotationNames.ODataId);
                if (id != null && !entry.HasNonComputedId)
                {
                    id = this.MetadataDocumentBaseUri.MakeRelativeUri(id);
                }

                this.JsonWriter.WriteValue(id == null ? null : this.UriToString(id));
            }

            // Write the "@odata.etag": "ETag value"
            string etag = entry.ETag;
            if (etag != null)
            {
                this.ODataAnnotationWriter.WriteInstanceAnnotationName(ODataAnnotationNames.ODataETag);
                this.JsonWriter.WriteValue(etag);
            }
        }
        /// <summary>
        /// Writes the metadata properties for an entry which can only occur at the end.
        /// </summary>
        /// <param name="entryState">The entry state for which to write the metadata properties.</param>
        /// <param name="duplicatePropertyNamesChecker">The duplicate names checker for properties of this entry.</param>
        internal void WriteEntryEndMetadataProperties(IODataJsonLightWriterEntryState entryState, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker)
        {
            Debug.Assert(entryState != null, "entryState != null");

            ODataEntry entry = entryState.Entry;

            var navigationLinkInfo = entry.MetadataBuilder.GetNextUnprocessedNavigationLink();

            while (navigationLinkInfo != null)
            {
                Debug.Assert(entry.MetadataBuilder != null, "entry.MetadataBuilder != null");
                navigationLinkInfo.NavigationLink.MetadataBuilder = entry.MetadataBuilder;

                this.WriteNavigationLinkMetadata(navigationLinkInfo.NavigationLink, duplicatePropertyNamesChecker);
                navigationLinkInfo = entry.MetadataBuilder.GetNextUnprocessedNavigationLink();
            }

            // write "odata.actions" metadata
            IEnumerable <ODataAction> actions = entry.Actions;

            if (actions != null)
            {
                this.WriteOperations(actions.Cast <ODataOperation>(), /*isAction*/ true);
            }

            // write "odata.functions" metadata
            IEnumerable <ODataFunction> functions = entry.Functions;

            if (functions != null)
            {
                this.WriteOperations(functions.Cast <ODataOperation>(), /*isAction*/ false);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Writes the metadata properties for an entry which can only occur at the start.
        /// </summary>
        /// <param name="entryState">The entry state for which to write the metadata properties.</param>
        internal void WriteEntryStartMetadataProperties(IODataJsonLightWriterEntryState entryState)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(entryState != null, "entryState != null");

            ODataEntry entry = entryState.Entry;

            // Write the "odata.type": "typename"
            string typeName = this.JsonLightOutputContext.TypeNameOracle.GetEntryTypeNameForWriting(entryState.GetOrCreateTypeContext(this.Model, this.WritingResponse).ExpectedEntityTypeName, entry);

            if (typeName != null)
            {
                this.JsonWriter.WriteName(ODataAnnotationNames.ODataType);
                this.JsonWriter.WriteValue(typeName);
            }

            // Write the "odata.id": "Entity Id"
            string id = entry.Id;

            if (id != null)
            {
                this.JsonWriter.WriteName(ODataAnnotationNames.ODataId);
                this.JsonWriter.WriteValue(id);
            }

            // Write the "etag": "ETag value"
            string etag = entry.ETag;

            if (etag != null)
            {
                this.JsonWriter.WriteName(ODataAnnotationNames.ODataETag);
                this.JsonWriter.WriteValue(etag);
            }
        }
        /// <summary>
        /// Writes the metadata properties for an entry which can only occur at the start.
        /// </summary>
        /// <param name="entryState">The entry state for which to write the metadata properties.</param>
        internal void WriteEntryStartMetadataProperties(IODataJsonLightWriterEntryState entryState)
        {
            Debug.Assert(entryState != null, "entryState != null");

            ODataEntry entry = entryState.Entry;

            // Write the "@odata.type": "typename"
            string typeName = this.JsonLightOutputContext.TypeNameOracle.GetEntryTypeNameForWriting(entryState.GetOrCreateTypeContext(this.Model, this.WritingResponse).ExpectedEntityTypeName, entry);

            if (typeName != null)
            {
                if (typeName.StartsWith("ODataAggregation.DynamicTypes."))
                {
                    ODataJsonLightWriterUtils.WriteODataIdAnnotation(this.JsonWriter, @"""""");
                }
                else
                {
                    ODataJsonLightWriterUtils.WriteODataTypeInstanceAnnotation(this.JsonWriter, typeName);
                }
            }

            // Write the "@odata.id": "Entity Id"
            Uri id;

            if (entry.MetadataBuilder.TryGetIdForSerialization(out id))
            {
                this.JsonWriter.WriteInstanceAnnotationName(ODataAnnotationNames.ODataId);
                if (id != null && !entry.HasNonComputedId)
                {
                    id = this.MetadataDocumentBaseUri.MakeRelativeUri(id);
                }

                this.JsonWriter.WriteValue(id == null ? null : this.UriToString(id));
            }

            // Write the "@odata.etag": "ETag value"
            string etag = entry.ETag;

            if (etag != null)
            {
                this.JsonWriter.WriteInstanceAnnotationName(ODataAnnotationNames.ODataETag);
                this.JsonWriter.WriteValue(etag);
            }
        }
        /// <summary>
        /// Writes the metadata properties for an entry which can occur both at the start or at the end.
        /// </summary>
        /// <param name="entryState">The entry state for which to write the metadata properties.</param>
        /// <remarks>
        /// This method will only write properties which were not written yet.
        /// </remarks>
        internal void WriteEntryMetadataProperties(IODataJsonLightWriterEntryState entryState)
        {
            Debug.Assert(entryState != null, "entryState != null");

            ODataEntry entry = entryState.Entry;

            // Write the "@odata.editLink": "edit-link-uri"
            Uri editLinkUriValue = entry.EditLink;

            if (editLinkUriValue != null && !entryState.EditLinkWritten)
            {
                this.JsonWriter.WriteInstanceAnnotationName(ODataAnnotationNames.ODataEditLink);
                this.JsonWriter.WriteValue(this.UriToString(
                                               entry.HasNonComputedEditLink
                    ? editLinkUriValue
                    : this.MetadataDocumentBaseUri.MakeRelativeUri(editLinkUriValue)));
                entryState.EditLinkWritten = true;
            }

            // Write the "@odata.readLink": "read-link-uri".
            // If readlink is identical to editlink, don't write readlink.
            Uri readLinkUriValue = entry.ReadLink;

            if (readLinkUriValue != null && readLinkUriValue != editLinkUriValue && !entryState.ReadLinkWritten)
            {
                this.JsonWriter.WriteInstanceAnnotationName(ODataAnnotationNames.ODataReadLink);
                this.JsonWriter.WriteValue(this.UriToString(
                                               entry.HasNonComputedReadLink
                    ? readLinkUriValue
                    : this.MetadataDocumentBaseUri.MakeRelativeUri(readLinkUriValue)));
                entryState.ReadLinkWritten = true;
            }

            // Write MLE metadata
            ODataStreamReferenceValue mediaResource = entry.MediaResource;

            if (mediaResource != null)
            {
                // Write the "@odata.mediaEditLink": "edit-link-uri"
                Uri mediaEditLinkUriValue = mediaResource.EditLink;
                if (mediaEditLinkUriValue != null && !entryState.MediaEditLinkWritten)
                {
                    this.JsonWriter.WriteInstanceAnnotationName(ODataAnnotationNames.ODataMediaEditLink);
                    this.JsonWriter.WriteValue(this.UriToString(
                                                   mediaResource.HasNonComputedEditLink
                        ? mediaEditLinkUriValue
                        : this.MetadataDocumentBaseUri.MakeRelativeUri(mediaEditLinkUriValue)));
                    entryState.MediaEditLinkWritten = true;
                }

                // Write the "@odata.mediaReadLink": "read-link-uri"
                // If mediaReadLink is identical to mediaEditLink, don't write readlink.
                Uri mediaReadLinkUriValue = mediaResource.ReadLink;
                if (mediaReadLinkUriValue != null && mediaReadLinkUriValue != mediaEditLinkUriValue && !entryState.MediaReadLinkWritten)
                {
                    this.JsonWriter.WriteInstanceAnnotationName(ODataAnnotationNames.ODataMediaReadLink);
                    this.JsonWriter.WriteValue(this.UriToString(
                                                   mediaResource.HasNonComputedReadLink
                        ? mediaReadLinkUriValue
                        : this.MetadataDocumentBaseUri.MakeRelativeUri(mediaReadLinkUriValue)));
                    entryState.MediaReadLinkWritten = true;
                }

                // Write the "@odata.mediaContentType": "content/type"
                string mediaContentType = mediaResource.ContentType;
                if (mediaContentType != null && !entryState.MediaContentTypeWritten)
                {
                    this.JsonWriter.WriteInstanceAnnotationName(ODataAnnotationNames.ODataMediaContentType);
                    this.JsonWriter.WriteValue(mediaContentType);
                    entryState.MediaContentTypeWritten = true;
                }

                // Write the "@odata.mediaEtag": "ETAG"
                string mediaETag = mediaResource.ETag;
                if (mediaETag != null && !entryState.MediaETagWritten)
                {
                    this.JsonWriter.WriteInstanceAnnotationName(ODataAnnotationNames.ODataMediaETag);
                    this.JsonWriter.WriteValue(mediaETag);
                    entryState.MediaETagWritten = true;
                }
            }

            // TODO: actions
            // TODO: functions
            // TODO: association links
        }
        /// <summary>
        /// Writes the metadata properties for an entry which can occur both at the start or at the end.
        /// </summary>
        /// <param name="entryState">The entry state for which to write the metadata properties.</param>
        /// <remarks>
        /// This method will only write properties which were not written yet.
        /// </remarks>
        internal void WriteEntryMetadataProperties(IODataJsonLightWriterEntryState entryState)
        {
            Debug.Assert(entryState != null, "entryState != null");

            ODataEntry entry = entryState.Entry;

            // Write the "@odata.editLink": "edit-link-uri"
            Uri editLinkUriValue = entry.EditLink;
            if (editLinkUriValue != null && !entryState.EditLinkWritten)
            {
                this.ODataAnnotationWriter.WriteInstanceAnnotationName(ODataAnnotationNames.ODataEditLink);
                this.JsonWriter.WriteValue(this.UriToString(
                    entry.HasNonComputedEditLink
                    ? editLinkUriValue
                    : this.MetadataDocumentBaseUri.MakeRelativeUri(editLinkUriValue)));
                entryState.EditLinkWritten = true;
            }

            // Write the "@odata.readLink": "read-link-uri".
            // If readlink is identical to editlink, don't write readlink.
            Uri readLinkUriValue = entry.ReadLink;
            if (readLinkUriValue != null && readLinkUriValue != editLinkUriValue && !entryState.ReadLinkWritten)
            {
                this.ODataAnnotationWriter.WriteInstanceAnnotationName(ODataAnnotationNames.ODataReadLink);
                this.JsonWriter.WriteValue(this.UriToString(
                    entry.HasNonComputedReadLink
                    ? readLinkUriValue
                    : this.MetadataDocumentBaseUri.MakeRelativeUri(readLinkUriValue)));
                entryState.ReadLinkWritten = true;
            }

            // Write MLE metadata
            ODataStreamReferenceValue mediaResource = entry.MediaResource;
            if (mediaResource != null)
            {
                // Write the "@odata.mediaEditLink": "edit-link-uri"
                Uri mediaEditLinkUriValue = mediaResource.EditLink;
                if (mediaEditLinkUriValue != null && !entryState.MediaEditLinkWritten)
                {
                    this.ODataAnnotationWriter.WriteInstanceAnnotationName(ODataAnnotationNames.ODataMediaEditLink);
                    this.JsonWriter.WriteValue(this.UriToString(
                        mediaResource.HasNonComputedEditLink
                        ? mediaEditLinkUriValue
                        : this.MetadataDocumentBaseUri.MakeRelativeUri(mediaEditLinkUriValue)));
                    entryState.MediaEditLinkWritten = true;
                }

                // Write the "@odata.mediaReadLink": "read-link-uri"
                // If mediaReadLink is identical to mediaEditLink, don't write readlink.
                Uri mediaReadLinkUriValue = mediaResource.ReadLink;
                if (mediaReadLinkUriValue != null && mediaReadLinkUriValue != mediaEditLinkUriValue && !entryState.MediaReadLinkWritten)
                {
                    this.ODataAnnotationWriter.WriteInstanceAnnotationName(ODataAnnotationNames.ODataMediaReadLink);
                    this.JsonWriter.WriteValue(this.UriToString(
                        mediaResource.HasNonComputedReadLink
                        ? mediaReadLinkUriValue
                        : this.MetadataDocumentBaseUri.MakeRelativeUri(mediaReadLinkUriValue)));
                    entryState.MediaReadLinkWritten = true;
                }

                // Write the "@odata.mediaContentType": "content/type"
                string mediaContentType = mediaResource.ContentType;
                if (mediaContentType != null && !entryState.MediaContentTypeWritten)
                {
                    this.ODataAnnotationWriter.WriteInstanceAnnotationName(ODataAnnotationNames.ODataMediaContentType);
                    this.JsonWriter.WriteValue(mediaContentType);
                    entryState.MediaContentTypeWritten = true;
                }

                // Write the "@odata.mediaEtag": "ETAG"
                string mediaETag = mediaResource.ETag;
                if (mediaETag != null && !entryState.MediaETagWritten)
                {
                    this.ODataAnnotationWriter.WriteInstanceAnnotationName(ODataAnnotationNames.ODataMediaETag);
                    this.JsonWriter.WriteValue(mediaETag);
                    entryState.MediaETagWritten = true;
                }
            }

            // TODO: actions
            // TODO: functions
            // TODO: association links
        }
        /// <summary>
        /// Writes the metadata properties for an entry which can only occur at the end.
        /// </summary>
        /// <param name="entryState">The entry state for which to write the metadata properties.</param>
        /// <param name="duplicatePropertyNamesChecker">The duplicate names checker for properties of this entry.</param>
        internal void WriteEntryEndMetadataProperties(IODataJsonLightWriterEntryState entryState, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker)
        {
            Debug.Assert(entryState != null, "entryState != null");

            ODataEntry entry = entryState.Entry;

            var navigationLinkInfo = entry.MetadataBuilder.GetNextUnprocessedNavigationLink();
            while (navigationLinkInfo != null)
            {
                Debug.Assert(entry.MetadataBuilder != null, "entry.MetadataBuilder != null");
                navigationLinkInfo.NavigationLink.MetadataBuilder = entry.MetadataBuilder;

                this.WriteNavigationLinkMetadata(navigationLinkInfo.NavigationLink, duplicatePropertyNamesChecker);
                navigationLinkInfo = entry.MetadataBuilder.GetNextUnprocessedNavigationLink();
            }

            // write "odata.actions" metadata
            IEnumerable<ODataAction> actions = entry.Actions;
            if (actions != null && actions.Any())
            {
                this.WriteOperations(actions.Cast<ODataOperation>(), /*isAction*/ true);
            }

            // write "odata.functions" metadata
            IEnumerable<ODataFunction> functions = entry.Functions;
            if (functions != null && functions.Any())
            {
                this.WriteOperations(functions.Cast<ODataOperation>(), /*isAction*/ false);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Writes the metadata properties for an entry which can occur both at the start or at the end.
        /// </summary>
        /// <param name="entryState">The entry state for which to write the metadata properties.</param>
        /// <remarks>
        /// This method will only write properties which were not written yet.
        /// </remarks>
        internal void WriteEntryMetadataProperties(IODataJsonLightWriterEntryState entryState)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(entryState != null, "entryState != null");

            ODataEntry entry = entryState.Entry;

            // Write the "odata.editLink": "edit-link-uri"
            Uri editLinkUriValue = entry.EditLink;

            if (editLinkUriValue != null && !entryState.EditLinkWritten)
            {
                this.JsonWriter.WriteName(ODataAnnotationNames.ODataEditLink);
                this.JsonWriter.WriteValue(this.UriToString(editLinkUriValue));
                entryState.EditLinkWritten = true;
            }

            // Write the "odata.readLink": "read-link-uri"
            Uri readLinkUriValue = entry.ReadLink;

            if (readLinkUriValue != null && !entryState.ReadLinkWritten)
            {
                this.JsonWriter.WriteName(ODataAnnotationNames.ODataReadLink);
                this.JsonWriter.WriteValue(this.UriToString(readLinkUriValue));
                entryState.ReadLinkWritten = true;
            }

            // Write MLE metadata
            ODataStreamReferenceValue mediaResource = entry.MediaResource;

            if (mediaResource != null)
            {
                // Write the "odata.mediaEditLink": "edit-link-uri"
                Uri mediaEditLinkUriValue = mediaResource.EditLink;
                if (mediaEditLinkUriValue != null && !entryState.MediaEditLinkWritten)
                {
                    this.JsonWriter.WriteName(ODataAnnotationNames.ODataMediaEditLink);
                    this.JsonWriter.WriteValue(this.UriToString(mediaEditLinkUriValue));
                    entryState.MediaEditLinkWritten = true;
                }

                // Write the "odata.mediaReadLink": "read-link-uri"
                Uri mediaReadLinkUriValue = mediaResource.ReadLink;
                if (mediaReadLinkUriValue != null && !entryState.MediaReadLinkWritten)
                {
                    this.JsonWriter.WriteName(ODataAnnotationNames.ODataMediaReadLink);
                    this.JsonWriter.WriteValue(this.UriToString(mediaReadLinkUriValue));
                    entryState.MediaReadLinkWritten = true;
                }

                // Write the "odata.mediaContentType": "content/type"
                string mediaContentType = mediaResource.ContentType;
                if (mediaContentType != null && !entryState.MediaContentTypeWritten)
                {
                    this.JsonWriter.WriteName(ODataAnnotationNames.ODataMediaContentType);
                    this.JsonWriter.WriteValue(mediaContentType);
                    entryState.MediaContentTypeWritten = true;
                }

                // Write the "odata.mediaETag": "ETAG"
                string mediaETag = mediaResource.ETag;
                if (mediaETag != null && !entryState.MediaETagWritten)
                {
                    this.JsonWriter.WriteName(ODataAnnotationNames.ODataMediaETag);
                    this.JsonWriter.WriteValue(mediaETag);
                    entryState.MediaETagWritten = true;
                }
            }

            // TODO: actions
            // TODO: functions
            // TODO: association links
        }