Ejemplo n.º 1
0
        private void CheckForNavigationLinkWithContent(ODataPayloadKind contentPayloadKind)
        {
            Scope currentScope = this.CurrentScope;

            if ((currentScope.State == WriterState.NavigationLink) || (currentScope.State == WriterState.NavigationLinkWithContent))
            {
                Action action = null;
                ODataNavigationLink currentNavigationLink  = (ODataNavigationLink)currentScope.Item;
                IEdmType            navigationPropertyType = null;
                this.InterceptException(delegate {
                    navigationPropertyType = WriterValidationUtils.ValidateNavigationLink(currentNavigationLink, this.ParentEntryEntityType, new ODataPayloadKind?(contentPayloadKind));
                    ((NavigationLinkScope)this.CurrentScope).NavigationPropertyType = navigationPropertyType;
                });
                if (currentScope.State != WriterState.NavigationLinkWithContent)
                {
                    this.PromoteNavigationLinkScope();
                    if (!this.SkipWriting)
                    {
                        if (action == null)
                        {
                            action = delegate {
                                this.DuplicatePropertyNamesChecker.CheckForDuplicatePropertyNames(currentNavigationLink, contentPayloadKind != ODataPayloadKind.EntityReferenceLink, new bool?(contentPayloadKind == ODataPayloadKind.Feed));
                                this.StartNavigationLinkWithContent(currentNavigationLink);
                            };
                        }
                        this.InterceptException(action);
                    }
                }
                else if (this.outputContext.WritingResponse || (currentNavigationLink.IsCollection != true))
                {
                    this.ThrowODataException(Microsoft.Data.OData.Strings.ODataWriterCore_MultipleItemsInNavigationLinkContent, currentNavigationLink);
                }
            }
            else if (contentPayloadKind == ODataPayloadKind.EntityReferenceLink)
            {
                this.ThrowODataException(Microsoft.Data.OData.Strings.ODataWriterCore_EntityReferenceLinkWithoutNavigationLink, null);
            }
        }
Ejemplo n.º 2
0
        private void WriteEndImplementation()
        {
            this.InterceptException(delegate {
                Scope currentScope = this.CurrentScope;
                switch (currentScope.State)
                {
                case WriterState.Start:
                case WriterState.Completed:
                case WriterState.Error:
                    throw new ODataException(Microsoft.Data.OData.Strings.ODataWriterCore_WriteEndCalledInInvalidState(currentScope.State.ToString()));

                case WriterState.Entry:
                    if (!this.SkipWriting)
                    {
                        ODataEntry entry = (ODataEntry)currentScope.Item;
                        if (entry != null)
                        {
                            WriterValidationUtils.ValidateEntryAtEnd(entry);
                        }
                        this.EndEntry(entry);
                        this.DecreaseEntryDepth();
                    }
                    break;

                case WriterState.Feed:
                    if (!this.SkipWriting)
                    {
                        ODataFeed item = (ODataFeed)currentScope.Item;
                        WriterValidationUtils.ValidateFeedAtEnd(item, !this.outputContext.WritingResponse, this.outputContext.Version);
                        this.EndFeed(item);
                    }
                    break;

                case WriterState.NavigationLink:
                    if (!this.outputContext.WritingResponse)
                    {
                        throw new ODataException(Microsoft.Data.OData.Strings.ODataWriterCore_DeferredLinkInRequest);
                    }
                    if (!this.SkipWriting)
                    {
                        ODataNavigationLink navigationLink = (ODataNavigationLink)currentScope.Item;
                        ((NavigationLinkScope)this.CurrentScope).NavigationPropertyType = WriterValidationUtils.ValidateNavigationLink(navigationLink, this.ParentEntryEntityType, null);
                        this.DuplicatePropertyNamesChecker.CheckForDuplicatePropertyNames(navigationLink, false, navigationLink.IsCollection);
                        this.WriteDeferredNavigationLink(navigationLink);
                    }
                    break;

                case WriterState.NavigationLinkWithContent:
                    if (!this.SkipWriting)
                    {
                        this.EndNavigationLinkWithContent((ODataNavigationLink)currentScope.Item);
                    }
                    break;

                default:
                    throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodes.ODataWriterCore_WriteEnd_UnreachableCodePath));
                }
                this.LeaveScope();
            });
        }