/// <summary>
        /// Verify that the transition from the current state into new state is valid .
        /// </summary>
        /// <param name="newState">The new writer state to transition into.</param>
        private void ValidateTransition(WriterState newState)
        {
            if (!IsErrorState(this.State) && IsErrorState(newState))
            {
                // we can always transition into an error state if we are not already in an error state
                return;
            }

            switch (this.State)
            {
                case WriterState.Start:
                    if (newState != WriterState.DeltaFeed)
                    {
                        throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromStart(this.State.ToString(), newState.ToString()));
                    }

                    break;
                case WriterState.DeltaEntry:
                case WriterState.DeltaDeletedEntry:
                case WriterState.DeltaLink:
                case WriterState.DeltaDeletedLink:
                    if (this.CurrentScope.Item == null)
                    {
                        throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromNullEntry(this.State.ToString(), newState.ToString()));
                    }

                    break;
                case WriterState.DeltaFeed:
                    if (newState != WriterState.DeltaEntry && newState != WriterState.DeltaDeletedEntry &&
                        newState != WriterState.DeltaLink && newState != WriterState.DeltaDeletedLink)
                    {
                        throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromFeed(this.State.ToString(), newState.ToString()));
                    }

                    break;
                case WriterState.Completed:
                    // we should never see a state transition when in state 'Completed'
                    throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromCompleted(this.State.ToString(), newState.ToString()));
                case WriterState.Error:
                    if (newState != WriterState.Error)
                    {
                        // No more state transitions once we are in error state except for the fatal error
                        throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromError(this.State.ToString(), newState.ToString()));
                    }

                    break;
                default:
                    throw new ODataException(Strings.General_InternalError(InternalErrorCodes.ODataWriterCore_ValidateTransition_UnreachableCodePath));
            }
        }
Esempio n. 2
0
        private void ValidateTransition(WriterState newState)
        {
            if (!IsErrorState(this.State) && IsErrorState(newState))
            {
                // we can always transition into an error state if we are not already in an error state
                return;
            }

            switch (this.State)
            {
                case WriterState.Start:
                    if (newState != WriterState.Feed && newState != WriterState.Entry)
                    {
                        throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromStart(this.State.ToString(), newState.ToString()));
                    }

                    if (newState == WriterState.Feed && !this.writingFeed)
                    {
                        throw new ODataException(Strings.ODataWriterCore_CannotWriteTopLevelFeedWithEntryWriter);
                    }

                    if (newState == WriterState.Entry && this.writingFeed)
                    {
                        throw new ODataException(Strings.ODataWriterCore_CannotWriteTopLevelEntryWithFeedWriter);
                    }

                    break;
                case WriterState.Entry:
                    {
                        if (this.CurrentScope.Item == null)
                        {
                            throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromNullEntry(this.State.ToString(), newState.ToString()));
                        }

                        if (newState != WriterState.NavigationLink)
                        {
                            throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromEntry(this.State.ToString(), newState.ToString()));
                        }
                    }

                    break;
                case WriterState.Feed:
                    if (newState != WriterState.Entry)
                    {
                        throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromFeed(this.State.ToString(), newState.ToString()));
                    }

                    break;
                case WriterState.NavigationLink:
                    if (newState != WriterState.NavigationLinkWithContent)
                    {
                        throw new ODataException(Strings.ODataWriterCore_InvalidStateTransition(this.State.ToString(), newState.ToString()));
                    }

                    break;
                case WriterState.NavigationLinkWithContent:
                    if (newState != WriterState.Feed && newState != WriterState.Entry)
                    {
                        throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromExpandedLink(this.State.ToString(), newState.ToString()));
                    }

                    break;
                case WriterState.Completed:
                    // we should never see a state transition when in state 'Completed'
                    throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromCompleted(this.State.ToString(), newState.ToString()));
                case WriterState.Error:
                    if (newState != WriterState.Error)
                    {
                        // No more state transitions once we are in error state except for the fatal error
                        throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromError(this.State.ToString(), newState.ToString()));
                    }

                    break;
                default:
                    throw new ODataException(Strings.General_InternalError(InternalErrorCodes.ODataWriterCore_ValidateTransition_UnreachableCodePath));
            }
        }
