Exemple #1
0
 public sealed override Task WriteStartAsync(ODataCollectionStart collection)
 {
     this.VerifyCanWriteStart(false, collection);
     return(TaskUtils.GetTaskForSynchronousOperation(delegate {
         this.WriteStartImplementation(collection);
     }));
 }
 protected override void StartCollection(ODataCollectionStart collectionStart)
 {
     string name = collectionStart.Name;
     if (name == null)
     {
         throw new ODataException(Microsoft.Data.OData.Strings.ODataAtomCollectionWriter_CollectionNameMustNotBeNull);
     }
     this.atomOutputContext.XmlWriter.WriteStartElement(name, this.atomCollectionSerializer.MessageWriterSettings.WriterBehavior.ODataNamespace);
     this.atomOutputContext.XmlWriter.WriteAttributeString("xmlns", "http://www.w3.org/2000/xmlns/", this.atomCollectionSerializer.MessageWriterSettings.WriterBehavior.ODataNamespace);
     this.atomCollectionSerializer.WriteDefaultNamespaceAttributes(ODataAtomSerializer.DefaultNamespaceFlags.Gml | ODataAtomSerializer.DefaultNamespaceFlags.GeoRss | ODataAtomSerializer.DefaultNamespaceFlags.ODataMetadata);
 }
Exemple #3
0
        private void VerifyCanWriteStart(bool synchronousCall, ODataCollectionStart collectionStart)
        {
            ExceptionUtils.CheckArgumentNotNull <ODataCollectionStart>(collectionStart, "collection");
            string name = collectionStart.Name;

            if ((name != null) && (name.Length == 0))
            {
                throw new ODataException(Microsoft.Data.OData.Strings.ODataCollectionWriterCore_CollectionsMustNotHaveEmptyName);
            }
            this.VerifyNotDisposed();
            this.VerifyCallAllowed(synchronousCall);
        }
