Пример #1
0
        /// <summary>
        /// Wraps the specified <paramref name="payload"/> into and Edmx envelope.
        /// </summary>
        /// <param name="payload">The <see cref="XElement"/> payload to wrap.</param>
        /// <param name="edmVersion">The Edm Version for the edmx envelope.</param>
        /// <returns>
        /// The Edmx wrapper that contains the <paramref name="payload"/>.
        /// </returns>
        public static XElement WrapInEdmxEnvelope(this XElement payload, EdmVersion edmVersion)
        {
            ExceptionUtilities.CheckArgumentNotNull(payload, "payload");

            XAttribute metadataNamespaceAttr = null;

            Version    edmxVersion   = edmVersion.ToEdmxVersion();
            XNamespace edmxNamespace = EdmxXNamespace(edmxVersion);

            return(new XElement(edmxNamespace + "Edmx",
                                new XAttribute(XNamespace.Xmlns + "edmx", edmxNamespace),
                                new XAttribute(EdmxVersionAttributeName, edmxVersion.ToString()),
                                new XElement(edmxNamespace + "DataServices",
                                             metadataNamespaceAttr,
                                             payload)));
        }
Пример #2
0
        /// <summary>
        /// Unwraps the <paramref name="envelope"/> Edmx envelope and returns the actual payload.
        /// </summary>
        /// <param name="envelope">The <see cref="XElement"/> reprsenting the Edmx envelope.</param>
        /// <param name="edmVersion">The Edm Version for the edmx envelope.</param>
        /// <returns>The payload that was wrapped by the Edmx envelope.</returns>
        public static XElement UnwrapEdmxEnvelope(this XElement envelope, EdmVersion edmVersion)
        {
            ExceptionUtilities.CheckArgumentNotNull(envelope, "envelope");

            Version    edmxVersion   = edmVersion.ToEdmxVersion();
            XNamespace edmxNamespace = EdmxXNamespace(edmxVersion);

            ExceptionUtilities.Assert(envelope.Name.Namespace == edmxNamespace && envelope.Name.LocalName == "Edmx", "Expected <edmx:Edmx> as the top-level element.");

            XAttribute versionAttribute = envelope.Attribute(EdmxVersionAttributeName);

            ExceptionUtilities.Assert(versionAttribute != null && versionAttribute.Value == edmxVersion.ToString(), "Edmx version attribute not valid.");

            XElement dataServicesElement = envelope.Element(edmxNamespace + "DataServices");

            ExceptionUtilities.Assert(dataServicesElement != null, "<DataServices> element not found.");

            return(dataServicesElement.Elements().Single());
        }
Пример #3
0
        /// <summary>
        /// Unwraps the <paramref name="envelope"/> Edmx envelope and returns the actual payload.
        /// </summary>
        /// <param name="envelope">The <see cref="XElement"/> reprsenting the Edmx envelope.</param>
        /// <param name="edmVersion">The Edm Version for the edmx envelope.</param>
        /// <returns>The payload that was wrapped by the Edmx envelope.</returns>
        public static XElement UnwrapEdmxEnvelope(this XElement envelope, EdmVersion edmVersion)
        {
            ExceptionUtilities.CheckArgumentNotNull(envelope, "envelope");

            Version edmxVersion = edmVersion.ToEdmxVersion();
            XNamespace edmxNamespace = EdmxXNamespace(edmxVersion);
            ExceptionUtilities.Assert(envelope.Name.Namespace == edmxNamespace && envelope.Name.LocalName == "Edmx", "Expected <edmx:Edmx> as the top-level element.");

            XAttribute versionAttribute = envelope.Attribute(EdmxVersionAttributeName);
            ExceptionUtilities.Assert(versionAttribute != null && versionAttribute.Value == edmxVersion.ToString(), "Edmx version attribute not valid.");

            XElement dataServicesElement = envelope.Element(edmxNamespace + "DataServices");
            ExceptionUtilities.Assert(dataServicesElement != null, "<DataServices> element not found.");

            return dataServicesElement.Elements().Single();
        }
Пример #4
0
        /// <summary>
        /// Wraps the specified <paramref name="payload"/> into and Edmx envelope.
        /// </summary>
        /// <param name="payload">The <see cref="XElement"/> payload to wrap.</param>
        /// <param name="edmVersion">The Edm Version for the edmx envelope.</param>
        /// <returns>
        /// The Edmx wrapper that contains the <paramref name="payload"/>.
        /// </returns>
        public static XElement WrapInEdmxEnvelope(this XElement payload, EdmVersion edmVersion)
        {
            ExceptionUtilities.CheckArgumentNotNull(payload, "payload");

            XAttribute metadataNamespaceAttr = null;

            Version edmxVersion = edmVersion.ToEdmxVersion();
            XNamespace edmxNamespace = EdmxXNamespace(edmxVersion);
            return new XElement(edmxNamespace + "Edmx", 
                new XAttribute(XNamespace.Xmlns + "edmx", edmxNamespace),
                new XAttribute(EdmxVersionAttributeName, edmxVersion.ToString()),
                new XElement(edmxNamespace + "DataServices",
                    metadataNamespaceAttr,
                    payload));
        }