Exemple #1
0
        internal void WriteOperation(ODataOperation operation)
        {
            string str;

            WriterValidationUtils.ValidateOperation(operation, base.WritingResponse);
            if (operation is ODataAction)
            {
                str = "action";
            }
            else
            {
                str = "function";
            }
            base.XmlWriter.WriteStartElement("m", str, "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
            string str2 = base.UriToUrlAttributeValue(operation.Metadata, false);

            base.XmlWriter.WriteAttributeString("metadata", str2);
            if (operation.Title != null)
            {
                base.XmlWriter.WriteAttributeString("title", operation.Title);
            }
            string str3 = base.UriToUrlAttributeValue(operation.Target);

            base.XmlWriter.WriteAttributeString("target", str3);
            base.XmlWriter.WriteEndElement();
        }
Exemple #2
0
        /// <summary>
        /// Writes an operation (an action or a function).
        /// </summary>
        /// <param name="operation">The association link to write.</param>
        internal void WriteOperation(ODataOperation operation)
        {
            DebugUtils.CheckNoExternalCallers();

            // checks for null and validates its properties
            WriterValidationUtils.ValidateOperation(operation, this.WritingResponse);

            string elementName;

            if (operation is ODataAction)
            {
                elementName = AtomConstants.ODataActionElementName;
            }
            else
            {
                Debug.Assert(operation is ODataFunction, "operation is either an ODataAction or an ODataFunction");
                elementName = AtomConstants.ODataFunctionElementName;
            }

            // <m:action ... or <m:function ...
            this.XmlWriter.WriteStartElement(
                AtomConstants.ODataMetadataNamespacePrefix,
                elementName,
                AtomConstants.ODataMetadataNamespace);

            // write the attributes of the action/function

            // The metadata URI of an ODataOperation can be relative.
            string metadataAttributeValue = this.UriToUrlAttributeValue(operation.Metadata, /*failOnRelativeUriWithoutBaseUri*/ false);

            this.XmlWriter.WriteAttributeString(AtomConstants.ODataOperationMetadataAttribute, metadataAttributeValue);

            if (operation.Title != null)
            {
                this.XmlWriter.WriteAttributeString(AtomConstants.ODataOperationTitleAttribute, operation.Title);
            }

            string targetAttribute = this.UriToUrlAttributeValue(operation.Target);

            this.XmlWriter.WriteAttributeString(AtomConstants.ODataOperationTargetAttribute, targetAttribute);

            // </m:action> or </m:function>
            this.XmlWriter.WriteEndElement();
        }
        /// <summary>
        /// Writes "actions" or "functions" metadata.
        /// </summary>
        /// <param name="operations">The operations to write.</param>
        /// <param name="isAction">true when writing the entry's actions; false when writing the entry's functions.</param>
        private void WriteOperations(IEnumerable <ODataOperation> operations, bool isAction)
        {
            DebugUtils.CheckNoExternalCallers();
            bool   firstOperation = true;
            string operationName  = isAction ? JsonConstants.ODataActionsMetadataName : JsonConstants.ODataFunctionsMetadataName;

            // we cannot compare two URI's directly because the 'Equals' method on the 'Uri' class compares two 'Uri' instances without regard to the
            // fragment part of the URI. (E.G: For 'http://someuri/index.htm#EC.action1' and http://someuri/index.htm#EC.action2', the 'Equals' method
            // will return true.
            var metadataGroups = operations.GroupBy(o =>
            {
                // We need to validate here to ensure that the metadata is not null, otherwise call to the method 'UriToString' will throw.
                ValidationUtils.ValidateOperationNotNull(o, isAction);
                WriterValidationUtils.ValidateOperation(o, this.WritingResponse);

                return(this.UriToUriString(o.Metadata, /*makeAbsolute*/ false));
            });

            foreach (IGrouping <string, ODataOperation> metadataGroup in metadataGroups)
            {
                if (firstOperation)
                {
                    // write the the object only if there is any operations.
                    this.JsonWriter.WriteName(operationName);
                    this.JsonWriter.StartObjectScope();
                    firstOperation = false;
                }

                this.WriteOperationMetadataGroup(metadataGroup);
            }

            // close the object if there is any operations.
            if (!firstOperation)
            {
                this.JsonWriter.EndObjectScope();
            }
        }
Exemple #4
0
        private void WriteOperations(IEnumerable <ODataOperation> operations, bool isAction)
        {
            bool   flag = true;
            string name = isAction ? "actions" : "functions";

            foreach (IGrouping <string, ODataOperation> grouping in operations.GroupBy <ODataOperation, string>(delegate(ODataOperation o) {
                ValidationUtils.ValidateOperationNotNull(o, isAction);
                WriterValidationUtils.ValidateOperation(o, this.WritingResponse);
                return(this.UriToUriString(o.Metadata, false));
            }))
            {
                if (flag)
                {
                    base.JsonWriter.WriteName(name);
                    base.JsonWriter.StartObjectScope();
                    flag = false;
                }
                this.WriteOperationMetadataGroup(grouping);
            }
            if (!flag)
            {
                base.JsonWriter.EndObjectScope();
            }
        }