Пример #1
0
        private void ValidateSelectItem(SelectItem selectItem, IEdmProperty pathProperty, IEdmStructuredType pathStructuredType,
                                        IEdmModel edmModel)
        {
            PathSelectItem pathSelectItem = selectItem as PathSelectItem;

            if (pathSelectItem != null)
            {
                ODataPathSegment          segment = pathSelectItem.SelectedPath.LastSegment;
                NavigationPropertySegment navigationPropertySegment = segment as NavigationPropertySegment;
                if (navigationPropertySegment != null)
                {
                    IEdmNavigationProperty property = navigationPropertySegment.NavigationProperty;
                    if (EdmLibHelpers.IsNotNavigable(property, edmModel))
                    {
                        throw new ODataException(Error.Format(SRResources.NotNavigablePropertyUsedInNavigation,
                                                              property.Name));
                    }
                }
                else
                {
                    PropertySegment propertySegment = segment as PropertySegment;
                    if (propertySegment != null)
                    {
                        if (EdmLibHelpers.IsNotSelectable(propertySegment.Property, pathProperty, pathStructuredType, edmModel,
                                                          _defaultQuerySettings.EnableSelect))
                        {
                            throw new ODataException(Error.Format(SRResources.NotSelectablePropertyUsedInSelect,
                                                                  propertySegment.Property.Name));
                        }
                    }
                }
            }
            else
            {
                WildcardSelectItem wildCardSelectItem = selectItem as WildcardSelectItem;
                if (wildCardSelectItem != null)
                {
                    foreach (var property in pathStructuredType.StructuralProperties())
                    {
                        if (EdmLibHelpers.IsNotSelectable(property, pathProperty, pathStructuredType, edmModel,
                                                          _defaultQuerySettings.EnableSelect))
                        {
                            throw new ODataException(Error.Format(SRResources.NotSelectablePropertyUsedInSelect,
                                                                  property.Name));
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Build a wildcard selection item
        /// </summary>
        /// <param name="tokenIn">the token to bind to a wildcard</param>
        /// <param name="model">the model to search for this wildcard</param>
        /// <param name="item">the new wildcard selection item, if we found one</param>
        /// <returns>true if we successfully bound to a wildcard, false otherwise</returns>
        public static bool TryBindAsWildcard(PathSegmentToken tokenIn, IEdmModel model, out SelectItem item)
        {
            bool isTypeToken = tokenIn.IsNamespaceOrContainerQualified();
            bool wildcard    = tokenIn.Identifier.EndsWith("*", StringComparison.Ordinal);

            IEdmEntityContainer container;

            if (isTypeToken && wildcard && UriEdmHelpers.TryGetEntityContainer(tokenIn.Identifier.Substring(0, tokenIn.Identifier.LastIndexOf('.')), model, out container))
            {
                item = new ContainerQualifiedWildcardSelectItem(container);
                return(true);
            }

            if (tokenIn.Identifier == "*")
            {
                item = new WildcardSelectItem();
                return(true);
            }

            item = null;
            return(false);
        }
 /// <summary>
 /// Handle a WildcardSelectItem
 /// </summary>
 /// <param name="item">the item to Handle</param>
 public virtual void Handle(WildcardSelectItem item)
 {
     throw new NotImplementedException();
 }
Пример #4
0
        private void BuildSelections(
            SelectExpandClause selectExpandClause,
            HashSet<IEdmStructuralProperty> allStructuralProperties,
            HashSet<IEdmStructuralProperty> allNestedProperties,
            HashSet<IEdmNavigationProperty> allNavigationProperties,
            HashSet<IEdmAction> allActions,
            HashSet<IEdmFunction> allFunctions)
        {
            foreach (SelectItem selectItem in selectExpandClause.SelectedItems)
            {
                if (selectItem is ExpandedNavigationSelectItem)
                {
                    continue;
                }

                PathSelectItem pathSelectItem = selectItem as PathSelectItem;
                if (pathSelectItem != null)
                {
                    ValidatePathIsSupported(pathSelectItem.SelectedPath);
                    ODataPathSegment segment = pathSelectItem.SelectedPath.LastSegment;

                    NavigationPropertySegment navigationPropertySegment = segment as NavigationPropertySegment;
                    if (navigationPropertySegment != null)
                    {
                        IEdmNavigationProperty navigationProperty = navigationPropertySegment.NavigationProperty;
                        if (allNavigationProperties.Contains(navigationProperty))
                        {
                            SelectedNavigationProperties.Add(navigationProperty);
                        }
                        continue;
                    }

                    PropertySegment structuralPropertySegment = segment as PropertySegment;
                    if (structuralPropertySegment != null)
                    {
                        IEdmStructuralProperty structuralProperty = structuralPropertySegment.Property;
                        if (allStructuralProperties.Contains(structuralProperty))
                        {
                            SelectedStructuralProperties.Add(structuralProperty);
                        }
                        else if (allNestedProperties.Contains(structuralProperty))
                        {
                            SelectedComplexProperties.Add(structuralProperty);
                        }
                        continue;
                    }

                    OperationSegment operationSegment = segment as OperationSegment;
                    if (operationSegment != null)
                    {
                        AddOperations(allActions, allFunctions, operationSegment);
                        continue;
                    }

                    DynamicPathSegment dynamicPathSegment = segment as DynamicPathSegment;
                    if (dynamicPathSegment != null)
                    {
                        SelectedDynamicProperties.Add(dynamicPathSegment.Identifier);
                        continue;
                    }
                    throw new ODataException(Error.Format(SRResources.SelectionTypeNotSupported, segment.GetType().Name));
                }

                WildcardSelectItem wildCardSelectItem = selectItem as WildcardSelectItem;
                if (wildCardSelectItem != null)
                {
                    SelectedStructuralProperties = allStructuralProperties;
                    SelectedComplexProperties = allNestedProperties;
                    SelectedNavigationProperties = allNavigationProperties;
                    SelectAllDynamicProperties = true;
                    continue;
                }

                NamespaceQualifiedWildcardSelectItem wildCardActionSelection = selectItem as NamespaceQualifiedWildcardSelectItem;
                if (wildCardActionSelection != null)
                {
                    SelectedActions = allActions;
                    SelectedFunctions = allFunctions;
                    continue;
                }

                throw new ODataException(Error.Format(SRResources.SelectionTypeNotSupported, selectItem.GetType().Name));
            }
        }
Пример #5
0
 /// <summary>
 /// Translate a WildcardSelectItem
 /// </summary>
 /// <param name="item">the item to Translate</param>
 /// <returns>Defined by the implementer</returns>
 public override string Translate(WildcardSelectItem item)
 {
     return(string.Empty);
 }
Пример #6
0
        public static WildcardSelectItem ShouldBeWildcardSelectionItem(this SelectItem actual)
        {
            WildcardSelectItem wildSelectItem = actual.ShouldBeSelectedItemOfType <WildcardSelectItem>();

            return(wildSelectItem);
        }
        /// <summary>
        /// Build a wildcard selection item
        /// </summary>
        /// <param name="tokenIn">the token to bind to a wildcard</param>
        /// <param name="model">the model to search for this wildcard</param>
        /// <param name="item">the new wildcard selection item, if we found one</param>
        /// <returns>true if we successfully bound to a wildcard, false otherwise</returns>
        public static bool TryBindAsWildcard(PathSegmentToken tokenIn, IEdmModel model, out SelectItem item)
        {
            bool isTypeToken = tokenIn.IsNamespaceOrContainerQualified();
            bool wildcard = tokenIn.Identifier.EndsWith("*", StringComparison.Ordinal);

            if (isTypeToken && wildcard)
            {
                string namespaceName = tokenIn.Identifier.Substring(0, tokenIn.Identifier.Length - 2);

                if (model.DeclaredNamespaces.Any(declaredNamespace => declaredNamespace.Equals(namespaceName, StringComparison.Ordinal)))
                {
                    item = new NamespaceQualifiedWildcardSelectItem(namespaceName);
                    return true;
                }
            }

            if (tokenIn.Identifier == "*")
            {
                item = new WildcardSelectItem();
                return true;
            }

            item = null;
            return false;
        }
Пример #8
0
        /// <summary>
        /// Build $select and $expand clause
        /// </summary>
        /// <param name="selectExpandClause">The select expand clause</param>
        /// <param name="structuralTypeInfo">The structural type properties.</param>
        private void BuildSelectExpand(SelectExpandClause selectExpandClause, EdmStructuralTypeInfo structuralTypeInfo)
        {
            Contract.Assert(selectExpandClause != null);
            Contract.Assert(structuralTypeInfo != null);

            var currentLevelPropertiesInclude = new Dictionary <IEdmStructuralProperty, SelectExpandIncludedProperty>();

            // Explicitly set SelectAllDynamicProperties as false,
            // Below will re-set it as true if it meets the select all condition.
            SelectAllDynamicProperties = false;
            foreach (SelectItem selectItem in selectExpandClause.SelectedItems)
            {
                // $expand=...
                ExpandedReferenceSelectItem expandReferenceItem = selectItem as ExpandedReferenceSelectItem;
                if (expandReferenceItem != null)
                {
                    BuildExpandItem(expandReferenceItem, currentLevelPropertiesInclude, structuralTypeInfo);
                    continue;
                }

                PathSelectItem pathSelectItem = selectItem as PathSelectItem;
                if (pathSelectItem != null)
                {
                    // $select=abc/.../xyz
                    BuildSelectItem(pathSelectItem, currentLevelPropertiesInclude, structuralTypeInfo);
                    continue;
                }

                WildcardSelectItem wildCardSelectItem = selectItem as WildcardSelectItem;
                if (wildCardSelectItem != null)
                {
                    // $select=*
                    MergeAllStructuralProperties(structuralTypeInfo.AllStructuralProperties, currentLevelPropertiesInclude);
                    MergeSelectedNavigationProperties(structuralTypeInfo.AllNavigationProperties);
                    SelectAllDynamicProperties = true;
                    continue;
                }

                NamespaceQualifiedWildcardSelectItem wildCardActionSelection = selectItem as NamespaceQualifiedWildcardSelectItem;
                if (wildCardActionSelection != null)
                {
                    // $select=NS.*
                    AddNamespaceWildcardOperation(wildCardActionSelection, structuralTypeInfo.AllActions, structuralTypeInfo.AllFunctions);
                    continue;
                }

                throw new ODataException(Error.Format(SRResources.SelectionTypeNotSupported, selectItem.GetType().Name));
            }

            if (selectExpandClause.AllSelected)
            {
                MergeAllStructuralProperties(structuralTypeInfo.AllStructuralProperties, currentLevelPropertiesInclude);
                MergeSelectedNavigationProperties(structuralTypeInfo.AllNavigationProperties);
                MergeSelectedAction(structuralTypeInfo.AllActions);
                MergeSelectedFunction(structuralTypeInfo.AllFunctions);
                SelectAllDynamicProperties = true;
            }

            // to make sure the structural properties are in the same order defined in the type.
            if (structuralTypeInfo.AllStructuralProperties != null)
            {
                foreach (var structuralProperty in structuralTypeInfo.AllStructuralProperties)
                {
                    SelectExpandIncludedProperty includeProperty;
                    if (!currentLevelPropertiesInclude.TryGetValue(structuralProperty, out includeProperty))
                    {
                        continue;
                    }

                    PathSelectItem pathSelectItem = includeProperty == null ? null : includeProperty.ToPathSelectItem();
                    AddStructuralProperty(structuralProperty, pathSelectItem);
                }
            }
        }
Пример #9
0
 /// <summary>
 /// Writes Selection Item of type WildcardSelectItem node to string
 /// </summary>
 /// <param name="node">Node to write to string</param>
 /// <returns>String representation of node.</returns>
 private static string ToString(WildcardSelectItem node)
 {
     return(String.Format("(Wildcard)"));
 }
Пример #10
0
 public void TwoInstanceAreNotReferenceEquals()
 {
     var item1 = new WildcardSelectItem();
     var item2 = new WildcardSelectItem();
     item1.Should().NotBeSameAs(item2);
 }
Пример #11
0
        private void BuildSelections(SelectExpandClause selectExpandClause, HashSet <IEdmStructuralProperty> allStructuralProperties, HashSet <IEdmNavigationProperty> allNavigationProperties, HashSet <IEdmFunctionImport> allActions)
        {
            foreach (SelectItem selectItem in selectExpandClause.SelectedItems)
            {
                if (selectItem is ExpandedNavigationSelectItem)
                {
                    continue;
                }

                PathSelectItem pathSelectItem = selectItem as PathSelectItem;

                if (pathSelectItem != null)
                {
                    ValidatePathIsSupported(pathSelectItem.SelectedPath);
                    ODataPathSegment segment = pathSelectItem.SelectedPath.LastSegment;

                    NavigationPropertySegment navigationPropertySegment = segment as NavigationPropertySegment;
                    if (navigationPropertySegment != null)
                    {
                        IEdmNavigationProperty navigationProperty = navigationPropertySegment.NavigationProperty;
                        if (allNavigationProperties.Contains(navigationProperty))
                        {
                            SelectedNavigationProperties.Add(navigationProperty);
                        }
                        continue;
                    }

                    PropertySegment structuralPropertySegment = segment as PropertySegment;
                    if (structuralPropertySegment != null)
                    {
                        IEdmStructuralProperty structuralProperty = structuralPropertySegment.Property;
                        if (allStructuralProperties.Contains(structuralProperty))
                        {
                            SelectedStructuralProperties.Add(structuralProperty);
                        }
                        continue;
                    }

                    OperationSegment operationSegment = segment as OperationSegment;
                    if (operationSegment != null)
                    {
                        foreach (IEdmFunctionImport action in operationSegment.Operations)
                        {
                            if (allActions.Contains(action))
                            {
                                SelectedActions.Add(action);
                            }
                        }
                        continue;
                    }

                    throw new ODataException(Error.Format(SRResources.SelectionTypeNotSupported, segment.GetType().Name));
                }

                WildcardSelectItem wildCardSelectItem = selectItem as WildcardSelectItem;
                if (wildCardSelectItem != null)
                {
                    SelectedStructuralProperties = allStructuralProperties;
                    SelectedNavigationProperties = allNavigationProperties;
                    continue;
                }

                ContainerQualifiedWildcardSelectItem wildCardActionSelection = selectItem as ContainerQualifiedWildcardSelectItem;
                if (wildCardActionSelection != null)
                {
                    IEnumerable <IEdmFunctionImport> actionsInThisContainer = allActions.Where(a => a.Container == wildCardActionSelection.Container);
                    foreach (IEdmFunctionImport action in actionsInThisContainer)
                    {
                        SelectedActions.Add(action);
                    }
                    continue;
                }

                throw new ODataException(Error.Format(SRResources.SelectionTypeNotSupported, selectItem.GetType().Name));
            }
        }
Пример #12
0
 /// <summary>
 /// Translate a WildcardSelectItem
 /// </summary>
 /// <param name="item">the item to Translate</param>
 /// <returns>Defined by the implementer</returns>
 public virtual T Translate(WildcardSelectItem item)
 {
     throw new NotImplementedException();
 }
Пример #13
0
 /// <summary>
 /// Handle a WildcardSelectItem
 /// </summary>
 /// <param name="item">the item to Handle</param>
 public override void Handle(WildcardSelectItem item)
 {
     this.ProjectedEntry.Properties = this.OriginalEntry.Properties;
 }
Пример #14
0
 /// <summary>
 /// Handle a WildcardSelectItem
 /// </summary>
 /// <param name="item">the item to Handle</param>
 public virtual void Handle(WildcardSelectItem item)
 {
     throw new NotImplementedException();
 }
Пример #15
0
 /// <summary>
 /// Handle a WildcardSelectItem
 /// </summary>
 /// <param name="item">the item to Handle</param>
 public override void Handle(WildcardSelectItem item)
 {
     this.ProjectedEntryWrapper.Resource.Properties        = this.OriginalEntryWrapper.Resource.Properties;
     this.ProjectedEntryWrapper.NestedResourceInfoWrappers = this.OriginalEntryWrapper.NestedResourceInfoWrappers;
 }
 /// <summary>
 /// Handle a WildcardSelectItem
 /// </summary>
 /// <param name="item">the item to Handle</param>
 public override void Handle(WildcardSelectItem item)
 {
     this.ProjectedEntry.Properties = this.OriginalEntry.Properties;
 }
Пример #17
0
 /// <summary>
 /// Writes Selection Item of type WildcardSelectItem node to string
 /// </summary>
 /// <param name="node">Node to write to string</param>
 /// <returns>String representation of node.</returns>
 private static string ToString(WildcardSelectItem node)
 {
     return String.Format("(Wildcard)");
 }