Exemplo n.º 1
0
        private void ProcessSelectExpandItem(SelectExpandClause clause, EdmNode edmNode, CustomNavigationProperty parentCustomNavProp, NavigationPropertySegment parentSegment)
        {
            if (edmNode == null)
            {
                var entityType = parentSegment.EdmType.AsElementType() as EdmEntityType;
                var RdfNode    = new VariablePattern($"{parentSegment.NavigationProperty.Name}");
                edmNode = new EdmNode()
                {
                    Name        = parentSegment.NavigationProperty.Name,
                    ItemEdmType = entityType,
                    RdfNode     = RdfNode,
                    //StructProperties = entityType.StructuralProperties().ToList(),
                    NavProperties = new List <CustomNavigationProperty>()
                };
                parentCustomNavProp.NestedEdmNodes.Add(edmNode);
            }

            List <IEdmStructuralProperty> structPropList = new List <IEdmStructuralProperty>();

            foreach (var item in clause.SelectedItems)
            {
                var selectItem = item as PathSelectItem;
                if (selectItem != null && selectItem.SelectedPath != null)
                {
                    var segment = selectItem.SelectedPath.FirstSegment as PropertySegment;
                    if (segment != null)
                    {
                        structPropList.Add(segment.Property);
                    }
                }

                var expandItem = item as ExpandedNavigationSelectItem;
                if (expandItem != null)
                {
                    var segment = expandItem.PathToNavigationProperty.FirstSegment as NavigationPropertySegment;
                    if (segment != null && expandItem.SelectAndExpand != null)
                    {
                        CustomNavigationProperty customNavProp = new CustomNavigationProperty();
                        edmNode.NavProperties.Add(customNavProp);
                        customNavProp.NestedEdmNodes     = new List <EdmNode>();
                        customNavProp.NavigationProperty = segment.NavigationProperty;
                        customNavProp.Filters            = expandItem.FilterOption != null ? expandItem.FilterOption.Expression : null;
                        customNavProp.Top     = expandItem.TopOption.GetValueOrDefault();
                        customNavProp.Skip    = expandItem.SkipOption.GetValueOrDefault();
                        customNavProp.OrderBy = expandItem.OrderByOption;
                        ProcessSelectExpandItem(expandItem.SelectAndExpand, null, customNavProp, segment);
                    }
                }
            }
            if (structPropList.Count > 0)
            {
                //edmNode.StructProperties = structPropList;
                if (parentCustomNavProp != null)
                {
                    parentCustomNavProp.StructProperties = structPropList;
                }
            }
        }
Exemplo n.º 2
0
        private void ProcessOdataPath()
        {
            foreach (var seg in QueryOptions.Context.Path.Segments)
            {
                if (seg is EntitySetSegment)
                {
                    var setSeg     = seg as EntitySetSegment;
                    var entityType = setSeg.EdmType.AsElementType() as EdmEntityType;
                    var rdfNode    = new VariablePattern($"{setSeg.EntitySet.Name}");
                    EdmNodeList.Add(new EdmNode()
                    {
                        Name             = setSeg.EntitySet.Name,
                        ItemEdmType      = entityType,
                        RdfNode          = rdfNode,
                        StructProperties = entityType.StructuralProperties().ToList(),
                        NavProperties    = new List <CustomNavigationProperty>()
                    });
                }
                else if (seg is KeySegment)
                {
                    var keys    = (seg as KeySegment).Keys.ToList();
                    Uri keyUri  = null;
                    var edmNode = EdmNodeList[EdmNodeList.Count - 1];
                    if (keys.Count() > 0)
                    {
                        edmNode.IdKey = keys[0].Value.ToString();
                        if (keys[0].Value.ToString().StartsWith(NamespaceUri.AbsoluteUri))
                        {
                            keyUri = new Uri(keys[0].Value.ToString());
                        }
                        else
                        {
                            keyUri = new Uri(NamespaceUri, keys[0].Value.ToString());
                        }
                    }
                    NodeFactory nodeFactory = new NodeFactory();
                    edmNode.RdfNode = new NodeMatchPattern(nodeFactory.CreateUriNode(keyUri));
                }

                else if (seg is NavigationPropertySegment || seg is NavigationPropertyLinkSegment)
                {
                    var                      propSeg     = seg as NavigationPropertySegment;
                    var                      propSegLink = seg as NavigationPropertyLinkSegment;
                    EdmEntityType            entityType;
                    CustomNavigationProperty navProp = new CustomNavigationProperty();
                    if (propSeg != null)
                    {
                        entityType = propSeg.EdmType.AsElementType() as EdmEntityType;
                        navProp.NavigationProperty = propSeg.NavigationProperty;
                    }
                    else
                    {
                        entityType = propSegLink.EdmType.AsElementType() as EdmEntityType;
                        navProp.NavigationProperty = propSegLink.NavigationProperty;
                    }
                    var edmNode = EdmNodeList[EdmNodeList.Count - 1];
                    edmNode.NavProperties.Add(navProp);

                    EdmNodeList.Add(new EdmNode()
                    {
                        Name             = navProp.NavigationProperty.Name,
                        ItemEdmType      = entityType,
                        RdfNode          = new VariablePattern($"{navProp.NavigationProperty.Name}"),
                        StructProperties = entityType.StructuralProperties().ToList(),
                        NavProperties    = new List <CustomNavigationProperty>()
                    });
                }
                else if (seg is PropertySegment)
                {
                    var propSeg = seg as PropertySegment;
                    var edmNode = EdmNodeList[EdmNodeList.Count - 1];
                    edmNode.StructProperties.Clear();
                    edmNode.StructProperties.Add(propSeg.Property);
                }
                else if (seg is CountSegment)
                {
                }
                else if (seg is ValueSegment)
                {
                }
                else
                {
                    throw new Exception($"Error with {seg.ToString()}");
                }
            }
        }