internal ODataEntityReferenceLinks ReadEntityReferenceLinks()
 {
     bool flag = (base.Version >= ODataVersion.V2) && base.ReadingResponse;
     ODataJsonReaderUtils.EntityReferenceLinksWrapperPropertyBitMask none = ODataJsonReaderUtils.EntityReferenceLinksWrapperPropertyBitMask.None;
     ODataEntityReferenceLinks entityReferenceLinks = new ODataEntityReferenceLinks();
     base.ReadPayloadStart(false);
     if (flag)
     {
         base.JsonReader.ReadStartObject();
         if (!this.ReadEntityReferenceLinkProperties(entityReferenceLinks, ref none))
         {
             throw new ODataException(Strings.ODataJsonEntityReferenceLinkDeserializer_ExpectedEntityReferenceLinksResultsPropertyNotFound);
         }
     }
     base.JsonReader.ReadStartArray();
     List<ODataEntityReferenceLink> sourceList = new List<ODataEntityReferenceLink>();
     while (base.JsonReader.NodeType != JsonNodeType.EndArray)
     {
         ODataEntityReferenceLink item = this.ReadSingleEntityReferenceLink();
         sourceList.Add(item);
     }
     base.JsonReader.ReadEndArray();
     if (flag)
     {
         this.ReadEntityReferenceLinkProperties(entityReferenceLinks, ref none);
         base.JsonReader.ReadEndObject();
     }
     entityReferenceLinks.Links = new ReadOnlyEnumerable<ODataEntityReferenceLink>(sourceList);
     base.ReadPayloadEnd(false);
     return entityReferenceLinks;
 }
 internal void WriteEntityReferenceLinks(ODataEntityReferenceLinks entityReferenceLinks)
 {
     base.WritePayloadStart();
     base.XmlWriter.WriteStartElement(string.Empty, "links", base.MessageWriterSettings.WriterBehavior.ODataNamespace);
     base.XmlWriter.WriteAttributeString("xmlns", base.MessageWriterSettings.WriterBehavior.ODataNamespace);
     if (entityReferenceLinks.Count.HasValue)
     {
         base.WriteCount(entityReferenceLinks.Count.Value, true);
     }
     IEnumerable<ODataEntityReferenceLink> links = entityReferenceLinks.Links;
     if (links != null)
     {
         foreach (ODataEntityReferenceLink link in links)
         {
             WriterValidationUtils.ValidateEntityReferenceLinkNotNull(link);
             this.WriteEntityReferenceLink(link, false);
         }
     }
     if (entityReferenceLinks.NextPageLink != null)
     {
         string str = base.UriToUrlAttributeValue(entityReferenceLinks.NextPageLink);
         base.XmlWriter.WriteElementString(string.Empty, "next", base.MessageWriterSettings.WriterBehavior.ODataNamespace, str);
     }
     base.XmlWriter.WriteEndElement();
     base.WritePayloadEnd();
 }
