Esempio n. 1
0
        /// <summary>
        /// Gets the short name of the entity for the context
        /// </summary>
        /// <param name="context">The context object which directly or indirectly points to an entry</param>
        /// <returns>The short name of entity</returns>
        public static string GetEntityName(ServiceContext context)
        {
            string entityName = context.EntityTypeShortName;

            if (string.IsNullOrEmpty(entityName))
            {
                var     edmxHelper   = new EdmxHelper(XElement.Parse(context.MetadataDocument));
                var     segments     = ResourcePathHelper.GetPathSegments(context);
                var     segsToEntity = GetEntryUriSegments(segments.Take(segments.Count() - 1), edmxHelper);
                UriType uriType;
                var     target = edmxHelper.GetTargetType(segsToEntity, out uriType);
                entityName = ((EntityType)target).Name;
            }
            return(entityName);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the target MetadataItem for sequence of uri path segments
        /// </summary>
        /// <param name="edmxHelper">The EdmxHelper class object</param>
        /// <param name="pathSegment">The sequence of uri path segment</param>
        /// <param name="uriType">Output parameter of UriType</param>
        /// <returns>The target MetadataItem for the uri path segments; or null if a meaningful one cannot be derived</returns>
        public static MetadataItem GetTargetType(this EdmxHelper edmxHelper, IEnumerable <string> pathSegment, out UriType uriType)
        {
            EntityContainer currContainer;
            string          leadSegment = pathSegment.First();
            var             containers  = from c in edmxHelper.containers where c.Name.Equals(leadSegment, System.StringComparison.Ordinal) select c;

            if (!containers.Any())
            {
                // get the default container
                currContainer = edmxHelper.containerDefault;
            }
            else
            {
                currContainer = containers.First();
                pathSegment   = pathSegment.Skip(1);
            }

            UriType uType  = UriType.URIUNKNOWN;
            var     result = GetTargetType(currContainer, pathSegment, ref uType);

            uriType = uType;
            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the segments pointing to an entry based
        /// </summary>
        /// <param name="segments">The segments pointing to derived resources of the entry</param>
        /// <param name="edmxHelper">The EdmxHelper instance</param>
        /// <returns>The segments pointing to the entry</returns>
        public static IEnumerable <string> GetEntryUriSegments(IEnumerable <string> segments, EdmxHelper edmxHelper)
        {
            if (!segments.Any())
            {
                return(segments);
            }

            UriType uriType;
            var     target = edmxHelper.GetTargetType(segments, out uriType);

            if (uriType == UriType.URI2)
            {
                return(segments);
            }

            return(GetEntryUriSegments(segments.Take(segments.Count() - 1), edmxHelper));
        }