Esempio n. 1
0
 private void ReplaceScope(CollectionWriterState newState, ODataItem item)
 {
     this.ValidateTransition(newState);
     this.scopes.Pop();
     this.scopes.Push(new Scope(newState, item));
     this.NotifyListener(newState);
 }
Esempio n. 2
0
        private void PushScope(WriterState state, ODataItem item, bool skipWriting)
        {
            Scope scope;

            switch (state)
            {
            case WriterState.Start:
            case WriterState.Completed:
                scope = new Scope(state, item, skipWriting);
                break;

            case WriterState.Error:
                scope = new Scope(state, item, skipWriting);
                break;

            case WriterState.Entry:
                scope = this.CreateEntryScope((ODataEntry)item, skipWriting);
                break;

            case WriterState.Feed:
                scope = this.CreateFeedScope((ODataFeed)item, skipWriting);
                break;

            case WriterState.NavigationLink:
            case WriterState.NavigationLinkWithContent:
                scope = new NavigationLinkScope(state, (ODataNavigationLink)item, skipWriting);
                break;

            default:
                throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodes.ODataWriterCore_Scope_Create_UnreachableCodePath));
            }
            this.scopes.Push(scope);
        }
Esempio n. 3
0
 private void EnterScope(WriterState newState, ODataItem item)
 {
     this.InterceptException(() => this.ValidateTransition(newState));
     bool skipWriting = this.SkipWriting;
     Scope currentScope = this.CurrentScope;
     if (((currentScope.State == WriterState.Entry) && (newState == WriterState.NavigationLink)) && !skipWriting)
     {
         ProjectedPropertiesAnnotation projectedProperties = currentScope.Item.GetAnnotation<ProjectedPropertiesAnnotation>();
         ODataNavigationLink link = (ODataNavigationLink) item;
         skipWriting = projectedProperties.ShouldSkipProperty(link.Name);
     }
     else if ((currentScope.State == WriterState.Feed) && (newState == WriterState.Entry))
     {
         FeedScope scope1 = (FeedScope) currentScope;
         scope1.EntryCount++;
     }
     this.PushScope(newState, item, skipWriting);
 }
Esempio n. 4
0
            internal Scope(ODataReaderState state, ODataItem item, IEdmEntityType expectedEntityType)
            {
                Debug.Assert(
                    state == ODataReaderState.Exception && item == null ||
                    state == ODataReaderState.EntryStart && (item == null || item is ODataEntry) ||
                    state == ODataReaderState.EntryEnd && (item == null || item is ODataEntry) ||
                    state == ODataReaderState.FeedStart && item is ODataFeed ||
                    state == ODataReaderState.FeedEnd && item is ODataFeed ||
                    state == ODataReaderState.NavigationLinkStart && item is ODataNavigationLink ||
                    state == ODataReaderState.NavigationLinkEnd && item is ODataNavigationLink ||
                    state == ODataReaderState.EntityReferenceLink && item is ODataEntityReferenceLink ||
                    state == ODataReaderState.Start && item == null ||
                    state == ODataReaderState.Completed && item == null,
                    "Reader state and associated item do not match.");

                this.state      = state;
                this.item       = item;
                this.EntityType = expectedEntityType;
            }
Esempio n. 5
0
        private void EnterScope(WriterState newState, ODataItem item)
        {
            this.InterceptException(() => this.ValidateTransition(newState));
            bool  skipWriting  = this.SkipWriting;
            Scope currentScope = this.CurrentScope;

            if (((currentScope.State == WriterState.Entry) && (newState == WriterState.NavigationLink)) && !skipWriting)
            {
                ProjectedPropertiesAnnotation projectedProperties = currentScope.Item.GetAnnotation <ProjectedPropertiesAnnotation>();
                ODataNavigationLink           link = (ODataNavigationLink)item;
                skipWriting = projectedProperties.ShouldSkipProperty(link.Name);
            }
            else if ((currentScope.State == WriterState.Feed) && (newState == WriterState.Entry))
            {
                FeedScope scope1 = (FeedScope)currentScope;
                scope1.EntryCount++;
            }
            this.PushScope(newState, item, skipWriting);
        }
