/// <summary> /// Constructs a BindInfo with the given <paramref name="bindMethod"/>. /// </summary> /// <param name="bindingStateQueryOptions">The query options to be passed for the binding state. Null by default.</param> /// <param name="bindMethodDelegate">The bind method algorithm. By default, uses MetadataBinder method /// if this parameter isn't populated.</param> public BindInfo(List <CustomQueryOptionToken> bindingStateQueryOptions = null, MetadataBinder.QueryTokenVisitor bindMethod = null) { ResourceRangeVariable implicitRangeVariable = new ResourceRangeVariable( ExpressionConstants.It, HardCodedTestModel.GetPersonTypeReference(), HardCodedTestModel.GetPeopleSet()); this.bindingState = new BindingState(configuration) { ImplicitRangeVariable = implicitRangeVariable }; this.bindingState.RangeVariables.Push( new BindingState(configuration) { ImplicitRangeVariable = implicitRangeVariable }.ImplicitRangeVariable); if (bindingStateQueryOptions != null) { this.bindingState.QueryOptions = bindingStateQueryOptions; } this.binder = new MetadataBinder(bindingState); this.bindMethod = bindMethod ?? binder.Bind; }
protected Binding(string providerKey, string membersKey, bool isSingleton, object requiredBy) { this.providerKey = providerKey; this.membersKey = membersKey; this.state = isSingleton ? BindingState.IsSingleton : 0; this.requiredBy = requiredBy; }
/// <summary> /// Constructor for binderbase. /// </summary> /// <param name="bindMethod">Method to use for binding the parent token, if needed.</param> /// <param name="state">State of the metadata binding.</param> protected BinderBase(MetadataBinder.QueryTokenVisitor bindMethod, BindingState state) { ExceptionUtils.CheckArgumentNotNull(bindMethod, "bindMethod"); ExceptionUtils.CheckArgumentNotNull(state, "state"); this.bindMethod = bindMethod; this.state = state; }
public void BindApplyWitMultipleTokensShouldReturnApplyClause() { var tokens = _parser.ParseApply( "groupby((ID, SSN, LifeTime))/aggregate(LifeTime with sum as TotalLife)/groupby((TotalLife))/aggregate(TotalLife with sum as TotalTotalLife)"); var state = new BindingState(_configuration); var metadataBiner = new MetadataBinder(_bindingState); var binder = new ApplyBinder(metadataBiner.Bind, _bindingState); var actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(4); var transformations = actual.Transformations.ToList(); var firstGroupBy = transformations[0] as GroupByTransformationNode; firstGroupBy.Should().NotBeNull(); var firstAggregate = transformations[1] as AggregateTransformationNode; firstAggregate.Should().NotBeNull(); var scecondGroupBy = transformations[2] as GroupByTransformationNode; scecondGroupBy.Should().NotBeNull(); var scecondAggregate = transformations[3] as AggregateTransformationNode; scecondAggregate.Should().NotBeNull(); }
public void BindApplyWithExpandReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply( "expand(MyPaintings, filter(FrameColor eq 'Red'))/groupby((LifeTime),aggregate(MyPaintings($count as Count)))"); BindingState state = new BindingState(_configuration); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState, V4configuration, new ODataPathInfo(HardCodedTestModel.GetPersonType(), HardCodedTestModel.GetPeopleSet())); ApplyClause actual = binder.BindApply(tokens); Assert.NotNull(actual); Assert.Equal(2, actual.Transformations.Count()); ExpandTransformationNode expand = Assert.IsType <ExpandTransformationNode>(actual.Transformations.First()); Assert.NotNull(expand.ExpandClause); ExpandedNavigationSelectItem expandItem = Assert.IsType <ExpandedNavigationSelectItem>(Assert.Single(expand.ExpandClause.SelectedItems)); Assert.Equal("Paintings", expandItem.NavigationSource.Name); Assert.NotNull(expandItem.FilterOption); GroupByTransformationNode groupBy = Assert.IsType <GroupByTransformationNode>(actual.Transformations.Last()); Assert.Single(groupBy.GroupingProperties); AggregateTransformationNode aggregate = Assert.IsType <AggregateTransformationNode>(groupBy.ChildTransformations); Assert.IsType <EntitySetAggregateExpression>(Assert.Single(aggregate.AggregateExpressions)); }
public void BindApplyWithNestedExpandReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply( "expand(MyPaintings, filter(FrameColor eq 'Red'), expand(Owner, filter(Name eq 'Me')))"); BindingState state = new BindingState(_configuration); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState, V4configuration, new ODataPathInfo(HardCodedTestModel.GetPersonType(), HardCodedTestModel.GetPeopleSet())); ApplyClause actual = binder.BindApply(tokens); Assert.NotNull(actual); ExpandTransformationNode expand = Assert.IsType <ExpandTransformationNode>(Assert.Single(actual.Transformations)); Assert.NotNull(expand.ExpandClause); ExpandedNavigationSelectItem expandItem = Assert.IsType <ExpandedNavigationSelectItem>(Assert.Single(expand.ExpandClause.SelectedItems)); Assert.Equal("Paintings", expandItem.NavigationSource.Name); Assert.NotNull(expandItem.SelectAndExpand); Assert.NotNull(expandItem.FilterOption); ExpandedNavigationSelectItem expandItem1 = Assert.IsType <ExpandedNavigationSelectItem>(Assert.Single(expandItem.SelectAndExpand.SelectedItems)); Assert.NotNull(expandItem1.FilterOption); }
public ApplyBinder(MetadataBinder.QueryTokenVisitor bindMethod, BindingState state) { this.bindMethod = bindMethod; this.state = state; this.filterBinder = new FilterBinder(bindMethod, state); this.computeBinder = new ComputeBinder(bindMethod); }
public void BindApplyWitMultipleTokensShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply( "groupby((ID, SSN, LifeTime))/aggregate(LifeTime with sum as TotalLife)/groupby((TotalLife))/aggregate(TotalLife with sum as TotalTotalLife)"); BindingState state = new BindingState(_configuration); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState); ApplyClause actual = binder.BindApply(tokens); Assert.NotNull(actual); Assert.Equal(4, actual.Transformations.Count()); List <TransformationNode> transformations = actual.Transformations.ToList(); Assert.NotNull(transformations[0]); Assert.IsType <GroupByTransformationNode>(transformations[0]); Assert.NotNull(transformations[1]); Assert.IsType <AggregateTransformationNode>(transformations[1]); Assert.NotNull(transformations[2]); Assert.IsType <GroupByTransformationNode>(transformations[2]); Assert.NotNull(transformations[3]); Assert.IsType <AggregateTransformationNode>(transformations[3]); }
public void BindApplyWithEntitySetAggregationReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply( "groupby((LifeTime),aggregate(MyPaintings($count as Count)))"); BindingState state = new BindingState(_configuration); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState); ApplyClause actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(1); GroupByTransformationNode groupBy = actual.Transformations.First() as GroupByTransformationNode; groupBy.Should().NotBeNull(); groupBy.GroupingProperties.Should().HaveCount(1); AggregateTransformationNode aggregate = groupBy.ChildTransformations as AggregateTransformationNode; aggregate.Should().NotBeNull(); aggregate.AggregateExpressions.Should().HaveCount(1); EntitySetAggregateExpression entitySetAggregate = aggregate.AggregateExpressions.First() as EntitySetAggregateExpression; entitySetAggregate.Should().NotBeNull(); }
public void BindApplyWithNestedExpandReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply( "expand(MyPaintings, filter(FrameColor eq 'Red'), expand(Owner, filter(Name eq 'Me')))"); BindingState state = new BindingState(_configuration); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState, V4configuration, new ODataPathInfo(HardCodedTestModel.GetPersonType(), HardCodedTestModel.GetPeopleSet())); ApplyClause actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(1); ExpandTransformationNode expand = actual.Transformations.First() as ExpandTransformationNode; expand.Should().NotBeNull(); expand.ExpandClause.Should().NotBeNull(); expand.ExpandClause.SelectedItems.Should().HaveCount(1); ExpandedNavigationSelectItem expandItem = expand.ExpandClause.SelectedItems.First() as ExpandedNavigationSelectItem; expandItem.Should().NotBeNull(); expandItem.NavigationSource.Name.ShouldBeEquivalentTo("Paintings"); expandItem.SelectAndExpand.Should().NotBeNull(); expandItem.SelectAndExpand.SelectedItems.Should().HaveCount(1); expandItem.FilterOption.Should().NotBeNull(); ExpandedNavigationSelectItem expandItem1 = expandItem.SelectAndExpand.SelectedItems.First() as ExpandedNavigationSelectItem; expandItem1.FilterOption.Should().NotBeNull(); }
internal static void ThrowOnUnbound(BindingState bindingState) { if (BindingState.Unbound == bindingState) { throw OperationForbiddenOnUnboundObjects; } }
/// <summary> /// Parses an <paramref name="orderBy "/> clause on the given <paramref name="elementType"/>, binding /// the text into semantic nodes using the provided model. /// </summary> /// <param name="orderBy">String representation of the orderby expression.</param> /// <param name="configuration">The configuration used for binding.</param> /// <param name="elementType">Type that the orderby clause refers to.</param> /// <param name="navigationSource">NavigationSource that the elements are from.</param> /// <returns>An <see cref="OrderByClause"/> representing the metadata bound orderby expression.</returns> private OrderByClause ParseOrderByImplementation(string orderBy, ODataUriParserConfiguration configuration, IEdmType elementType, IEdmNavigationSource navigationSource) { ExceptionUtils.CheckArgumentNotNull(configuration, "configuration"); ExceptionUtils.CheckArgumentNotNull(configuration.Model, "model"); ExceptionUtils.CheckArgumentNotNull(elementType, "elementType"); ExceptionUtils.CheckArgumentNotNull(orderBy, "orderBy"); // Get the syntactic representation of the orderby expression UriQueryExpressionParser expressionParser = new UriQueryExpressionParser(configuration.Settings.OrderByLimit, configuration.EnableCaseInsensitiveUriFunctionIdentifier); var orderByQueryTokens = expressionParser.ParseOrderBy(orderBy); // Bind it to metadata BindingState state = new BindingState(configuration); state.ImplicitRangeVariable = NodeFactory.CreateImplicitRangeVariable(elementType.ToTypeReference(), navigationSource); state.RangeVariables.Push(state.ImplicitRangeVariable); if (applyClause != null) { state.AggregatedPropertyNames = applyClause.GetLastAggregatedPropertyNames(); } MetadataBinder binder = new MetadataBinder(state); OrderByBinder orderByBinder = new OrderByBinder(binder.Bind); OrderByClause orderByClause = orderByBinder.BindOrderBy(state, orderByQueryTokens); return(orderByClause); }
/// <summary> /// Parses a <paramref name="filter"/> clause on the given <paramref name="elementType"/>, binding /// the text into semantic nodes using the provided model. /// </summary> /// <param name="filter">String representation of the filter expression.</param> /// <param name="configuration">The configuration used for binding.</param> /// <param name="elementType">Type that the filter clause refers to.</param> /// <param name="navigationSource">Navigation source that the elements being filtered are from.</param> /// <returns>A <see cref="FilterClause"/> representing the metadata bound filter expression.</returns> private FilterClause ParseFilterImplementation(string filter, ODataUriParserConfiguration configuration, IEdmType elementType, IEdmNavigationSource navigationSource) { ExceptionUtils.CheckArgumentNotNull(configuration, "configuration"); ExceptionUtils.CheckArgumentNotNull(elementType, "elementType"); ExceptionUtils.CheckArgumentNotNull(filter, "filter"); // Get the syntactic representation of the filter expression UriQueryExpressionParser expressionParser = new UriQueryExpressionParser(configuration.Settings.FilterLimit, configuration.EnableCaseInsensitiveUriFunctionIdentifier); QueryToken filterToken = expressionParser.ParseFilter(filter); // Bind it to metadata BindingState state = new BindingState(configuration); state.ImplicitRangeVariable = NodeFactory.CreateImplicitRangeVariable(elementType.ToTypeReference(), navigationSource); state.RangeVariables.Push(state.ImplicitRangeVariable); if (applyClause != null) { state.AggregatedPropertyNames = applyClause.GetLastAggregatedPropertyNames(); } MetadataBinder binder = new MetadataBinder(state); FilterBinder filterBinder = new FilterBinder(binder.Bind, state); FilterClause boundNode = filterBinder.BindFilter(filterToken); return(boundNode); }
public void CreateParentShouldThrowIfBindingStateWithoutImplicitParameter() { var state = new BindingState(this.configuration); Action createparent = () => EndPathBinder.CreateParentFromImplicitRangeVariable(state); createparent.ShouldThrow <ODataException>().WithMessage(Strings.MetadataBinder_PropertyAccessWithoutParentParameter); }
public ApplyBinder(MetadataBinder.QueryTokenVisitor bindMethod, BindingState state, ODataUriParserConfiguration configuration, ODataPathInfo odataPathInfo) { this.bindMethod = bindMethod; this.state = state; this.filterBinder = new FilterBinder(bindMethod, state); this.configuration = configuration; this.odataPathInfo = odataPathInfo; }
/// <summary> /// pressing the OK button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public Boolean btnOK_Click() { if (comboTypes.Text != "" && comboTypes.SelectedIndex != -1) { BindingSemantics bindingSemantics = BindingSemantics.MANDATORY; BindingOperator bindingOperator = BindingOperator.CHECK_ONLY; BindingState bindingState = BindingState.UNBOUND; if (radioButtonMandatory.Checked) { bindingSemantics = BindingSemantics.MANDATORY; } else if (radioButtonNegative.Checked) { bindingSemantics = BindingSemantics.NEGATIVE; } if (radioButtonCreate.Checked) { bindingOperator = BindingOperator.CREATE; } else if (radioButtonCheckonly.Checked) { bindingOperator = BindingOperator.CHECK_ONLY; } else if (radioButtonDestroy.Checked) { bindingOperator = BindingOperator.DESTROY; } if (!checkBoxBound.Checked) { bindingState = BindingState.UNBOUND; } if (checkBoxBound.Checked) { bindingState = BindingState.BOUND; } objectVariable.Name = comboNames.Text; objectVariable.Classifier = comboTypes.Classifiers[comboTypes.SelectedIndex]; objectVariable.BindingOperator = bindingOperator; objectVariable.BindingSemantics = bindingSemantics; objectVariable.BindingState = bindingState; if (complexNACControl.getNacIndexValue() != "" && radioButtonNegative.Checked) { objectVariable.NacIndex = int.Parse(complexNACControl.getNacIndexValue()); } else { objectVariable.NacIndex = -1; } return(true); } return(false); }
public void OpenPropertyIsNotBoundToAFunction() { var token = new EndPathToken("SomeOpenProperty", null); BindingState state = GetBindingStateForTest(HardCodedTestModel.GetPaintingTypeReference(), HardCodedTestModel.GetPaintingsSet()); EndPathBinder binder = new EndPathBinder(BindMethod, state); var result = binder.BindEndPath(token); result.ShouldBeSingleValueOpenPropertyAccessQueryNode("SomeOpenProperty"); }
public void ComplexCollectionPropertyShouldCreateMatchingNode() { var state = new BindingState(Configuration); var binder = new InnerPathTokenBinder(FakeBindMethods.BindMethodReturningASinglePerson, state); var token = new InnerPathToken("PreviousAddresses", new DummyToken(), null /*namedValues*/); var result = binder.BindInnerPathSegment(token); result.ShouldBeCollectionComplexNode(HardCodedTestModel.GetPersonPreviousAddressesProp()); }
public void PrimitiveCollectionPropertyShouldCreateMatchingNode() { var state = new BindingState(Configuration); var binder = new InnerPathTokenBinder(FakeBindMethods.BindMethodReturningASingleDog, state); var token = new InnerPathToken("Nicknames", new DummyToken(), null /*namedValues*/); var result = binder.BindInnerPathSegment(token); result.ShouldBeCollectionPropertyAccessQueryNode(HardCodedTestModel.GetDogNicknamesProperty()); }
public void DeclaredPropertyOnOpenTypeShouldCreateMatchingNode() { var state = new BindingState(Configuration); var binder = new InnerPathTokenBinder(FakeBindMethods.BindMethodReturningASinglePainting, state); var token = new InnerPathToken("Colors", new DummyToken(), null /*namedValues*/); var result = binder.BindInnerPathSegment(token); result.ShouldBeCollectionPropertyAccessQueryNode(HardCodedTestModel.GetPaintingColorsProperty()); }
public void CollectionOfDateTimeOffsetShouldCreateMatchingNode() { var state = new BindingState(Configuration); var binder = new InnerPathTokenBinder(FakeBindMethods.BindMethodReturningASingleLion, state); var token = new InnerPathToken("AttackDates", new DummyToken(), null /*namedValues*/); var result = binder.BindInnerPathSegment(token); result.ShouldBeCollectionPropertyAccessQueryNode(HardCodedTestModel.GetLionAttackDatesProp()); }
public void OpenPropertyShouldCreateMatchingNode() { const string OpenPropertyName = "Emotions"; var state = new BindingState(Configuration); var binder = new InnerPathTokenBinder(FakeBindMethods.BindMethodReturningASinglePainting, state); var token = new InnerPathToken(OpenPropertyName, new DummyToken(), null /*namedValues*/); var result = binder.BindInnerPathSegment(token); result.ShouldBeSingleValueOpenPropertyAccessQueryNode(OpenPropertyName); }
public void CollectionNavigationPropertyShouldCreateMatchingNode() { var state = new BindingState(Configuration); var binder = new InnerPathTokenBinder(FakeBindMethods.BindMethodReturningASingleDog, state); var token = new InnerPathToken("MyPeople", new DummyToken(), null /*namedValues*/); var result = binder.BindInnerPathSegment(token); Assert.Same(HardCodedTestModel.GetDogsSet().FindNavigationTarget(HardCodedTestModel.GetDogMyPeopleNavProp()), result.ShouldBeCollectionNavigationNode(HardCodedTestModel.GetDogMyPeopleNavProp()).NavigationSource); }
public void GetNavigationNodeCreatesCollectionNavigationNodeForManyMultiplicityProperty() { IEdmNavigationProperty property = HardCodedTestModel.GetDogMyPeopleNavProp(); SingleEntityNode parent = new SingleEntityCastNode(null, HardCodedTestModel.GetDogType()); BindingState state = new BindingState(configuration); KeyBinder keyBinder = new KeyBinder(FakeBindMethods.BindMethodReturningASingleDog); var result = InnerPathTokenBinder.GetNavigationNode(property, parent, null, state, keyBinder); result.ShouldBeCollectionNavigationNode(property); }
public static BindingState computeBindingState(String value) { try { BindingState bState = (BindingState)Enum.Parse(typeof(BindingState), value.ToUpper()); return(bState); } catch { return(BindingState.UNBOUND); } }
public void GetNavigationNodeCreatesSingleNavigationNodeForSingleMultiplicityProperty() { IEdmNavigationProperty property = HardCodedTestModel.GetPersonMyDogNavProp(); IEdmNavigationSource navigationSource; SingleResourceNode parent = new SingleResourceCastNode(null, HardCodedTestModel.GetDogType()); BindingState state = new BindingState(Configuration); KeyBinder keyBinder = new KeyBinder(FakeBindMethods.BindMethodReturningASingleDog); var result = InnerPathTokenBinder.GetNavigationNode(property, parent, null, state, keyBinder, out navigationSource); result.ShouldBeSingleNavigationNode(property); }
public void CreateLambdaNodeForAnyTokenShouldCreateAnyNode() { BindingState bindingState = new BindingState(configuration); CollectionResourceNode parent = new EntitySetNode(HardCodedTestModel.GetPeopleSet()); SingleValueNode expression = new ConstantNode(true); RangeVariable rangeVariable = new ResourceRangeVariable("bob", HardCodedTestModel.GetPersonTypeReference(), parent); var resultNode = NodeFactory.CreateLambdaNode(bindingState, parent, expression, rangeVariable, QueryTokenKind.Any); var node = resultNode.ShouldBeAnyQueryNode(); node.Body.Should().BeSameAs(expression); node.Source.Should().BeSameAs(parent); }
public void InnerPathTokenBinderShouldFailIfPropertySourceIsNotASingleValue() { var state = new BindingState(Configuration); state.ImplicitRangeVariable = NodeFactory.CreateImplicitRangeVariable(HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet()); var metadataBinder = new MetadataBinder(state); var binder = new InnerPathTokenBinder(metadataBinder.Bind, state); var token = new InnerPathToken("MyDog", new InnerPathToken("MyPeople", null, null), null); Action bind = () => binder.BindInnerPathSegment(token); bind.Throws <ODataException>(Strings.MetadataBinder_PropertyAccessSourceNotSingleValue("MyDog")); }
public void KeyLookupOnNavPropIntegrationTest() { var state = new BindingState(Configuration); state.ImplicitRangeVariable = NodeFactory.CreateImplicitRangeVariable(HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet()); var metadataBinder = new MetadataBinder(state); var binder = new InnerPathTokenBinder(metadataBinder.Bind, state); var token = new InnerPathToken("MyPeople", null, new[] { new NamedValue(null, new LiteralToken(123)) }); var result = binder.BindInnerPathSegment(token); result.ShouldBeKeyLookupQueryNode(); }
private MetadataBinder BuildNewMetadataBinder(IEdmEntitySet targetEntitySet) { BindingState state = new BindingState(this.configuration) { ImplicitRangeVariable = NodeFactory.CreateImplicitRangeVariable( targetEntitySet.ElementType.ToTypeReference(), targetEntitySet) }; state.RangeVariables.Push(state.ImplicitRangeVariable); return(new MetadataBinder(state)); }