예제 #3
0
 private IEnumerable<ODataEntityReferenceLink> GetLinksCollection(IEnumerator elements, bool hasMoved, ODataEntityReferenceLinks linksCollection)
 {
     object lastObject = null;
     IExpandedResult skipTokenExpandedResult = null;
 Label_PostSwitchInIterator:;
     if (hasMoved)
     {
         object current = elements.Current;
         IExpandedResult skipToken = null;
         if (current != null)
         {
             IExpandedResult expanded = current as IExpandedResult;
             if (expanded != null)
             {
                 current = Serializer.GetExpandedElement(expanded);
                 skipToken = this.GetSkipToken(expanded);
             }
         }
         this.IncrementSegmentResultCount();
         ODataEntityReferenceLink iteratorVariable4 = new ODataEntityReferenceLink {
             Url = this.GetEntityUri(current)
         };
         yield return iteratorVariable4;
         hasMoved = elements.MoveNext();
         lastObject = current;
         skipTokenExpandedResult = skipToken;
         goto Label_PostSwitchInIterator;
     }
     if (this.NeedNextPageLink(elements))
     {
         linksCollection.NextPageLink = this.GetNextLinkUri(lastObject, skipTokenExpandedResult, this.RequestDescription.ResultUri);
     }
 }
        private ODataEntityReferenceLinks ReadLinksElement()
        {
            ODataEntityReferenceLinks links = new ODataEntityReferenceLinks();
            List<ODataEntityReferenceLink> sourceList = new List<ODataEntityReferenceLink>();
            DuplicateEntityReferenceLinksElementBitMask none = DuplicateEntityReferenceLinksElementBitMask.None;
            if (base.XmlReader.IsEmptyElement)
            {
                goto Label_018C;
            }
            base.XmlReader.Read();
        Label_002A:
            switch (base.XmlReader.NodeType)
            {
                case XmlNodeType.Element:
                    if ((base.XmlReader.NamespaceEquals(base.XmlReader.ODataMetadataNamespace) && base.XmlReader.LocalNameEquals(this.ODataCountElementName)) && (base.Version >= ODataVersion.V2))
                    {
                        VerifyEntityReferenceLinksElementNotFound(ref none, DuplicateEntityReferenceLinksElementBitMask.Count, base.XmlReader.ODataMetadataNamespace, "count");
                        long num = (long) AtomValueUtils.ReadPrimitiveValue(base.XmlReader, EdmCoreModel.Instance.GetInt64(false));
                        links.Count = new long?(num);
                        base.XmlReader.Read();
                        goto Label_017A;
                    }
                    if (base.XmlReader.NamespaceEquals(base.XmlReader.ODataNamespace))
                    {
                        if (base.XmlReader.LocalNameEquals(this.ODataUriElementName))
                        {
                            ODataEntityReferenceLink item = this.ReadUriElement();
                            sourceList.Add(item);
                            goto Label_017A;
                        }
                        if (base.XmlReader.LocalNameEquals(this.ODataNextElementName) && (base.Version >= ODataVersion.V2))
                        {
                            VerifyEntityReferenceLinksElementNotFound(ref none, DuplicateEntityReferenceLinksElementBitMask.NextLink, base.XmlReader.ODataNamespace, "next");
                            Uri xmlBaseUri = base.XmlReader.XmlBaseUri;
                            string uriFromPayload = base.XmlReader.ReadElementValue();
                            links.NextPageLink = base.ProcessUriFromPayload(uriFromPayload, xmlBaseUri);
                            goto Label_017A;
                        }
                    }
                    break;

                case XmlNodeType.EndElement:
                    goto Label_017A;
            }
            base.XmlReader.Skip();
        Label_017A:
            if (base.XmlReader.NodeType != XmlNodeType.EndElement)
            {
                goto Label_002A;
            }
        Label_018C:
            base.XmlReader.Read();
            links.Links = new ReadOnlyEnumerable<ODataEntityReferenceLink>(sourceList);
            return links;
        }
        /// <inheridoc />
        public override void WriteObject(object graph, Type type, ODataMessageWriter messageWriter, ODataSerializerContext writeContext)
        {
            if (messageWriter == null)
            {
                throw Error.ArgumentNull("messageWriter");
            }

            if (writeContext == null)
            {
                throw Error.ArgumentNull("writeContext");
            }

            if (writeContext.Path == null)
            {
                throw new SerializationException(SRResources.ODataPathMissing);
            }

            IEdmEntitySet entitySet = writeContext.Path.GetEntitySet();
            if (entitySet == null)
            {
                throw new SerializationException(SRResources.EntitySetMissingDuringSerialization);
            }

            IEdmNavigationProperty navigationProperty = writeContext.Path.GetNavigationProperty();
            if (navigationProperty == null)
            {
                throw new SerializationException(SRResources.NavigationPropertyMissingDuringSerialization);
            }

            if (graph != null)
            {
                ODataEntityReferenceLinks entityReferenceLinks = graph as ODataEntityReferenceLinks;
                if (entityReferenceLinks == null)
                {
                    IEnumerable<Uri> uris = graph as IEnumerable<Uri>;
                    if (uris == null)
                    {
                        throw new SerializationException(Error.Format(SRResources.CannotWriteType, GetType().Name, graph.GetType().FullName));
                    }

                    entityReferenceLinks = new ODataEntityReferenceLinks
                    {
                        Links = uris.Select(uri => new ODataEntityReferenceLink { Url = uri })
                    };
                    if (writeContext.Request != null)
                    {
                        entityReferenceLinks.Count = writeContext.Request.ODataProperties().TotalCount;
                    }
                }

                messageWriter.WriteEntityReferenceLinks(entityReferenceLinks, entitySet, navigationProperty);
            }
        }
