Exemplo n.º 1
0
        /// <summary>
        /// Gets sub item of the specified EntityContainer instance by the name
        /// </summary>
        /// <param name="container">The EntityContainer instance</param>
        /// <param name="name">The name of sub item</param>
        /// <returns>sub item object if one is found; null otherwise</returns>
        private static ODataUriItem GetItem(EntityContainer container, string name)
        {
            ODataUriItem result = null;

            EntitySet entitySet;
            bool      isEntitySet = container.TryGetEntitySetByName(name, false, out entitySet);

            if (isEntitySet)
            {
                return(new ODataUriItem(entitySet, UriType.URI1));
            }
            else
            {
                var fs = container.FunctionImports.Where(x => x.Name.Equals(name, StringComparison.Ordinal));
                if (fs.Any())
                {
                    EdmFunction func       = fs.First();
                    var         retVal     = func.ReturnParameter;
                    var         retType    = retVal.TypeUsage.EdmType;
                    UriType     retUriType = GetUriTypeOfFuncReturn(retType);
                    if (retUriType == UriType.URI11 || retUriType == UriType.URI13 || retUriType == UriType.URI_CollEt)
                    {
                        result = new ODataUriItem(((CollectionType)retType).TypeUsage.EdmType, retUriType);
                    }
                    else
                    {
                        result = new ODataUriItem(retType, retUriType);
                    }
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets MetadataItem object for URI relative path under the specified EntityContainer instance
        /// </summary>
        /// <param name="container">The EntityContainer instance</param>
        /// <param name="pathSegment">The URI relative path</param>
        /// <param name="uriType">Output parameter of UriType value</param>
        /// <returns>The MetadataItem instance if one is found; null otherwise</returns>
        private static MetadataItem GetTargetType(EntityContainer container, IEnumerable <string> pathSegment, ref UriType uriType)
        {
            ODataUriItem curr = new ODataUriItem(container, UriType.URI_Container);

            foreach (var segment in pathSegment)
            {
                // to normalize first segment
                string       segmentKey;
                string       segmentCore = ResourcePathHelper.ParseSegment(segment, out segmentKey);
                ODataUriItem subItem     = curr.GetItem(segmentCore);
                if (subItem == null)
                {
                    uriType = UriType.URIUNKNOWN;
                    return(null);
                }

                if (subItem.uriType == UriType.URI1 && !string.IsNullOrEmpty(segmentKey))
                {
                    subItem = new ODataUriItem(((EntitySet)subItem.Item).ElementType, UriType.URI2);
                }

                curr = subItem;
            }

            uriType = curr.uriType;
            return(curr.Item);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets sub item of the specified ComplexType instance by the name
        /// </summary>
        /// <param name="type">The ComplexType instance</param>
        /// <param name="name">The name of sub item</param>
        /// <returns>sub item object if one is found; null otherwise</returns>
        private static ODataUriItem GetItem(ComplexType type, string name)
        {
            ODataUriItem result = null;

            EdmProperty property;
            bool        isProperty = type.Properties.TryGetValue(name, false, out property);

            if (isProperty)
            {
                result = new ODataUriItem(property, property.BuiltInTypeKind == BuiltInTypeKind.ComplexType ? UriType.URI3 : UriType.URI5);
            }

            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets ODataUriItem instance by specified name
        /// </summary>
        /// <param name="name">name of sub item</param>
        /// <returns>sub-item if one is found; null otherwise</returns>
        public ODataUriItem GetItem(string name)
        {
            switch (this.uriType)
            {
            case UriType.URI_Container:
                return(GetItem((EntityContainer)this.Item, name));

            case UriType.URI1:
                return(GetItem((EntitySet)this.Item, name));

            case UriType.URI2:
                return(GetItem((EntityType)this.Item, name));

            case UriType.URI3:
                ComplexType ct = (ComplexType)((EdmProperty)this.Item).TypeUsage.EdmType;
                return(GetItem(ct, name));

            case UriType.URI4:
            case UriType.URI5:
            case UriType.URI14:
                if (name.Equals("$value", StringComparison.Ordinal))
                {
                    return(this);
                }
                else
                {
                    return(null);
                }

            case UriType.URI6:
                RelationshipEndMember asso = (RelationshipEndMember)this.Item;
                var alias = new ODataUriItem(asso.GetEntityType(), UriType.URI2);
                return(alias.GetItem(name));

            case UriType.URI_Link:
                var next = GetItem((EntityType)this.Item, name);
                if (next.uriType == UriType.URI6)
                {
                    return(new ODataUriItem(next.Item, UriType.URI7));
                }
                else
                {
                    return(null);
                }

            default:
                return(null);
            }
        }
        /// <summary>
        /// Gets collection of RelationshipEndMember as navigation targets along the navigation path from the EntityType object 
        /// </summary>
        /// <param name="entityType">The EntityType instance to start with</param>
        /// <param name="navigation">The navigation path</param>
        /// <returns>Collection of navigation targets</returns>
        public static IEnumerable<RelationshipEndMember> GetNavigationStack(EntityType entityType, IEnumerable<string> navigation)
        {
            var result = new List<RelationshipEndMember>();

            EntityType currEntityType = entityType;
            UriType uriType = UriType.URI2;
            foreach(var nav in navigation)
            {
                ODataUriItem curr = new ODataUriItem(currEntityType, uriType);
                var next = curr.GetItem(nav);
                RelationshipEndMember navRole = (RelationshipEndMember)next.Item;
                result.Add(navRole);
                currEntityType = navRole.GetEntityType();
            }

            return result;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets collection of RelationshipEndMember as navigation targets along the navigation path from the EntityType object
        /// </summary>
        /// <param name="entityType">The EntityType instance to start with</param>
        /// <param name="navigation">The navigation path</param>
        /// <returns>Collection of navigation targets</returns>
        public static IEnumerable <RelationshipEndMember> GetNavigationStack(EntityType entityType, IEnumerable <string> navigation)
        {
            var result = new List <RelationshipEndMember>();

            EntityType currEntityType = entityType;
            UriType    uriType        = UriType.URI2;

            foreach (var nav in navigation)
            {
                ODataUriItem          curr    = new ODataUriItem(currEntityType, uriType);
                var                   next    = curr.GetItem(nav);
                RelationshipEndMember navRole = (RelationshipEndMember)next.Item;
                result.Add(navRole);
                currEntityType = navRole.GetEntityType();
            }

            return(result);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Gets ODataUriItem instance by specified name
 /// </summary>
 /// <param name="name">name of sub item</param>
 /// <returns>sub-item if one is found; null otherwise</returns>
 public ODataUriItem GetItem(string name)
 {
     switch (this.uriType)
     {
         case UriType.URI_Container:
             return GetItem((EntityContainer)this.Item, name);
         case UriType.URI1:
             return GetItem((EntitySet)this.Item, name);
         case UriType.URI2:
             return GetItem((EntityType)this.Item, name);
         case UriType.URI3:
             ComplexType ct = (ComplexType)((EdmProperty)this.Item).TypeUsage.EdmType;
             return GetItem(ct, name);
         case UriType.URI4:
         case UriType.URI5:
         case UriType.URI14:
             if (name.Equals("$value", StringComparison.Ordinal))
             {
                 return this;
             }
             else
             {
                 return null;
             }
         case UriType.URI6:
             RelationshipEndMember asso = (RelationshipEndMember)this.Item;
             var alias = new ODataUriItem(asso.GetEntityType(), UriType.URI2);
             return alias.GetItem(name);
         case UriType.URI_Link:
             var next = GetItem((EntityType)this.Item, name);
             if (next.uriType == UriType.URI6)
             {
                 return new ODataUriItem(next.Item, UriType.URI7);
             }
             else
             {
                 return null;
             }
         default:
             return null;
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// Gets sub item of the specified EntityType instance by the name
        /// </summary>
        /// <param name="entityType">The EntityType instance</param>
        /// <param name="name">The name of sub item</param>
        /// <returns>sub item object if one is found; null otherwise</returns>
        private static ODataUriItem GetItem(EntityType entityType, string name)
        {
            if (name.Equals("$links", StringComparison.Ordinal))
            {
                return(new ODataUriItem(entityType, UriType.URI_Link));
            }
            else if (name.Equals("$count", StringComparison.Ordinal))
            {
                return(new ODataUriItem(entityType, UriType.URI16));
            }
            else if (name.Equals("$value", StringComparison.Ordinal))
            {
                return(new ODataUriItem(entityType, UriType.URI17));
            }
            else
            {
                ODataUriItem result = null;

                EdmProperty property;
                bool        isProperty = entityType.Properties.TryGetValue(name, false, out property);
                if (isProperty)
                {
                    EdmType targetType = property.TypeUsage.EdmType;
                    result = new ODataUriItem(property, targetType.BuiltInTypeKind == BuiltInTypeKind.ComplexType ? UriType.URI3 : UriType.URI5);
                }
                else
                {
                    NavigationProperty navProperty;
                    bool isNavProperty = entityType.NavigationProperties.TryGetValue(name, false, out navProperty);
                    if (isNavProperty)
                    {
                        result = new ODataUriItem(navProperty.ToEndMember, UriType.URI6);
                    }
                }

                return(result);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Gets sub item of the specified EntityContainer instance by the name 
        /// </summary>
        /// <param name="container">The EntityContainer instance</param>
        /// <param name="name">The name of sub item</param>
        /// <returns>sub item object if one is found; null otherwise</returns>
        private static ODataUriItem GetItem(EntityContainer container, string name)
        {
            ODataUriItem result = null;

            EntitySet entitySet;
            bool isEntitySet = container.TryGetEntitySetByName(name, false, out entitySet);
            if (isEntitySet)
            {
                return new ODataUriItem(entitySet, UriType.URI1);
            }
            else
            {
                var fs = container.FunctionImports.Where(x => x.Name.Equals(name, StringComparison.Ordinal));
                if (fs.Any())
                {
                    EdmFunction func = fs.First();
                    var retVal = func.ReturnParameter;
                    var retType = retVal.TypeUsage.EdmType;
                    UriType retUriType = GetUriTypeOfFuncReturn(retType);
                    if (retUriType == UriType.URI11 || retUriType == UriType.URI13 || retUriType == UriType.URI_CollEt)
                    {
                        result = new ODataUriItem(((CollectionType)retType).TypeUsage.EdmType, retUriType);
                    }
                    else
                    {
                        result = new ODataUriItem(retType, retUriType);
                    }
                }
            }

            return result;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Gets sub item of the specified ComplexType instance by the name 
        /// </summary>
        /// <param name="type">The ComplexType instance</param>
        /// <param name="name">The name of sub item</param>
        /// <returns>sub item object if one is found; null otherwise</returns>
        private static ODataUriItem GetItem(ComplexType type, string name)
        {
            ODataUriItem result = null;

            EdmProperty property;
            bool isProperty = type.Properties.TryGetValue(name, false, out property);
            if (isProperty)
            {
                result = new ODataUriItem(property, property.BuiltInTypeKind == BuiltInTypeKind.ComplexType ? UriType.URI3 : UriType.URI5);
            }

            return result;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Gets sub item of the specified EntityType instance by the name 
        /// </summary>
        /// <param name="entityType">The EntityType instance</param>
        /// <param name="name">The name of sub item</param>
        /// <returns>sub item object if one is found; null otherwise</returns>
        private static ODataUriItem GetItem(EntityType entityType, string name)
        {
            if (name.Equals("$links", StringComparison.Ordinal))
            {
                return new ODataUriItem(entityType, UriType.URI_Link);
            }
            else if (name.Equals("$count", StringComparison.Ordinal))
            {
                return new ODataUriItem(entityType, UriType.URI16);
            }
            else if (name.Equals("$value", StringComparison.Ordinal))
            {
                return new ODataUriItem(entityType, UriType.URI17);
            }
            else
            {
                ODataUriItem result = null;

                EdmProperty property;
                bool isProperty = entityType.Properties.TryGetValue(name, false, out property);
                if (isProperty)
                {
                    EdmType targetType = property.TypeUsage.EdmType;
                    result = new ODataUriItem(property, targetType.BuiltInTypeKind == BuiltInTypeKind.ComplexType ? UriType.URI3 : UriType.URI5);
                }
                else
                {
                    NavigationProperty navProperty;
                    bool isNavProperty = entityType.NavigationProperties.TryGetValue(name, false, out navProperty);
                    if (isNavProperty)
                    {
                        result = new ODataUriItem(navProperty.ToEndMember, UriType.URI6);
                    }
                }

                return result;
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Gets MetadataItem object for URI relative path under the specified EntityContainer instance 
        /// </summary>
        /// <param name="container">The EntityContainer instance</param>
        /// <param name="pathSegment">The URI relative path</param>
        /// <param name="uriType">Output parameter of UriType value</param>
        /// <returns>The MetadataItem instance if one is found; null otherwise</returns>
        private static MetadataItem GetTargetType(EntityContainer container, IEnumerable<string> pathSegment, ref UriType uriType)
        {
            ODataUriItem curr = new ODataUriItem(container, UriType.URI_Container);
            foreach (var segment in pathSegment)
            {
                // to normalize first segment
                string segmentKey;
                string segmentCore = ResourcePathHelper.ParseSegment(segment, out segmentKey);
                ODataUriItem subItem = curr.GetItem(segmentCore);
                if (subItem == null)
                {
                    uriType = UriType.URIUNKNOWN;
                    return null;
                }

                if (subItem.uriType == UriType.URI1 && !string.IsNullOrEmpty(segmentKey))
                {
                    subItem = new ODataUriItem(((EntitySet)subItem.Item).ElementType, UriType.URI2);
                }

                curr = subItem;
            }

            uriType = curr.uriType;
            return curr.Item;
        }