Esempio n. 1
0
        /// <summary>
        /// Concatenates the given sequence of segment sets onto the given string builder
        /// </summary>
        /// <param name="converter">The uri to string converter to extend</param>
        /// <param name="builder">The string builder to append onto</param>
        /// <param name="segmentSets">The segment sets to append</param>
        public static void ConcatenateSegments(this IODataUriToStringConverter converter, StringBuilder builder, ODataUriSegmentPathCollection segmentSets)
        {
            ExceptionUtilities.CheckArgumentNotNull(converter, "converter");
            ExceptionUtilities.CheckArgumentNotNull(builder, "builder");
            ExceptionUtilities.CheckCollectionNotEmpty(segmentSets, "segmentSets");

            bool isFirstSegmentSet = true;

            foreach (var segments in segmentSets)
            {
                if (!isFirstSegmentSet)
                {
                    builder.Append(',');
                }

                isFirstSegmentSet = false;
                converter.ConcatenateSegments(builder, segments);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Concatenates the given sequence of segment sets into a comma and slash delimited string
        /// </summary>
        /// <param name="converter">The uri to string converter to extend</param>
        /// <param name="segmentSets">the segment sets to concatenate</param>
        /// <returns>the concatenated segment string</returns>
        public static string ConcatenateSegments(this IODataUriToStringConverter converter, ODataUriSegmentPathCollection segmentSets)
        {
            var builder = new StringBuilder();

            converter.ConcatenateSegments(builder, segmentSets);
            return(builder.ToString());
        }
Esempio n. 3
0
        /// <summary>
        /// Parses a collection of segment paths using the format expected for the '$expand' and '$select' query options
        /// </summary>
        /// <param name="type">The entity type the paths start from</param>
        /// <param name="toParse">The string to parse</param>
        /// <returns>The parsed collection of segment paths</returns>
        public static ODataUriSegmentPathCollection ParseSegmentPathCollection(EntityType type, string toParse)
        {
            ExceptionUtilities.CheckArgumentNotNull(toParse, "toParse");

            ODataUriSegmentPathCollection segmentPathCollection = new ODataUriSegmentPathCollection();

            foreach (string path in toParse.Trim().Split(','))
            {
                IList <ODataUriSegment> segmentPath = new List <ODataUriSegment>();

                IEnumerable <MemberProperty>     possibleProperties  = type.AllProperties;
                IEnumerable <NavigationProperty> possibleNavigations = type.AllNavigationProperties;

                foreach (string segment in path.Trim().Split('/'))
                {
                    EntityType matchingType;
                    if (TryGetEntityTypeInHierarchy(type, segment, out matchingType))
                    {
                        segmentPath.Add(new EntityTypeSegment(matchingType));
                        continue;
                    }

                    MemberProperty property = null;
                    if (possibleProperties != null)
                    {
                        property = possibleProperties.SingleOrDefault(p => p.Name == segment);
                    }

                    NavigationProperty navigation = null;
                    if (possibleNavigations != null)
                    {
                        navigation = possibleNavigations.SingleOrDefault(p => p.Name == segment);
                    }

                    if (property == null && navigation == null)
                    {
                        possibleProperties = null;
                        SystemSegment systemSegment;
                        if (SystemSegment.TryGet(segment, out systemSegment))
                        {
                            segmentPath.Add(systemSegment);
                        }
                        else
                        {
                            segmentPath.Add(new UnrecognizedSegment(segment));
                        }
                    }
                    else if (property != null)
                    {
                        possibleNavigations = null;

                        ComplexDataType complexType = property.PropertyType as ComplexDataType;
                        if (complexType != null)
                        {
                            possibleProperties = complexType.Definition.Properties;
                        }
                        else
                        {
                            possibleProperties  = null;
                            possibleNavigations = null;
                        }

                        segmentPath.Add(new PropertySegment(property));
                    }
                    else
                    {
                        possibleProperties  = navigation.ToAssociationEnd.EntityType.AllProperties;
                        possibleNavigations = navigation.ToAssociationEnd.EntityType.AllNavigationProperties;
                        segmentPath.Add(new NavigationSegment(navigation));
                    }
                }

                segmentPathCollection.Add(segmentPath);
            }

            return(segmentPathCollection);
        }