Esempio n. 3
0
        private void ValidateTransition(WriterState newState)
        {
            if (!IsErrorState(this.State) && IsErrorState(newState) &&
                !(this.State == WriterState.Completed && newState == WriterState.Error))
            {
                // we can always transition into an error state if we are not already in an error state
                // unless we're in a completed state trying to write an error (we can't write error after the payload
                // was finished as it might introduce another top-level element in XML)
                return;
            }

            switch (this.State)
            {
            case WriterState.Start:
                if (newState != WriterState.Feed && newState != WriterState.Entry)
                {
                    throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromStart(this.State.ToString(), newState.ToString()));
                }

                if (newState == WriterState.Feed && !this.writingFeed)
                {
                    throw new ODataException(Strings.ODataWriterCore_CannotWriteTopLevelFeedWithEntryWriter);
                }

                if (newState == WriterState.Entry && this.writingFeed)
                {
                    throw new ODataException(Strings.ODataWriterCore_CannotWriteTopLevelEntryWithFeedWriter);
                }

                break;

            case WriterState.Entry:
                if (newState != WriterState.Link)
                {
                    throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromEntry(this.State.ToString(), newState.ToString()));
                }

                break;

            case WriterState.Feed:
                if (newState != WriterState.Entry)
                {
                    throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromFeed(this.State.ToString(), newState.ToString()));
                }

                break;

            case WriterState.Link:
                if (newState != WriterState.ExpandedLink)
                {
                    throw new ODataException(Strings.ODataWriterCore_InvalidStateTransition(this.State.ToString(), newState.ToString()));
                }

                break;

            case WriterState.ExpandedLink:
                if (newState != WriterState.Feed && newState != WriterState.Entry)
                {
                    throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromExpandedLink(this.State.ToString(), newState.ToString()));
                }

                break;

            case WriterState.Completed:
                // we should never see a state transition when in state 'Completed'
                throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromCompleted(this.State.ToString(), newState.ToString()));

            case WriterState.ODataExceptionThrown:
                if (!IsErrorState(newState))
                {
                    // once an exception has been thrown we only allow clients to write an error (or we detect a fatal exception)
                    throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromODataExceptionThrown(this.State.ToString(), newState.ToString()));
                }

                break;

            case WriterState.Error:
                // No more state transitions once we are in error state except for the fatal error
                if (newState != WriterState.FatalExceptionThrown)
                {
                    throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromError(this.State.ToString(), newState.ToString()));
                }

                break;

            case WriterState.FatalExceptionThrown:
                if (newState != WriterState.FatalExceptionThrown)
                {
                    throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromFatalExceptionThrown(this.State.ToString(), newState.ToString()));
                }

                break;

            default:
                throw new ODataException(Strings.General_InternalError(InternalErrorCodes.ODataWriterCore_ValidateTransition_UnreachableCodePath));
            }
        }
