public void ParametersCanUseRelativeSourceBindings() { Window.LoadContent( @"<Button xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:magellan='http://xamlforge.com/magellan' xmlns:i='clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity' Name='MyButton' Content='Hello' > <i:Interaction.Triggers> <i:EventTrigger EventName='Click'> <magellan:NavigateControllerAction x:Name='NavBehavior' Controller='MyController' Action='MyAction'> <magellan:NavigateControllerAction.Parameters> <magellan:Parameter ParameterName='win' Value='{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window}}' /> <magellan:Parameter ParameterName='winTitle' Value='{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window}, Path=Title}' /> </magellan:NavigateControllerAction.Parameters> </magellan:NavigateControllerAction> </i:EventTrigger> </i:Interaction.Triggers> </Button>"); ExpectNavigationRequest("MyController", "MyAction", new { win = Window, winTitle = "Hello" }); Window.Title = "Hello"; NavigationProperties.SetNavigator(Window, Navigator.Object); Window.Find <Button>("MyButton").ExecuteClick(); Window.ProcessEvents(); }
/// <summary> /// Adds a navigation property to the entity type. /// </summary> /// <param name="navigationPropertyName">Name of the navigation property.</param> /// <param name="modelAssociationSet">Association set that this navigation property is based on.</param> /// <param name="fromRoleName">From-role. Normally the same as the from-role for the associationset, but can be reversed for recursive associations.</param> /// <param name="fromRoleName">To-role. Normally the same as the To-role for the associationset, but can be reversed for recursive associations.</param> /// <returns>A NavigationProperty object.</returns> public NavigationProperty AddNavigationMember(string navigationPropertyName, ModelAssociationSet modelAssociationSet, string fromRoleName, string toRoleName) { try { if (!NavigationProperties.Any(np => np.Name.Equals(navigationPropertyName)) && !MemberProperties.Any(mp => mp.Name.Equals(navigationPropertyName)) && navigationPropertyName != this.Name) { NavigationProperty navigationProperty = new NavigationProperty(ParentFile, this, navigationPropertyName, modelAssociationSet, _entityTypeElement, fromRoleName, toRoleName); _navigationProperties.Add(navigationProperty.Name, navigationProperty); navigationProperty.NameChanged += new EventHandler <NameChangeArgs>(navprop_NameChanged); navigationProperty.Removed += new EventHandler(navprop_Removed); return(navigationProperty); } else { throw new ArgumentException("A property named " + navigationPropertyName + " already exist in the type " + this.Name); } } catch (Exception ex) { try { ExceptionTools.AddExceptionData(ex, this); } catch { } throw; } }
/// <summary> /// If the target implements <see cref="INavigationAware"/>, assigns the Navigator to it, and sets /// the NavigationProperties.Navigator attached property. /// </summary> /// <param name="target">The target.</param> /// <param name="request">The request.</param> protected virtual void AssignNavigator(object target, ResolvedNavigationRequest request) { if (target == null) { return; } var navigator = request.Navigator; if (navigator == null) { return; } var navigationAware = target as INavigationAware; var dependencyObject = target as DependencyObject; if (navigationAware != null) { TraceSources.MagellanSource.TraceVerbose("The object '{0}' implements the INavigationAware interface, so it is being provided with a navigator.", navigationAware.GetType().Name); navigationAware.Navigator = navigator; } if (dependencyObject != null) { NavigationProperties.SetNavigator(dependencyObject, navigator); NavigationProperties.SetCurrentRequest(dependencyObject, request); } }
public void ParametersCanUseDataContextBindings() { Window.LoadContent( @"<Button xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:magellan='http://xamlforge.com/magellan' xmlns:i='clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity' Name='MyButton' Content='Hello' > <i:Interaction.Triggers> <i:EventTrigger EventName='Click'> <magellan:NavigateControllerAction x:Name='NavBehavior' Controller='MyController' Action='MyAction'> <magellan:NavigateControllerAction.Parameters> <magellan:Parameter ParameterName='param' Value='{Binding}' /> <magellan:Parameter ParameterName='paramA' Value='{Binding Path=A}' /> <magellan:Parameter ParameterName='paramB' Value='{Binding Path=B}' /> </magellan:NavigateControllerAction.Parameters> </magellan:NavigateControllerAction> </i:EventTrigger> </i:Interaction.Triggers> </Button>"); var dataContext = new { A = 3, B = 8 }; ExpectNavigationRequest("MyController", "MyAction", new { param = dataContext, paramA = dataContext.A, paramB = dataContext.B }); Window.DataContext = dataContext; NavigationProperties.SetNavigator(Window, Navigator.Object); Window.Find <Button>("MyButton").ExecuteClick(); Window.ProcessEvents(); }
/// <summary> /// Adds a scalar member to this entity type. /// </summary> /// <param name="name">Name of the new member property.</param> /// <param name="type">Type of the new member property.</param> /// <param name="nullable">Nullable; true or false.</param> /// <param name="ordinal">Ordinal position within the entity type.</param> /// <returns>A ModelMemberProperty object.</returns> public ModelMemberProperty AddMember(string name, Type type, bool nullable, int ordinal) { try { if (!MemberProperties.Where(mp => mp.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)).Any() && !NavigationProperties.Any(np => np.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)) && name != this.Name) { ModelMemberProperty mp = new ModelMemberProperty(base.ParentFile, this, name, ordinal, _entityTypeElement); mp.Type = type; mp.Nullable = nullable; _memberProperties.Add(name, mp); mp.NameChanged += new EventHandler <NameChangeArgs>(prop_NameChanged); mp.Removed += new EventHandler(prop_Removed); return(mp); } else { throw new ArgumentException("A property with the name " + name + " already exist in the type " + this.Name); } } catch (Exception ex) { try { ExceptionTools.AddExceptionData(ex, this); } catch { } throw; } }
public void ParametersCanUseElementBindings() { Window.LoadContent( @"<Button xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:i='clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity' Name='MyButton' Content='Bye!' > <i:Interaction.Triggers> <i:EventTrigger EventName='Click'> <NavigateControllerAction x:Name='NavBehavior' Controller='MyController' Action='MyAction'> <NavigateControllerAction.Parameters> <Parameter ParameterName='btn' Value='{Binding ElementName=MyButton}' /> <Parameter ParameterName='btnContent' Value='{Binding ElementName=MyButton, Path=Content}' /> <Parameter ParameterName='x' Value='Wazoo' /> </NavigateControllerAction.Parameters> </NavigateControllerAction> </i:EventTrigger> </i:Interaction.Triggers> </Button>"); ExpectNavigationRequest("MyController", "MyAction", new { btn = Window.Find <Button>("MyButton"), btnContent = "Bye!", x = "Wazoo" }); NavigationProperties.SetNavigator(Window, Navigator.Object); Window.Find <Button>("MyButton").ExecuteClick(); Window.ProcessEvents(); }
public override void Handle(ExpandedNavigationSelectItem item) { var navigationSegment = (NavigationPropertySegment)item.PathToNavigationProperty.LastSegment; if (navigationSegment.NavigationProperty.DeclaringType == _edmStructuredType) { NavigationProperties.Add(navigationSegment.NavigationProperty); } else { Handle(item.SelectAndExpand); } }
public override void Handle(ExpandedNavigationSelectItem item) { var navigationSegment = (NavigationPropertySegment)item.PathToNavigationProperty.LastSegment; if (IsPropertyDefineInType(navigationSegment.NavigationProperty)) { NavigationProperties.Add(navigationSegment.NavigationProperty); } else { Handle(item.SelectAndExpand); } }
public void CanCreateNavigatorForASourceElementWhenNavigatorAlreadySet() { var oldNavigator = new Mock <INavigator>(); var button = new Button(); NavigationProperties.SetNavigator(button, oldNavigator.Object); var resolver = new Mock <IRouteResolver>(); var factory = new NavigatorFactory(resolver.Object); var navigator = factory.GetOwningNavigator(button); Assert.AreEqual(navigator, oldNavigator.Object); }
protected virtual Object CreateEntity(ODataResourceBase resource, IReadOnlyList <NavigationInfo> navigationProperties) { Db.OeEntitySetAdapter entitySetAdapter = TestHelper.FindEntitySetAdapterByTypeName(EntitySetAdapters, resource.TypeName); Object entity = CreateEntity(entitySetAdapter.EntityType, resource); Dictionary <PropertyInfo, NavigationInfo> propertyInfos = null; foreach (NavigationInfo navigationInfo in navigationProperties) { PropertyInfo clrProperty = entitySetAdapter.EntityType.GetProperty(navigationInfo.Name); Object value = navigationInfo.Value; if ((navigationInfo.Count == null && navigationInfo.NextPageLink == null)) { if (clrProperty.GetSetMethod() != null) { clrProperty.SetValue(entity, value); } } else { if (value == null && navigationInfo.NextPageLink != null) { if (navigationInfo.IsCollection) { value = CreateCollection(clrProperty.PropertyType); } else { value = Activator.CreateInstance(clrProperty.PropertyType); } } clrProperty.SetValue(entity, value); if (value != null) { NavigationProperties.Add(value, navigationInfo); } if (propertyInfos == null) { propertyInfos = new Dictionary <PropertyInfo, NavigationInfo>(navigationProperties.Count); NavigationInfoEntities.Add(entity, propertyInfos); } propertyInfos.Add(clrProperty, navigationInfo); } } return(entity); }
private void Navigate() { var parameters = Parameters.ToDictionary(x => x.ParameterName, x => x.Value); var navigator = NavigationProperties.GetNavigator(AssociatedObject); if (navigator == null) { throw new ImpossibleNavigationRequestException("The Navigator for this UI element is not avaialable. Please ensure the current view has been loaded into a frame, or that the NavigationProperties.Navigator attached property has been set."); } var request = new RouteValueDictionary(parameters); PrepareRequest(request); navigator.ProcessRequest(new NavigationRequest(request)); }
public override object ToMinified() { var rs = NavigationProperties.Select(np => np.ToMinified()).ToList(); var xs = ComplexProperties.Select(cp => cp.ToMinified()).ToList(); return(new { n = Name, rn = ResourceName, l = GetDisplayName(), s = ShortName, q = QueryName, t = QueryType, b = BaseTypeName, c = IsComplexType, k = Keys, d = DataProperties.Select(dp => dp.ToMinified()).ToList(), r = rs.Any() ? rs : null, x = xs.Any() ? xs : null }); }
protected Object CreateEntity(ODataResource resource, IReadOnlyList <NavigationProperty> navigationProperties) { Db.OeEntitySetAdapter entitySetAdapter = EntitySetAdapters.FindByTypeName(resource.TypeName); Object entity = OeEdmClrHelper.CreateEntity(entitySetAdapter.EntityType, resource); Dictionary <PropertyInfo, ODataResourceSetBase> propertyInfos = null; foreach (NavigationProperty navigationProperty in navigationProperties) { PropertyInfo clrProperty = entitySetAdapter.EntityType.GetProperty(navigationProperty.Name); Object value = navigationProperty.Value; if (navigationProperty.ResourceSet == null || (navigationProperty.ResourceSet.Count == null && navigationProperty.ResourceSet.NextPageLink == null)) { if (clrProperty.GetSetMethod() != null) { clrProperty.SetValue(entity, value); } continue; } if (value == null && navigationProperty.ResourceSet.NextPageLink != null) { value = CreateCollection(clrProperty.PropertyType); } clrProperty.SetValue(entity, value); if (value is IEnumerable collection) { NavigationProperties.Add(collection, navigationProperty.ResourceSet); if (propertyInfos == null) { propertyInfos = new Dictionary <PropertyInfo, ODataResourceSetBase>(navigationProperties.Count); NavigationPropertyEntities.Add(entity, propertyInfos); } propertyInfos.Add(clrProperty, navigationProperty.ResourceSet); } } return(entity); }
public override void Handle(PathSelectItem item) { if (item.SelectedPath.LastSegment is NavigationPropertySegment navigationSegment) { if (IsPropertyDefineInType(navigationSegment.NavigationProperty) && !NavigationProperties.Contains(navigationSegment.NavigationProperty)) { NavigationProperties.Add(navigationSegment.NavigationProperty); } } else if (item.SelectedPath.LastSegment is PropertySegment propertySegment) { if (IsPropertyDefineInType(propertySegment.Property)) { StructuralProperties.Add(propertySegment.Property); } } else { throw new InvalidOperationException(item.SelectedPath.LastSegment.GetType().Name + " not supported"); } }
/// <summary> /// Creates an <see cref="INavigator"/> bound to the navigation service that owns a given source /// element. This method can be called multiple times for the same <paramref name="sourceElement"/>. /// </summary> /// <param name="sourceElement">A UI element that lives inside the frame that you want a navigator /// for.</param> /// <returns> /// An instance of the <see cref="INavigator"/> interface which can be used for navigation. /// </returns> public INavigator GetOwningNavigator(UIElement sourceElement) { Guard.ArgumentNotNull(sourceElement, "sourceElement"); var existingNavigator = NavigationProperties.GetNavigator(sourceElement); if (existingNavigator != null) { return(existingNavigator); } Func <INavigationService> lazyFrameGetter = () => { var frame = null as Frame; DependencyObject parent = sourceElement; while (parent != null) { frame = parent as Frame; if (frame != null) { break; } parent = VisualTreeHelper.GetParent(parent); } if (frame == null) { throw new ImpossibleNavigationRequestException("The Navigator for this UI element is not avaialable. Please ensure the current view has been loaded into a frame, or that the NavigationProperties.Navigator attached property has been set."); } var wrapper = new FrameNavigationServiceWrapper(sourceElement.Dispatcher, frame); return(wrapper); }; return(NewNavigator(lazyFrameGetter, null)); }
internal void UpdateNavigationProperties() { NavigationProperties.ForEach(np => UpdateNavigationProperty(np)); }
protected IEnumerable Read(Stream response, Db.OeEntitySetAdapter entitySetMetaAdatpter) { ResourceSet = null; NavigationProperties.Clear(); NavigationInfoEntities.Clear(); IODataResponseMessage responseMessage = new Infrastructure.OeInMemoryMessage(response, null, _serviceProvider); var settings = new ODataMessageReaderSettings() { EnableMessageStreamDisposal = false, Validations = ValidationKinds.None }; using (var messageReader = new ODataMessageReader(responseMessage, settings, EdmModel)) { IEdmEntitySet entitySet = OeEdmClrHelper.GetEntitySet(EdmModel, entitySetMetaAdatpter.EntitySetName); ODataReader reader = messageReader.CreateODataResourceSetReader(entitySet, entitySet.EntityType()); var stack = new Stack <StackItem>(); while (reader.Read()) { switch (reader.State) { case ODataReaderState.ResourceSetStart: if (stack.Count == 0) { ResourceSet = (ODataResourceSetBase)reader.Item; } else { stack.Peek().ResourceSet = (ODataResourceSetBase)reader.Item; } break; case ODataReaderState.ResourceStart: stack.Push(new StackItem((ODataResource)reader.Item)); break; case ODataReaderState.ResourceEnd: StackItem stackItem = stack.Pop(); if (reader.Item != null) { if (stack.Count == 0) { yield return(CreateRootEntity((ODataResource)stackItem.Item, stackItem.NavigationProperties, entitySetMetaAdatpter.EntityType)); } else { stack.Peek().AddEntry(CreateEntity((ODataResource)stackItem.Item, stackItem.NavigationProperties)); } } break; case ODataReaderState.NestedResourceInfoStart: stack.Push(new StackItem((ODataNestedResourceInfo)reader.Item)); break; case ODataReaderState.NestedResourceInfoEnd: StackItem item = stack.Pop(); stack.Peek().AddLink((ODataNestedResourceInfo)item.Item, item.Value, item.ResourceSet); break; } } } }