예제 #6
0
 private void ReadLinks()
 {
     try
     {
         if (this.links == null)
         {
             this.links = base.messageReader.ReadEntityReferenceLinks();
         }
     }
     catch (ODataErrorException exception)
     {
         throw new DataServiceClientException(System.Data.Services.Client.Strings.Deserialize_ServerException(exception.Error.Message), exception);
     }
     catch (ODataException exception2)
     {
         throw new InvalidOperationException(exception2.Message, exception2);
     }
 }
 private bool ReadEntityReferenceLinkProperties(ODataEntityReferenceLinks entityReferenceLinks, ref ODataJsonReaderUtils.EntityReferenceLinksWrapperPropertyBitMask propertiesFoundBitField)
 {
     while (base.JsonReader.NodeType == JsonNodeType.Property)
     {
         string str3 = base.JsonReader.ReadPropertyName();
         if (str3 == null)
         {
             goto Label_00D9;
         }
         if (!(str3 == "results"))
         {
             if (str3 == "__count")
             {
                 goto Label_0057;
             }
             if (str3 == "__next")
             {
                 goto Label_00A2;
             }
             goto Label_00D9;
         }
         ODataJsonReaderUtils.VerifyEntityReferenceLinksWrapperPropertyNotFound(ref propertiesFoundBitField, ODataJsonReaderUtils.EntityReferenceLinksWrapperPropertyBitMask.Results, "results");
         return true;
     Label_0057:
         ODataJsonReaderUtils.VerifyEntityReferenceLinksWrapperPropertyNotFound(ref propertiesFoundBitField, ODataJsonReaderUtils.EntityReferenceLinksWrapperPropertyBitMask.Count, "__count");
         long? propertyValue = (long?) ODataJsonReaderUtils.ConvertValue(base.JsonReader.ReadPrimitiveValue(), EdmCoreModel.Instance.GetInt64(true), base.MessageReaderSettings, base.Version, true);
         ODataJsonReaderUtils.ValidateCountPropertyInEntityReferenceLinks(propertyValue);
         entityReferenceLinks.Count = propertyValue;
         continue;
     Label_00A2:
         ODataJsonReaderUtils.VerifyEntityReferenceLinksWrapperPropertyNotFound(ref propertiesFoundBitField, ODataJsonReaderUtils.EntityReferenceLinksWrapperPropertyBitMask.NextPageLink, "__next");
         string str2 = base.JsonReader.ReadStringValue("__next");
         ODataJsonReaderUtils.ValidateEntityReferenceLinksStringProperty(str2, "__next");
         entityReferenceLinks.NextPageLink = base.ProcessUriFromPayload(str2);
         continue;
     Label_00D9:
         base.JsonReader.SkipValue();
     }
     return false;
 }
 private void WriteEntityReferenceLinksImplementation(ODataEntityReferenceLinks entityReferenceLinks, bool includeResultsWrapper)
 {
     if (includeResultsWrapper)
     {
         base.JsonWriter.StartObjectScope();
     }
     if (entityReferenceLinks.Count.HasValue)
     {
         base.JsonWriter.WriteName("__count");
         base.JsonWriter.WriteValue(entityReferenceLinks.Count.Value);
     }
     if (includeResultsWrapper)
     {
         base.JsonWriter.WriteDataArrayName();
     }
     base.JsonWriter.StartArrayScope();
     IEnumerable<ODataEntityReferenceLink> links = entityReferenceLinks.Links;
     if (links != null)
     {
         foreach (ODataEntityReferenceLink link in links)
         {
             WriterValidationUtils.ValidateEntityReferenceLinkNotNull(link);
             this.WriteEntityReferenceLinkImplementation(link);
         }
     }
     base.JsonWriter.EndArrayScope();
     if (entityReferenceLinks.NextPageLink != null)
     {
         base.JsonWriter.WriteName("__next");
         base.JsonWriter.WriteValue(base.UriToAbsoluteUriString(entityReferenceLinks.NextPageLink));
     }
     if (includeResultsWrapper)
     {
         base.JsonWriter.EndObjectScope();
     }
 }