Exemple #4
0
        /// <summary>
        /// Start writing a collection - implementation of the actual functionality.
        /// </summary>
        /// <param name="collectionStart">The <see cref="ODataCollectionStart"/> representing the collection.</param>
        private void WriteStartImplementation(ODataCollectionStart collectionStart)
        {
            this.StartPayloadInStartState();
            this.EnterScope(CollectionWriterState.Collection, collectionStart);
            this.InterceptException(() =>
            {
                if (this.expectedItemType == null)
                {
                    this.collectionValidator = new CollectionWithoutExpectedTypeValidator(/*expectedItemTypeName*/ null);
                }

                this.StartCollection(collectionStart);
            });
        }
        /// <summary>
        /// Verifies that calling WriteStart is valid.
        /// </summary>
        /// <param name="synchronousCall">true if the call is to be synchronous; false otherwise.</param>
        /// <param name="collectionStart">The <see cref="ODataCollectionStart"/> representing the collection.</param>
        private void VerifyCanWriteStart(bool synchronousCall, ODataCollectionStart collectionStart)
        {
            ExceptionUtils.CheckArgumentNotNull(collectionStart, "collection");

            // we do not allow empty collection names
            // NOTE: null is allowed as collection name in JSON but not in ATOM;
            //       the ODataAtomCollectionWriter checks for null.
            string collectionName = collectionStart.Name;

            if (collectionName != null && collectionName.Length == 0)
            {
                throw new ODataException(Strings.ODataCollectionWriterCore_CollectionsMustNotHaveEmptyName);
            }

            this.VerifyNotDisposed();
            this.VerifyCallAllowed(synchronousCall);
        }
        /// <summary>
        /// Reads the start element of a collection.
        /// </summary>
        /// <param name="isCollectionElementEmpty">true, if the collection element is empty; false otherwise.</param>
        /// <returns>An <see cref="ODataCollectionStart"/> representing the collection-level information. Currently this only contains 
        /// the name of the collection.</returns>
        /// <remarks>
        /// Pre-Condition:   XmlNodeType.Element - The start element of the collection.
        /// Post-Condition:  Any                 - The next node after the start element node of the collection or the 
        ///                                        empty collection element node.
        /// </remarks>
        internal ODataCollectionStart ReadCollectionStart(out bool isCollectionElementEmpty)
        {
            DebugUtils.CheckNoExternalCallers();
            this.XmlReader.AssertNotBuffering();
            this.AssertXmlCondition(XmlNodeType.Element);

            if (!this.XmlReader.NamespaceEquals(this.XmlReader.ODataNamespace))
            {
                throw new ODataException(o.Strings.ODataAtomCollectionDeserializer_TopLevelCollectionElementWrongNamespace(this.XmlReader.NamespaceURI, this.XmlReader.ODataNamespace));
            }
         
            while (this.XmlReader.MoveToNextAttribute())
            {
                if (this.XmlReader.NamespaceEquals(this.XmlReader.ODataMetadataNamespace) &&
                   (this.XmlReader.LocalNameEquals(this.AtomTypeAttributeName) ||
                   (this.XmlReader.LocalNameEquals(this.ODataNullAttributeName))))
                {
                    // make sure that m:type or m:null attributes are not present in the root element of the collection.
                    throw new ODataException(o.Strings.ODataAtomCollectionDeserializer_TypeOrNullAttributeNotAllowed);
                }
            }

            // ignore all other attributes.
            this.XmlReader.MoveToElement();

            ODataCollectionStart collectionStart = new ODataCollectionStart();

            // we don't need to validate the collection name because all valid XML local names 
            // are also valid collection names and the XML validity is checked by the XmlReader.
            collectionStart.Name = this.XmlReader.LocalName;

            isCollectionElementEmpty = this.XmlReader.IsEmptyElement;

            if (!isCollectionElementEmpty)
            {
                // if the collection start element is not an empty element than read over the 
                // start element.
                this.XmlReader.Read();
            }

            return collectionStart;
        }
 internal ODataCollectionStart ReadCollectionStart(out bool isCollectionElementEmpty)
 {
     if (!base.XmlReader.NamespaceEquals(base.XmlReader.ODataNamespace))
     {
         throw new ODataException(Microsoft.Data.OData.Strings.ODataAtomCollectionDeserializer_TopLevelCollectionElementWrongNamespace(base.XmlReader.NamespaceURI, base.XmlReader.ODataNamespace));
     }
     while (base.XmlReader.MoveToNextAttribute())
     {
         if (base.XmlReader.NamespaceEquals(base.XmlReader.ODataMetadataNamespace) && (base.XmlReader.LocalNameEquals(base.AtomTypeAttributeName) || base.XmlReader.LocalNameEquals(base.ODataNullAttributeName)))
         {
             throw new ODataException(Microsoft.Data.OData.Strings.ODataAtomCollectionDeserializer_TypeOrNullAttributeNotAllowed);
         }
     }
     base.XmlReader.MoveToElement();
     ODataCollectionStart start = new ODataCollectionStart {
         Name = base.XmlReader.LocalName
     };
     isCollectionElementEmpty = base.XmlReader.IsEmptyElement;
     if (!isCollectionElementEmpty)
     {
         base.XmlReader.Read();
     }
     return start;
 }
        /// <summary>
        /// Verifies that calling WriteStart is valid.
        /// </summary>
        /// <param name="synchronousCall">true if the call is to be synchronous; false otherwise.</param>
        /// <param name="collectionStart">The <see cref="ODataCollectionStart"/> representing the collection.</param>
        private void VerifyCanWriteStart(bool synchronousCall, ODataCollectionStart collectionStart)
        {
            ExceptionUtils.CheckArgumentNotNull(collectionStart, "collection");

            // we do not allow empty collection names
            // NOTE: null is allowed as collection name in JSON but not in ATOM;
            //       the ODataAtomCollectionWriter checks for null.
            string collectionName = collectionStart.Name;
            if (collectionName != null && collectionName.Length == 0)
            {
                throw new ODataException(Strings.ODataCollectionWriterCore_CollectionsMustNotHaveEmptyName);
            }

            this.VerifyNotDisposed();
            this.VerifyCallAllowed(synchronousCall);
        }
 /// <summary>
 /// Start writing a collection.
 /// </summary>
 /// <param name="collectionStart">The <see cref="ODataCollectionStart"/> representing the collection.</param>
 protected abstract void StartCollection(ODataCollectionStart collectionStart);
 /// <summary>
 /// Asynchronously start writing a collection.
 /// </summary>
 /// <param name="collection">The <see cref="ODataCollectionStart"/> representing the collection.</param>
 /// <returns>A task instance that represents the asynchronous write operation.</returns>
 public sealed override Task WriteStartAsync(ODataCollectionStart collection)
 {
     this.VerifyCanWriteStart(false, collection);
     return TaskUtils.GetTaskForSynchronousOperation(() => this.WriteStartImplementation(collection));
 }
 /// <summary>
 /// Start writing a collection.
 /// </summary>
 /// <param name="collectionStart">The <see cref="ODataCollectionStart"/> representing the collection.</param>
 public sealed override void WriteStart(ODataCollectionStart collectionStart)
 {
     this.VerifyCanWriteStart(true, collectionStart);
     this.WriteStartImplementation(collectionStart);
 }
