Exemplo n.º 1
0
        /// <summary>
        /// Remove the type-cast segment in the end of ODataPath, the method does not modify current ODataPath instance,
        /// it returns a new ODataPath without ending type segment.
        /// </summary>
        /// <param name="path">Path to perform the computation on.</param>
        /// <returns>The ODataPath without type-cast in the end</returns>
        public static ODataPath TrimEndingTypeSegment(this ODataPath path)
        {
            var handler = new SplitEndingSegmentOfTypeHandler <TypeSegment>();

            path.WalkWith(handler);
            return(handler.FirstPart);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Append the key segment in the end of ODataPath, the method does not modify current ODataPath instance,
        /// it returns a new ODataPath without ending type segment.
        /// If last segment is type cast, the key would be appended before type cast segment.
        /// </summary>
        /// <param name="path">Path to perform the computation on.</param>
        /// <param name="keys">The set of key property names and the values to be used in searching for the given item.</param>
        /// <param name="edmType">The type of the item this key returns.</param>
        /// <param name="navigationSource">The navigation source that this key is used to search.</param>
        /// <returns>The ODataPath with key segment appended</returns>
        public static ODataPath AppendKeySegment(this ODataPath path, IEnumerable <KeyValuePair <string, object> > keys, IEdmEntityType edmType, IEdmNavigationSource navigationSource)
        {
            var handler = new SplitEndingSegmentOfTypeHandler <TypeSegment>();

            path.WalkWith(handler);
            KeySegment keySegment = new KeySegment(keys, edmType, navigationSource);
            ODataPath  newPath    = handler.FirstPart;

            newPath.Add(keySegment);
            foreach (var segment in handler.LastPart)
            {
                newPath.Add(segment);
            }

            return(newPath);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Remove the key segment in the end of ODataPath, the method does not modify current ODataPath instance,
        /// it returns a new ODataPath without ending type segment.
        /// If last segment is type cast, the key before type cast segment would be removed.
        /// </summary>
        /// <param name="path">Path to perform the computation on.</param>
        /// <returns>The ODataPath without key segment removed</returns>
        public static ODataPath TrimEndingKeySegment(this ODataPath path)
        {
            var typeHandler = new SplitEndingSegmentOfTypeHandler <TypeSegment>();
            var keyHandler  = new SplitEndingSegmentOfTypeHandler <KeySegment>();

            path.WalkWith(typeHandler);
            typeHandler.FirstPart.WalkWith(keyHandler);
            ODataPath newPath = keyHandler.FirstPart;

            foreach (var segment in typeHandler.LastPart)
            {
                newPath.Add(segment);
            }

            return(newPath);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Translates an ODL path to Web API path.
        /// </summary>
        /// <param name="path">The ODL path to be translated.</param>
        /// <param name="model">The model used to translate.</param>
        /// <param name="unresolvedPathSegment">Unresolved path segment.</param>
        /// <param name="id">The key segment from $id.</param>
        /// <param name="enableUriTemplateParsing">Specifies the ODL path is template or not.</param>
        /// <param name="parameterAliasNodes">The parameter alias nodes info.</param>
        /// <param name="queryString">The query string.</param>
        /// <returns>The translated Web API path.</returns>
        public static ODataPath TranslateODLPathToWebAPIPath(
            Semantic.ODataPath path,
            IEdmModel model,
            UnresolvedPathSegment unresolvedPathSegment,
            KeySegment id,
            bool enableUriTemplateParsing,
            IDictionary <string, SingleValueNode> parameterAliasNodes,
            NameValueCollection queryString)
        {
            if (path == null)
            {
                throw Error.ArgumentNull("path");
            }
            if (model == null)
            {
                throw Error.ArgumentNull("model");
            }
            if (parameterAliasNodes == null)
            {
                throw Error.ArgumentNull("parameterAliasNodes");
            }

            IList <ODataPathSegment> segments = path.WalkWith(
                new ODataPathSegmentTranslator(model, enableUriTemplateParsing, parameterAliasNodes, queryString))
                                                .SelectMany(s => s).ToList();

            if (unresolvedPathSegment != null)
            {
                segments.Add(unresolvedPathSegment);
            }

            if (!enableUriTemplateParsing)
            {
                AppendIdForRef(segments, id);
            }

            ReverseRefPathSegmentAndKeyValuePathSegment(segments);
            ODataPath odataPath = new ODataPath(segments);

            odataPath.ODLPath = path;

            return(odataPath);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Get the string representation of <see cref="ODataPath"/>.
 /// mainly translate Query Url path.
 /// </summary>
 /// <param name="path">Path to perform the computation on.</param>
 /// <param name="urlConventions">Mark whether key is segment</param>
 /// <returns>The string representation of the Query Url path.</returns>
 public static string ToResourcePathString(this ODataPath path, ODataUrlConventions urlConventions)
 {
     return(string.Concat(path.WalkWith(new PathSegmentToResourcePathTranslator(urlConventions.UrlConvention)).ToArray()).TrimStart('/'));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Get the string representation of <see cref="ODataPath"/>.
 /// mainly translate Context Url path.
 /// </summary>
 /// <param name="path">Path to perform the computation on.</param>
 /// <returns>The string representation of the Context Url path.</returns>
 public static string ToContextUrlPathString(this ODataPath path)
 {
     return(string.Concat(path.WalkWith(PathSegmentToContextUrlPathTranslator.DefaultInstance).ToArray()).TrimStart('/'));
 }
Exemplo n.º 7
0
 /// <summary>
 /// Get the string representation of <see cref="ODataPath"/>.
 /// </summary>
 /// <param name="path">Path to perform the computation on.</param>
 /// <returns>The string representation of the path.</returns>
 public static string ToResourcePathString(this ODataPath path)
 {
     return(string.Concat(path.WalkWith(PathSegmentToResourcePathTranslator.DefaultInstance)).TrimStart('/'));
 }