예제 #9
0
 /// <summary>
 /// Asynchronously writes the result of a $links query as the message payload.
 /// </summary>
 /// <param name="links">The entity reference links to write as message payload.</param>
 /// <returns>A task representing the asynchronous writing of the entity reference links.</returns>
 /// <remarks>It is the responsibility of this method to flush the output before the task finishes.</remarks>
 internal virtual Task WriteEntityReferenceLinksAsync(ODataEntityReferenceLinks links)
 {
     DebugUtils.CheckNoExternalCallers();
     throw this.CreatePayloadKindNotSupportedException(ODataPayloadKind.EntityReferenceLinks);
 }
예제 #10
0
 private void WriteEntityReferenceLinksImplementation(ODataEntityReferenceLinks links)
 {
     new ODataJsonEntityReferenceLinkSerializer(this).WriteEntityReferenceLinks(links);
 }
예제 #11
0
 internal override Task WriteEntityReferenceLinksAsync(ODataEntityReferenceLinks links)
 {
     return TaskUtils.GetTaskForSynchronousOperationReturningTask(delegate {
         this.WriteEntityReferenceLinksImplementation(links);
         return this.FlushAsync();
     });
 }
예제 #12
0
 internal override void WriteEntityReferenceLinks(ODataEntityReferenceLinks links)
 {
     this.WriteEntityReferenceLinksImplementation(links);
     this.Flush();
 }
예제 #13
0
 internal virtual Task WriteEntityReferenceLinksAsync(ODataEntityReferenceLinks links)
 {
     throw this.CreatePayloadKindNotSupportedException(ODataPayloadKind.EntityReferenceLinks);
 }
 internal void WriteEntityReferenceLinks(ODataEntityReferenceLinks entityReferenceLinks)
 {
     base.WriteTopLevelPayload(() => this.WriteEntityReferenceLinksImplementation(entityReferenceLinks, (this.Version >= ODataVersion.V2) && this.WritingResponse));
 }
예제 #15
0
 private void WriteLinkCollection(IEnumerator elements, bool hasMoved)
 {
     ODataEntityReferenceLinks linksCollection = new ODataEntityReferenceLinks();
     if (base.RequestDescription.CountOption == RequestQueryCountOption.Inline)
     {
         linksCollection.Count = new long?(base.RequestDescription.CountValue);
     }
     linksCollection.Links = this.GetLinksCollection(elements, hasMoved, linksCollection);
     this.writer.WriteEntityReferenceLinks(linksCollection);
 }
예제 #16
0
 /// <summary>
 /// Asynchronously writes the result of a $links query as the message payload.
 /// </summary>
 /// <param name="links">The entity reference links to write as message payload.</param>
 /// <returns>A task representing the asynchronous writing of the entity reference links.</returns>
 /// <remarks>It is the responsibility of this method to flush the output before the task finishes.</remarks>
 internal virtual Task WriteEntityReferenceLinksAsync(ODataEntityReferenceLinks links)
 {
     DebugUtils.CheckNoExternalCallers();
     throw this.CreatePayloadKindNotSupportedException(ODataPayloadKind.EntityReferenceLinks);
 }
예제 #17
0
 internal virtual Task WriteEntityReferenceLinksAsync(ODataEntityReferenceLinks links)
 {
     throw this.CreatePayloadKindNotSupportedException(ODataPayloadKind.EntityReferenceLinks);
 }