Exemple #12
0
 /// <summary>Asynchronously start writing a collection.</summary>
 /// <returns>A task instance that represents the asynchronous write operation.</returns>
 /// <param name="collectionStart">The <see cref="T:Microsoft.Data.OData.ODataCollectionStart" /> representing the collection.</param>
 public abstract Task WriteStartAsync(ODataCollectionStart collectionStart);
 protected override void StartCollection(ODataCollectionStart collectionStart)
 {
     this.jsonCollectionSerializer.WriteCollectionStart();
 }
 /// <summary>
 /// Start writing a collection.
 /// </summary>
 /// <param name="collectionStart">The <see cref="ODataCollectionStart"/> representing the collection.</param>
 public sealed override void WriteStart(ODataCollectionStart collectionStart)
 {
     this.VerifyCanWriteStart(true, collectionStart);
     this.WriteStartImplementation(collectionStart);
 }
Exemple #15
0
        internal void WriteBodyOperationParameters(List<BodyOperationParameter> operationParameters, ODataRequestMessageWrapper requestMessage)
        {
            using (ODataMessageWriter writer = CreateMessageWriter(requestMessage, this.requestInfo))
            {
                ODataParameterWriter writer2 = writer.CreateODataParameterWriter(null);
                writer2.WriteStart();
                foreach (OperationParameter parameter in operationParameters)
                {
                    IEnumerator enumerator;
                    ODataCollectionWriter writer3;
                    object obj2;
                    if (parameter.Value == null)
                    {
                        writer2.WriteValue(parameter.Name, parameter.Value);
                        continue;
                    }
                    ClientEdmModel model = ClientEdmModel.GetModel(this.requestInfo.MaxProtocolVersion);
                    IEdmType orCreateEdmType = model.GetOrCreateEdmType(parameter.Value.GetType());
                    switch (orCreateEdmType.TypeKind)
                    {
                        case EdmTypeKind.Primitive:
                        {
                            writer2.WriteValue(parameter.Name, parameter.Value);
                            continue;
                        }
                        case EdmTypeKind.Complex:
                        {
                            ODataComplexValue parameterValue = this.CreateODataComplexValue(model.GetClientTypeAnnotation(orCreateEdmType).ElementType, parameter.Value, null, false, null);
                            writer2.WriteValue(parameter.Name, parameterValue);
                            continue;
                        }
                        case EdmTypeKind.Collection:
                        {
                            enumerator = ((ICollection) parameter.Value).GetEnumerator();
                            writer3 = writer2.CreateCollectionWriter(parameter.Name);
                            ODataCollectionStart collectionStart = new ODataCollectionStart();
                            writer3.WriteStart(collectionStart);
                            goto Label_016D;
                        }
                        default:
                            throw new NotSupportedException(System.Data.Services.Client.Strings.Serializer_InvalidParameterType(parameter.Name, orCreateEdmType.TypeKind));
                    }
                Label_00D3:
                    obj2 = enumerator.Current;
                    if (obj2 == null)
                    {
                        throw new NotSupportedException(System.Data.Services.Client.Strings.Serializer_NullCollectionParamterItemValue(parameter.Name));
                    }
                    IEdmType edmType = model.GetOrCreateEdmType(obj2.GetType());
                    switch (edmType.TypeKind)
                    {
                        case EdmTypeKind.Primitive:
                            writer3.WriteItem(obj2);
                            break;

                        case EdmTypeKind.Complex:
                        {
                            ODataComplexValue item = this.CreateODataComplexValue(model.GetClientTypeAnnotation(edmType).ElementType, obj2, null, false, null);
                            writer3.WriteItem(item);
                            break;
                        }
                        default:
                            throw new NotSupportedException(System.Data.Services.Client.Strings.Serializer_InvalidCollectionParamterItemType(parameter.Name, edmType.TypeKind));
                    }
                Label_016D:
                    if (enumerator.MoveNext())
                    {
                        goto Label_00D3;
                    }
                    writer3.WriteEnd();
                    writer3.Flush();
                }
                writer2.WriteEnd();
                writer2.Flush();
            }
        }
 private void VerifyCanWriteStart(bool synchronousCall, ODataCollectionStart collectionStart)
 {
     ExceptionUtils.CheckArgumentNotNull<ODataCollectionStart>(collectionStart, "collection");
     string name = collectionStart.Name;
     if ((name != null) && (name.Length == 0))
     {
         throw new ODataException(Microsoft.Data.OData.Strings.ODataCollectionWriterCore_CollectionsMustNotHaveEmptyName);
     }
     this.VerifyNotDisposed();
     this.VerifyCallAllowed(synchronousCall);
 }