Esempio n. 4
0
        private void ValidateTransition(WriterState newState)
        {
            if (!IsErrorState(this.State) && IsErrorState(newState) && 
                !(this.State == WriterState.Completed && newState == WriterState.Error))
            {
                // we can always transition into an error state if we are not already in an error state
                // unless we're in a completed state trying to write an error (we can't write error after the payload
                // was finished as it might introduce another top-level element in XML)
                return;
            }

            switch (this.State)
            {
                case WriterState.Start:
                    if (newState != WriterState.Feed && newState != WriterState.Entry)
                    {
                        throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromStart(this.State.ToString(), newState.ToString()));
                    }

                    if (newState == WriterState.Feed && !this.writingFeed)
                    {
                        throw new ODataException(Strings.ODataWriterCore_CannotWriteTopLevelFeedWithEntryWriter);
                    }

                    if (newState == WriterState.Entry && this.writingFeed)
                    {
                        throw new ODataException(Strings.ODataWriterCore_CannotWriteTopLevelEntryWithFeedWriter);
                    }

                    break;
                case WriterState.Entry:
                    if (newState != WriterState.Link)
                    {
                        throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromEntry(this.State.ToString(), newState.ToString()));
                    }

                    break;
                case WriterState.Feed:
                    if (newState != WriterState.Entry)
                    {
                        throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromFeed(this.State.ToString(), newState.ToString()));
                    }

                    break;
                case WriterState.Link:
                    if (newState != WriterState.ExpandedLink)
                    {
                        throw new ODataException(Strings.ODataWriterCore_InvalidStateTransition(this.State.ToString(), newState.ToString()));
                    }

                    break;
                case WriterState.ExpandedLink:
                    if (newState != WriterState.Feed && newState != WriterState.Entry)
                    {
                        throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromExpandedLink(this.State.ToString(), newState.ToString()));
                    }

                    break;
                case WriterState.Completed:
                    // we should never see a state transition when in state 'Completed'
                    throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromCompleted(this.State.ToString(), newState.ToString()));
                case WriterState.ODataExceptionThrown:
                    if (!IsErrorState(newState))
                    {
                        // once an exception has been thrown we only allow clients to write an error (or we detect a fatal exception)
                        throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromODataExceptionThrown(this.State.ToString(), newState.ToString()));
                    }

                    break;
                case WriterState.Error:
                    // No more state transitions once we are in error state except for the fatal error
                    if (newState != WriterState.FatalExceptionThrown)
                    {
                        throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromError(this.State.ToString(), newState.ToString()));
                    }

                    break;
                case WriterState.FatalExceptionThrown:
                    if (newState != WriterState.FatalExceptionThrown)
                    {
                        throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromFatalExceptionThrown(this.State.ToString(), newState.ToString()));
                    }

                    break;
                default:
                    throw new ODataException(Strings.General_InternalError(InternalErrorCodes.ODataWriterCore_ValidateTransition_UnreachableCodePath));
            }
        }
Esempio n. 5
0
        private void ValidateTransition(WriterState newState)
        {
            if (IsErrorState(this.State) || !IsErrorState(newState))
            {
                switch (this.State)
                {
                    case WriterState.Start:
                        if ((newState != WriterState.Feed) && (newState != WriterState.Entry))
                        {
                            throw new ODataException(Microsoft.Data.OData.Strings.ODataWriterCore_InvalidTransitionFromStart(this.State.ToString(), newState.ToString()));
                        }
                        if ((newState == WriterState.Feed) && !this.writingFeed)
                        {
                            throw new ODataException(Microsoft.Data.OData.Strings.ODataWriterCore_CannotWriteTopLevelFeedWithEntryWriter);
                        }
                        if ((newState != WriterState.Entry) || !this.writingFeed)
                        {
                            break;
                        }
                        throw new ODataException(Microsoft.Data.OData.Strings.ODataWriterCore_CannotWriteTopLevelEntryWithFeedWriter);

                    case WriterState.Entry:
                        if (this.CurrentScope.Item == null)
                        {
                            throw new ODataException(Microsoft.Data.OData.Strings.ODataWriterCore_InvalidTransitionFromNullEntry(this.State.ToString(), newState.ToString()));
                        }
                        if (newState != WriterState.NavigationLink)
                        {
                            throw new ODataException(Microsoft.Data.OData.Strings.ODataWriterCore_InvalidTransitionFromEntry(this.State.ToString(), newState.ToString()));
                        }
                        break;

                    case WriterState.Feed:
                        if (newState != WriterState.Entry)
                        {
                            throw new ODataException(Microsoft.Data.OData.Strings.ODataWriterCore_InvalidTransitionFromFeed(this.State.ToString(), newState.ToString()));
                        }
                        break;

                    case WriterState.NavigationLink:
                        if (newState != WriterState.NavigationLinkWithContent)
                        {
                            throw new ODataException(Microsoft.Data.OData.Strings.ODataWriterCore_InvalidStateTransition(this.State.ToString(), newState.ToString()));
                        }
                        break;

                    case WriterState.NavigationLinkWithContent:
                        if ((newState != WriterState.Feed) && (newState != WriterState.Entry))
                        {
                            throw new ODataException(Microsoft.Data.OData.Strings.ODataWriterCore_InvalidTransitionFromExpandedLink(this.State.ToString(), newState.ToString()));
                        }
                        break;

                    case WriterState.Completed:
                        throw new ODataException(Microsoft.Data.OData.Strings.ODataWriterCore_InvalidTransitionFromCompleted(this.State.ToString(), newState.ToString()));

                    case WriterState.Error:
                        if (newState != WriterState.Error)
                        {
                            throw new ODataException(Microsoft.Data.OData.Strings.ODataWriterCore_InvalidTransitionFromError(this.State.ToString(), newState.ToString()));
                        }
                        break;

                    default:
                        throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodes.ODataWriterCore_ValidateTransition_UnreachableCodePath));
                }
            }
        }