Esempio n. 6
0
 /// <summary>
 /// Initializes a new instance of <see cref="ODataItemBase"/>.
 /// </summary>
 /// <param name="item">The wrapped item.</param>
 protected ODataItemBase(ODataItem item)
 {
     _item = item;
 }
Esempio n. 7
0
 /// <summary>
 /// Enters the 'ExceptionThrown' state and then throws an ODataException with the specified error message.
 /// </summary>
 /// <param name="errorMessage">The error message for the exception.</param>
 /// <param name="item">The OData item to associate with the 'ExceptionThrown' state.</param>
 private void ThrowODataException(string errorMessage, ODataItem item)
 {
     this.EnterScope(WriterState.Error, item);
     throw new ODataException(errorMessage);
 }
 /// <summary>
 /// Replaces the current scope with a new scope; checks that the transition is valid.
 /// </summary>
 /// <param name="newState">The new state to transition into.</param>
 /// <param name="item">The item associated with the new state.</param>
 private void ReplaceScope(CollectionWriterState newState, ODataItem item)
 {
     this.ValidateTransition(newState);
     this.scopes.Pop();
     this.scopes.Push(new Scope(newState, item));
     this.NotifyListener(newState);
 }
Esempio n. 9
0
        private void PushScope(WriterState state, ODataItem item, bool skipWriting)
        {
            Debug.Assert(
                state == WriterState.Error ||
                state == WriterState.Entry && (item == null || item is ODataEntry) ||
                state == WriterState.Feed && item is ODataFeed ||
                state == WriterState.NavigationLink && item is ODataNavigationLink ||
                state == WriterState.NavigationLinkWithContent && item is ODataNavigationLink ||
                state == WriterState.Start && item == null ||
                state == WriterState.Completed && item == null,
                "Writer state and associated item do not match.");

            Scope scope;
            switch (state)
            {
                case WriterState.Entry:
                    scope = this.CreateEntryScope((ODataEntry)item, skipWriting);
                    break;
                case WriterState.Feed:
                    scope = this.CreateFeedScope((ODataFeed)item, skipWriting);
                    break;
                case WriterState.NavigationLink:            // fall through
                case WriterState.NavigationLinkWithContent:
                    scope = new NavigationLinkScope(state, (ODataNavigationLink)item, skipWriting);
                    break;
                case WriterState.Start:                     // fall through
                case WriterState.Completed:                 // fall through
                case WriterState.Error:
                    scope = new Scope(state, item, skipWriting);
                    break;
                default:
                    string errorMessage = Strings.General_InternalError(InternalErrorCodes.ODataWriterCore_Scope_Create_UnreachableCodePath);
                    Debug.Assert(false, errorMessage);
                    throw new ODataException(errorMessage);
            }

            this.scopes.Push(scope);
        }
Esempio n. 10
0
            /// <summary>
            /// Constructor creating a new writer scope.
            /// </summary>
            /// <param name="state">The writer state of this scope.</param>
            /// <param name="item">The item attached to this scope.</param>
            /// <param name="skipWriting">true if the content of this scope should not be written.</param>
            internal Scope(WriterState state, ODataItem item, bool skipWriting)
            {
                DebugUtils.CheckNoExternalCallers();

                this.state = state;
                this.item = item;
                this.skipWriting = skipWriting;
            }
Esempio n. 11
0
 internal JsonScope(ODataReaderState state, ODataItem item, IEdmEntityType expectedEntityType) : base(state, item, expectedEntityType)
 {
 }
