/// <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(CollectionWriterState 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 CollectionWriterState.Start: if (newState != CollectionWriterState.Collection && newState != CollectionWriterState.Completed) { throw new ODataException(Strings.ODataCollectionWriterCore_InvalidTransitionFromStart(this.State.ToString(), newState.ToString())); } break; case CollectionWriterState.Collection: if (newState != CollectionWriterState.Item && newState != CollectionWriterState.Completed) { throw new ODataException(Strings.ODataCollectionWriterCore_InvalidTransitionFromCollection(this.State.ToString(), newState.ToString())); } break; case CollectionWriterState.Item: if (newState != CollectionWriterState.Completed) { throw new ODataException(Strings.ODataCollectionWriterCore_InvalidTransitionFromItem(this.State.ToString(), newState.ToString())); } break; case CollectionWriterState.Completed: // we should never see a state transition when in state 'Completed' throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromCompleted(this.State.ToString(), newState.ToString())); case CollectionWriterState.Error: if (newState != CollectionWriterState.Error) { // No more state transitions once we are in error state throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromError(this.State.ToString(), newState.ToString())); } break; default: throw new ODataException(Strings.General_InternalError(InternalErrorCodes.ODataCollectionWriterCore_ValidateTransition_UnreachableCodePath)); } }
private void ValidateTransition(CollectionWriterState newState) { if (IsErrorState(this.State) || !IsErrorState(newState)) { switch (this.State) { case CollectionWriterState.Start: if ((newState != CollectionWriterState.Collection) && (newState != CollectionWriterState.Completed)) { throw new ODataException(Microsoft.Data.OData.Strings.ODataCollectionWriterCore_InvalidTransitionFromStart(this.State.ToString(), newState.ToString())); } break; case CollectionWriterState.Collection: if ((newState != CollectionWriterState.Item) && (newState != CollectionWriterState.Completed)) { throw new ODataException(Microsoft.Data.OData.Strings.ODataCollectionWriterCore_InvalidTransitionFromCollection(this.State.ToString(), newState.ToString())); } break; case CollectionWriterState.Item: if (newState != CollectionWriterState.Completed) { throw new ODataException(Microsoft.Data.OData.Strings.ODataCollectionWriterCore_InvalidTransitionFromItem(this.State.ToString(), newState.ToString())); } break; case CollectionWriterState.Completed: throw new ODataException(Microsoft.Data.OData.Strings.ODataWriterCore_InvalidTransitionFromCompleted(this.State.ToString(), newState.ToString())); case CollectionWriterState.Error: if (newState != CollectionWriterState.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.ODataCollectionWriterCore_ValidateTransition_UnreachableCodePath)); } } }
/// <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(CollectionWriterState newState) { if (!IsErrorState(this.State) && IsErrorState(newState) && !(this.State == CollectionWriterState.Completed && newState == CollectionWriterState.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 CollectionWriterState.Start: if (newState != CollectionWriterState.Collection && newState != CollectionWriterState.Completed) { throw new ODataException(Strings.ODataCollectionWriterCore_InvalidTransitionFromStart(this.State.ToString(), newState.ToString())); } break; case CollectionWriterState.Collection: if (newState != CollectionWriterState.Item && newState != CollectionWriterState.Completed) { throw new ODataException(Strings.ODataCollectionWriterCore_InvalidTransitionFromCollection(this.State.ToString(), newState.ToString())); } break; case CollectionWriterState.Item: if (newState != CollectionWriterState.Completed) { throw new ODataException(Strings.ODataCollectionWriterCore_InvalidTransitionFromItem(this.State.ToString(), newState.ToString())); } break; case CollectionWriterState.Completed: // we should never see a state transition when in state 'Completed' throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromCompleted(this.State.ToString(), newState.ToString())); case CollectionWriterState.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 CollectionWriterState.Error: // No more state transitions once we are in error state except for the fatal error if (newState != CollectionWriterState.FatalExceptionThrown) { throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromError(this.State.ToString(), newState.ToString())); } break; case CollectionWriterState.FatalExceptionThrown: if (newState != CollectionWriterState.FatalExceptionThrown) { throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromFatalExceptionThrown(this.State.ToString(), newState.ToString())); } break; default: throw new ODataException(Strings.General_InternalError(InternalErrorCodes.ODataCollectionWriterCore_ValidateTransition_UnreachableCodePath)); } }