Esempio n. 6
0
        private void ValidateTransition(WriterState newState)
        {
            if (IsErrorState(this.State) || !IsErrorState(newState))
            {
                switch (this.State)
                {
                case WriterState.Start:
                    if ((newState != WriterState.Feed) && (newState != WriterState.Entry))
                    {
                        throw new ODataException(Microsoft.Data.OData.Strings.ODataWriterCore_InvalidTransitionFromStart(this.State.ToString(), newState.ToString()));
                    }
                    if ((newState == WriterState.Feed) && !this.writingFeed)
                    {
                        throw new ODataException(Microsoft.Data.OData.Strings.ODataWriterCore_CannotWriteTopLevelFeedWithEntryWriter);
                    }
                    if ((newState != WriterState.Entry) || !this.writingFeed)
                    {
                        break;
                    }
                    throw new ODataException(Microsoft.Data.OData.Strings.ODataWriterCore_CannotWriteTopLevelEntryWithFeedWriter);

                case WriterState.Entry:
                    if (this.CurrentScope.Item == null)
                    {
                        throw new ODataException(Microsoft.Data.OData.Strings.ODataWriterCore_InvalidTransitionFromNullEntry(this.State.ToString(), newState.ToString()));
                    }
                    if (newState != WriterState.NavigationLink)
                    {
                        throw new ODataException(Microsoft.Data.OData.Strings.ODataWriterCore_InvalidTransitionFromEntry(this.State.ToString(), newState.ToString()));
                    }
                    break;

                case WriterState.Feed:
                    if (newState != WriterState.Entry)
                    {
                        throw new ODataException(Microsoft.Data.OData.Strings.ODataWriterCore_InvalidTransitionFromFeed(this.State.ToString(), newState.ToString()));
                    }
                    break;

                case WriterState.NavigationLink:
                    if (newState != WriterState.NavigationLinkWithContent)
                    {
                        throw new ODataException(Microsoft.Data.OData.Strings.ODataWriterCore_InvalidStateTransition(this.State.ToString(), newState.ToString()));
                    }
                    break;

                case WriterState.NavigationLinkWithContent:
                    if ((newState != WriterState.Feed) && (newState != WriterState.Entry))
                    {
                        throw new ODataException(Microsoft.Data.OData.Strings.ODataWriterCore_InvalidTransitionFromExpandedLink(this.State.ToString(), newState.ToString()));
                    }
                    break;

                case WriterState.Completed:
                    throw new ODataException(Microsoft.Data.OData.Strings.ODataWriterCore_InvalidTransitionFromCompleted(this.State.ToString(), newState.ToString()));

                case WriterState.Error:
                    if (newState != WriterState.Error)
                    {
                        throw new ODataException(Microsoft.Data.OData.Strings.ODataWriterCore_InvalidTransitionFromError(this.State.ToString(), newState.ToString()));
                    }
                    break;

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