Exemple #17
0
 protected override void WriteTopLevelElements(IExpandedResult expanded, IEnumerator elements, bool hasMoved)
 {
     if (base.RequestDescription.LinkUri)
     {
         bool needPop = base.PushSegmentForRoot();
         this.WriteLinkCollection(elements, hasMoved);
         base.PopSegmentName(needPop);
     }
     else
     {
         this.collectionWriter = this.writer.CreateODataCollectionWriter();
         ODataCollectionStart collectionStart = new ODataCollectionStart {
             Name = this.ComputeContainerName()
         };
         this.collectionWriter.WriteStart(collectionStart);
         while (hasMoved)
         {
             object current = elements.Current;
             ResourceType propertyResourceType = (current == null) ? base.RequestDescription.TargetResourceType : WebUtil.GetResourceType(base.Provider, current);
             if (propertyResourceType == null)
             {
                 throw new InvalidOperationException(System.Data.Services.Strings.Serializer_UnsupportedTopLevelType(current.GetType()));
             }
             this.collectionWriter.WriteItem(base.GetPropertyValue("element", propertyResourceType, current, false));
             hasMoved = elements.MoveNext();
         }
         this.collectionWriter.WriteEnd();
         this.collectionWriter.Flush();
     }
 }
 /// <summary>
 /// Start writing a collection - implementation of the actual functionality.
 /// </summary>
 /// <param name="collectionStart">The <see cref="ODataCollectionStart"/> representing the collection.</param>
 private void WriteStartImplementation(ODataCollectionStart collectionStart)
 {
     this.StartPayloadInStartState();
     this.EnterScope(CollectionWriterState.Collection, collectionStart);
     this.InterceptException(() => this.StartCollection(collectionStart));
 }
 public abstract void WriteStart(ODataCollectionStart collectionStart);
        /// <summary>
        /// Start writing a collection.
        /// </summary>
        /// <param name="collectionStart">The <see cref="ODataCollectionStart"/> representing the collection.</param>
        protected override void StartCollection(ODataCollectionStart collectionStart)
        {
            Debug.Assert(collectionStart != null, "collection != null");

            string collectionName = collectionStart.Name;
            if (collectionName == null)
            {
                // null collection names are not allowed in ATOM
                throw new ODataException(o.Strings.ODataAtomCollectionWriter_CollectionNameMustNotBeNull);
            }

            // Note that we don't perform metadata validation of the name of the collection.
            // This is because there are multiple possibilities (service operation, action, function, top-level property)
            // and without more information we can't know which one to look for.

            // <collectionName>
            this.atomOutputContext.XmlWriter.WriteStartElement(collectionName, this.atomCollectionSerializer.MessageWriterSettings.WriterBehavior.ODataNamespace);

            // xmlns:="ODataNamespace"
            this.atomOutputContext.XmlWriter.WriteAttributeString(
                AtomConstants.XmlnsNamespacePrefix,
                AtomConstants.XmlNamespacesNamespace,
                this.atomCollectionSerializer.MessageWriterSettings.WriterBehavior.ODataNamespace);

            this.atomCollectionSerializer.WriteDefaultNamespaceAttributes(
                ODataAtomSerializer.DefaultNamespaceFlags.ODataMetadata |
                ODataAtomSerializer.DefaultNamespaceFlags.Gml |
                ODataAtomSerializer.DefaultNamespaceFlags.GeoRss);
        }
 /// <summary>
 /// Start writing a collection.
 /// </summary>
 /// <param name="collectionStart">The <see cref="ODataCollectionStart"/> representing the collection.</param>
 protected abstract void StartCollection(ODataCollectionStart collectionStart);
 public abstract Task WriteStartAsync(ODataCollectionStart collectionStart);
 /// <summary>
 /// Start writing a collection - implementation of the actual functionality.
 /// </summary>
 /// <param name="collectionStart">The <see cref="ODataCollectionStart"/> representing the collection.</param>
 private void WriteStartImplementation(ODataCollectionStart collectionStart)
 {
     this.StartPayloadInStartState();
     this.EnterScope(CollectionWriterState.Collection, collectionStart);
     this.InterceptException(() => this.StartCollection(collectionStart));
 }
Exemple #24
0
 /// <summary>Start writing a collection.</summary>
 /// <param name="collectionStart">The <see cref="T:Microsoft.Data.OData.ODataCollectionStart" /> representing the collection.</param>
 public abstract void WriteStart(ODataCollectionStart collectionStart);