Esempio n. 12
0
        private void EnterScope(WriterState newState, ODataItem item)
        {
            this.InterceptException(() => this.ValidateTransition(newState));
            
            // If the parent scope was marked for skipping content, the new child scope should be as well.
            bool skipWriting = this.SkipWriting;

            Scope currentScope = this.CurrentScope;

            // When writing a navigation link, check if the link is being projected.
            // If we are projecting properties, but the nav. link is not projected mark it to skip its content.
            if (currentScope.State == WriterState.Entry && newState == WriterState.NavigationLink && !skipWriting)
            {
                Debug.Assert(currentScope.Item is ODataEntry, "If the current state is Entry the current Item must be entry as well (and not null either).");
                Debug.Assert(item is ODataNavigationLink, "If the new state is NavigationLink the new item must be a navigation link as well (and not null either).");

                ProjectedPropertiesAnnotation projectedProperties = currentScope.Item.GetAnnotation<ProjectedPropertiesAnnotation>();
                ODataNavigationLink navigationLink = (ODataNavigationLink)item;
                skipWriting = projectedProperties.ShouldSkipProperty(navigationLink.Name);
            }
            else if (currentScope.State == WriterState.Feed && newState == WriterState.Entry)
            {
                // When we're entering an entry scope on a feed, increment the count of entries on that feed.
                ((FeedScope)currentScope).EntryCount++;
            }

            this.PushScope(newState, item, skipWriting);
        }
Esempio n. 13
0
 internal Scope(ODataWriterCore.WriterState state, ODataItem item, bool skipWriting)
 {
     this.state       = state;
     this.item        = item;
     this.skipWriting = skipWriting;
 }
Esempio n. 14
0
 private void EnterScope(ODataReaderState state, ODataItem item, IEdmEntityType expectedEntityType)
 {
     base.EnterScope(new JsonScope(state, item, expectedEntityType));
 }
Esempio n. 15
0
 private void ThrowODataException(string errorMessage, ODataItem item)
 {
     this.EnterScope(WriterState.Error, item);
     throw new ODataException(errorMessage);
 }
Esempio n. 16
0
 internal Scope(ODataReaderState state, ODataItem item, IEdmEntityType expectedEntityType)
 {
     this.state      = state;
     this.item       = item;
     this.EntityType = expectedEntityType;
 }
Esempio n. 17
0
 /// <summary>
 /// Creates a new <see cref="AtomScope"/> for the specified <paramref name="state"/> and
 /// with the provided <paramref name="item"/> and pushes it on the stack of scopes.
 /// </summary>
 /// <param name="state">The <see cref="ODataReaderState"/> to use for the new scope.</param>
 /// <param name="item">The item to attach with the state in the new scope.</param>
 /// <param name="expectedEntityType">The expected type for the new scope.</param>
 private void EnterScope(ODataReaderState state, ODataItem item, IEdmEntityType expectedEntityType)
 {
     this.EnterScope(new AtomScope(state, item, expectedEntityType));
 }
Esempio n. 18
0
 internal Scope(ODataWriterCore.WriterState state, ODataItem item, bool skipWriting)
 {
     this.state = state;
     this.item = item;
     this.skipWriting = skipWriting;
 }
Esempio n. 19
0
        private void PushScope(WriterState state, ODataItem item, bool skipWriting)
        {
            Scope scope;
            switch (state)
            {
                case WriterState.Start:
                case WriterState.Completed:
					scope = new Scope(state, item, skipWriting);
					break;
                case WriterState.Error:
                    scope = new Scope(state, item, skipWriting);
                    break;

                case WriterState.Entry:
                    scope = this.CreateEntryScope((ODataEntry) item, skipWriting);
                    break;

                case WriterState.Feed:
                    scope = this.CreateFeedScope((ODataFeed) item, skipWriting);
                    break;

                case WriterState.NavigationLink:
                case WriterState.NavigationLinkWithContent:
                    scope = new NavigationLinkScope(state, (ODataNavigationLink) item, skipWriting);
                    break;

                default:
                    throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodes.ODataWriterCore_Scope_Create_UnreachableCodePath));
            }
            this.scopes.Push(scope);
        }