/// <summary> /// Initializes a new instance of the <see cref="DefaultActionLocator"/> class. /// </summary> /// <param name="serviceLocator">The service locator.</param> /// <param name="methodFactory">The method factory.</param> /// <param name="messageBinder">The message binder.</param> /// <param name="conventionManager">The convention manager.</param> public DefaultActionLocator(IServiceLocator serviceLocator, IMethodFactory methodFactory, IMessageBinder messageBinder, IConventionManager conventionManager) { this.serviceLocator = serviceLocator; this.methodFactory = methodFactory; this.messageBinder = messageBinder; this.conventionManager = conventionManager; }
protected override void given_the_context_of() { conventionManager = Mock <IConventionManager>(); binder = new DefaultMessageBinder(conventionManager); handlingNode = Stub <IInteractionNode>(); sourceNode = Stub <IInteractionNode>(); }
private static IEnumerable<ElementDescription> DefaultSelectElementsToInspectImplementation(IConventionManager conventionManager, DependencyObject root) { var queue = new Queue<DependencyObject>(); queue.Enqueue(root); while (queue.Count > 0) { var current = queue.Dequeue(); var currentName = current.GetName(); if (!string.IsNullOrEmpty(currentName)) { var currentType = current.GetType(); var currentConvention = conventionManager.GetElementConvention(currentType); if (currentConvention != null) yield return new ElementDescription { Type = currentType, Name = currentName, Convention = currentConvention }; } foreach (object child in LogicalTreeHelper.GetChildren(current)) { var childDo = child as DependencyObject; if (childDo == null || childDo is UserControl) continue; queue.Enqueue(childDo); } } }
/// <summary> /// Creates the application of the convention. /// </summary> /// <param name="conventionManager">The convention manager.</param> /// <param name="description">The description.</param> /// <param name="element">The element.</param> /// <param name="property">The property.</param> /// <returns>The convention application.</returns> public override IViewApplicable TryCreateApplication(IConventionManager conventionManager, IViewModelDescription description, ElementDescription element, PropertyInfo property) { var expectedPath = DeterminePropertyPath(element.Name); string correctedPath; var boundProperty = GetBoundProperty(property, expectedPath, out correctedPath); if (boundProperty == null) { return(null); } Log.Info("Binding convention matched for {0}.", element.Name); var setMethod = boundProperty.GetSetMethod(); var canWriteToProperty = boundProperty.CanWrite && setMethod != null && setMethod.IsPublic; return(new ApplicableBinding( element, element.Convention.BindableProperty, correctedPath, canWriteToProperty ? BindingMode.TwoWay : BindingMode.OneWay, ShouldValidate(boundProperty), false, conventionManager.GetValueConverter(element.Convention.BindableProperty, boundProperty.PropertyType) )); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultMessageBinder"/> class. /// </summary> public DefaultMessageBinder(IConventionManager conventionManager) { this.conventionManager = conventionManager; valueHandlers = new Dictionary <string, Func <IInteractionNode, object, object> >(); InitializeDefaultValueHandlers(); }
protected override void given_the_context_of() { _conventionManager = Mock<IConventionManager>(); _binder = new DefaultMessageBinder(_conventionManager); _handlingNode = Stub<IInteractionNode>(); _sourceNode = Stub<IInteractionNode>(); }
protected override void given_the_context_of() { _methodFactory = Mock<IMethodFactory>(); _conventionManager = new DefaultConventionManager( _methodFactory ); }
protected override void given_the_context_of() { methodFactory = Mock <IMethodFactory>(); conventionManager = new DefaultConventionManager( methodFactory ); }
/// <summary> /// Gets the applications. /// </summary> /// <param name="conventionManager">The convention manager.</param> /// <param name="viewModelDescription">The view model description.</param> /// <param name="elementDescription">The element description.</param> /// <returns>The applications.</returns> public IEnumerable <IViewApplicable> GetApplications(IConventionManager conventionManager, IViewModelDescription viewModelDescription, ElementDescription elementDescription) { return(from convention in conventions from target in getTargets(viewModelDescription) let application = convention.TryCreateApplication(conventionManager, viewModelDescription, elementDescription, target) where application != null select application); }
protected override void given_the_context_of() { methodFactory = Mock <IMethodFactory>(); messageBinder = Mock <IMessageBinder>(); serviceLocator = Mock <IServiceLocator>(); conventionManager = Mock <IConventionManager>(); locator = new DefaultActionLocator(serviceLocator, methodFactory, messageBinder, conventionManager); }
private static IEnumerable<ElementDescription> DefaultSelectElementsToInspectImplementation(IConventionManager conventionManager, DependencyObject root) { var queue = new Queue<DependencyObject>(); queue.Enqueue(root); while (queue.Count > 0) { var current = queue.Dequeue(); var currentName = current.GetName(); if (!string.IsNullOrEmpty(currentName)) { var currentType = current.GetType(); var currentConvention = conventionManager.GetElementConvention(currentType); if (currentConvention != null) yield return new ElementDescription { Type = currentType, Name = currentName, Convention = currentConvention }; } var childCount = VisualTreeHelper.GetChildrenCount(current); if (childCount > 0) { for(var i = 0; i < childCount; i++) { var childDo = VisualTreeHelper.GetChild(current, i); if(childDo is UserControl) continue; queue.Enqueue(childDo); } } else { var contentControl = current as ContentControl; if (contentControl != null) { if (contentControl.Content != null && contentControl.Content is DependencyObject && !(contentControl.Content is UserControl)) queue.Enqueue(contentControl.Content as DependencyObject); } else { var itemsControl = current as ItemsControl; if(itemsControl != null) { itemsControl.Items.OfType<DependencyObject>() .Where(item => !(item is UserControl)) .Apply(queue.Enqueue); } } } } }
protected override void given_the_context_of() { factory = new DefaultMethodFactory(); conventionManager = Mock<IConventionManager>(); binder = new DefaultMessageBinder(conventionManager); handlingNode = Stub<IInteractionNode>(); sourceNode = Stub<IInteractionNode>(); host = new ControlHost(); sourceNode.Stub(x => x.UIElement).Return(host).Repeat.Any(); }
protected override void given_the_context_of() { factory = new DefaultMethodFactory(); conventionManager = Mock <IConventionManager>(); binder = new DefaultMessageBinder(conventionManager); handlingNode = Stub <IInteractionNode>(); sourceNode = Stub <IInteractionNode>(); host = new ControlHost(); sourceNode.Stub(x => x.UIElement).Return(host).Repeat.Any(); }
/// <summary> /// Initializes a new instance of the <see cref="ActionCreationContext"/> class. /// </summary> /// <param name="serviceLocator">The service locator.</param> /// <param name="methodFactory">The method factory.</param> /// <param name="messageBinder">The message binder.</param> /// <param name="conventionManager">The convention manager</param> /// <param name="targetType">Type of the target.</param> /// <param name="targetFilters">The target filters.</param> /// <param name="method">The method.</param> public ActionCreationContext(IServiceLocator serviceLocator, IMethodFactory methodFactory, IMessageBinder messageBinder, IConventionManager conventionManager, Type targetType, IFilterManager targetFilters, MethodInfo method) { ConventionManager = conventionManager; ServiceLocator = serviceLocator; MethodFactory = methodFactory; MessageBinder = messageBinder; TargetType = targetType; TargetFilters = targetFilters; Method = method; }
/// <summary> /// Initializes a new instance of the <see cref="DefaultParser"/> class. /// </summary> public DefaultParser(IConventionManager conventionManager) { _conventionManager = conventionManager; RegisterTriggerParser("Event", new EventTriggerParser()); RegisterTriggerParser("Gesture", new GestureTriggerParser()); #if !SILVERLIGHT RegisterTriggerParser("AttachedEvent", new AttachedEventTriggerParser()); RegisterTriggerParser("CommandSource", new CommandTriggerParser()); #endif }
/// <summary> /// Initializes a new instance of the <see cref="DefaultParser"/> class. /// </summary> public DefaultParser(IConventionManager conventionManager) { this.conventionManager = conventionManager; RegisterTriggerParser("Event", new EventTriggerParser()); RegisterTriggerParser("Gesture", new GestureTriggerParser()); #if !SILVERLIGHT RegisterTriggerParser("AttachedEvent", new AttachedEventTriggerParser()); RegisterTriggerParser("CommandSource", new CommandTriggerParser()); #endif }
/// <summary> /// Creates the application of the convention. /// </summary> /// <param name="conventionManager">The convention manager.</param> /// <param name="description">The description.</param> /// <param name="element">The element.</param> /// <param name="action">The action.</param> /// <returns></returns> public override IViewApplicable TryCreateApplication(IConventionManager conventionManager, IViewModelDescription description, ElementDescription element, IAction action) { if (string.Compare(element.Name, action.Name, StringComparison.CurrentCultureIgnoreCase) != 0) { return(null); } var message = CreateActionMessage(action); Log.Info("Action convention matched for {0}.", element.Name); return(new ApplicableAction(element.Name, null, message)); }
public static void AddElementConvention <T>(this IConventionManager conventionManager, string defaultEvent, DependencyProperty bindableProperty, Action <T, object> setter, Func <T, object> getter) where T : DependencyObject { conventionManager.AddElementConvention( new DefaultElementConvention <T>( defaultEvent, bindableProperty, setter, getter, null )); }
/// <summary> /// Finds the interaction defaults or fail. /// </summary> /// <param name="conventionManager">The convention manager.</param> /// <param name="element">The element.</param> /// <returns></returns> public static IElementConvention FindElementConventionOrFail(this IConventionManager conventionManager, object element) { var type = element.GetType(); var defaults = conventionManager.GetElementConvention(type); if (defaults == null) { throw new CaliburnException( string.Format("Could not locate an IElementConvention for {0}. Please register one with the IConventionManager.", type.Name) ); } return(defaults); }
static Conventions() { var builder = new ConventionBuilder(); //foreach (var assm in AssemblySource.Instance) builder.ScanThisAssembly() .For <AttachmentConventions>() .For <ViewModelConventions>() .For <ViewConventions>() .For <ServiceConventions>() ; conventions = builder.Build(); }
public void Configure(IEnumerable <Type> views, IEnumerable <Type> viewModels, IEnumerable <Type> attachments, IConventionManager conventionManager) { this.conventionManager = conventionManager; var builder = new ContainerBuilder(); foreach (var type in views.Concat(attachments)) { builder.RegisterType(type); } foreach (var type in viewModels) { builder.RegisterType(type).OnActivating(Activating); } builder.RegisterInstance(PiracRunner.WindowManager).As <IWindowManager>(); builder.RegisterAssemblyModules(Assembly.GetExecutingAssembly()); container = builder.Build(); }
/// <summary> /// Tries to creates the application of the convention. /// </summary> /// <param name="conventionManager">The convention manager.</param> /// <param name="description">The description.</param> /// <param name="element">The element.</param> /// <param name="target">The target.</param> /// <returns> /// The convention application, or null if not applicable /// </returns> public override IViewApplicable TryCreateApplication(IConventionManager conventionManager, IViewModelDescription description, ElementDescription element, PropertyInfo target) { var exptectedPath = DeterminePropertyPath(element.Name); var index = exptectedPath.LastIndexOf("."); if (index == -1) { return(null); } var propertyPath = exptectedPath.Substring(0, index); string correctedPath; var actualTarget = GetBoundProperty(target, propertyPath, out correctedPath); if (actualTarget == null) { return(null); } var actionName = exptectedPath.Substring(index + 1); var subDescription = ViewModelDescriptionFactory.Create(actualTarget.PropertyType); var action = subDescription.Actions.FirstOrDefault(x => string.Compare(x.Name, actionName, StringComparison.CurrentCultureIgnoreCase) == 0); if (action == null) { return(null); } var message = CreateActionMessage(action); Log.Info("Sub action convention matched for {0} on {1}.", element.Name, correctedPath); return(new ApplicableAction( element.Name, correctedPath, message )); }
/// <summary> /// Creates the application of the convention. /// </summary> /// <param name="conventionManager">The convention manager.</param> /// <param name="description">The description.</param> /// <param name="element">The element.</param> /// <param name="property">The property.</param> /// <returns>The convention application.</returns> public override IViewApplicable TryCreateApplication(IConventionManager conventionManager, IViewModelDescription description, ElementDescription element, PropertyInfo property) { var expectedPath = DeterminePropertyPath(element.Name); string correctedPath; var boundProperty = GetBoundProperty(property, expectedPath, out correctedPath); if (boundProperty == null || !ItemsControlType.IsAssignableFrom(element.Type)) { return(null); } string path = null; DependencyProperty bindableProperty = null; BindingMode mode = BindingMode.OneWay; bool checkTemplate = ShouldCheckTemplate(property); IValueConverter converter = null; if (SelectorControlType.IsAssignableFrom(element.Type)) { string selectionPath; PropertyInfo selectionProperty; if (TryGetByPattern(property, correctedPath, out selectionPath, out selectionProperty, originalName => originalName.MakeSingular(), (info, baseName) => string.Compare(info.Name, "Current" + baseName, StringComparison.CurrentCultureIgnoreCase) == 0 || string.Compare(info.Name, "Active" + baseName, StringComparison.CurrentCultureIgnoreCase) == 0 || string.Compare(info.Name, "Selected" + baseName, StringComparison.CurrentCultureIgnoreCase) == 0 )) { path = selectionPath; bindableProperty = Selector.SelectedItemProperty; mode = selectionProperty.CanWrite ? BindingMode.TwoWay : BindingMode.OneWay; converter = conventionManager.GetValueConverter(bindableProperty, boundProperty.PropertyType); Log.Info("Selector binding convention added to {0}.", element.Name); } else { return(null); } } #if !SILVERLIGHT else if (HeaderedItemsControlType.IsAssignableFrom(element.Type)) { string headerPath; PropertyInfo headerProperty; if (TryGetByPattern(property, correctedPath, out headerPath, out headerProperty, originalName => originalName, (info, baseName) => string.Compare(info.Name, baseName + "Header", StringComparison.CurrentCultureIgnoreCase) == 0 )) { path = headerPath; bindableProperty = HeaderedItemsControl.HeaderProperty; mode = headerProperty.CanWrite ? BindingMode.TwoWay : BindingMode.OneWay; converter = conventionManager.GetValueConverter(bindableProperty, headerProperty.PropertyType); Log.Info("Header binding convention added to {0}.", element.Name); } else { return(null); } } #endif return(new ApplicableBinding( element, bindableProperty, path, mode, false, checkTemplate, converter )); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultResult"/> class. /// </summary> /// <param name="conventionManager">The convention manager.</param> /// <param name="outcome">The outcome of processing the message.</param> public DefaultResult(IConventionManager conventionManager, MessageProcessingOutcome outcome) { _conventionManager = conventionManager; _outcome = outcome; }
/// <summary> /// Initializes a new instance of the <see cref="MessageParserBase{T}"/> class. /// </summary> /// <param name="conventionManager">The convention manager.</param> /// <param name="messageBinder">The message binder.</param> /// <param name="defaultTrigger">The default trigger.</param> protected MessageParserBase(IConventionManager conventionManager, IMessageBinder messageBinder, UpdateSourceTrigger defaultTrigger) { this.conventionManager = conventionManager; this.messageBinder = messageBinder; this.defaultTrigger = defaultTrigger; }
/// <summary> /// Initializes a new instance of the <see cref="MessageParserBase{T}"/> class. /// </summary> /// <param name="messageBinder">The message binder.</param> protected MessageParserBase(IConventionManager conventionManager, IMessageBinder messageBinder) { this.conventionManager = conventionManager; this.messageBinder = messageBinder; }
/// <summary> /// Initializes a new instance of the <see cref="DefaultViewModelDescriptionFactory"/> class. /// </summary> /// <param name="serviceLocator">The service locator.</param> /// <param name="actionLocator">The action locator.</param> /// <param name="conventionManager">The convention manager.</param> public DefaultViewModelDescriptionFactory(IServiceLocator serviceLocator, IActionLocator actionLocator, IConventionManager conventionManager) { this.serviceLocator = serviceLocator; this.actionLocator = actionLocator; this.conventionManager = conventionManager; }
/// <summary> /// Initializes a new instance of the <see cref="MessageParserBase{T}"/> class. /// </summary> protected MessageParserBase(IConventionManager conventionManager, IMessageBinder messageBinder) : this(conventionManager, messageBinder, UpdateSourceTrigger.PropertyChanged) { }
/// <summary> /// Initializes a new instance of the <see cref="CommandMessageParser"/> class. /// </summary> /// <param name="conventionManager">The convention mangager.</param> /// <param name="messageBinder">The message binder.</param> /// <param name="commandSource">The location that the parser will use to get the command.</param> public CommandMessageParser(IConventionManager conventionManager, IMessageBinder messageBinder, CommandSource commandSource) : this(conventionManager, messageBinder, UpdateSourceTrigger.PropertyChanged, commandSource) { }
/// <summary> /// Initializes a new instance of the <see cref="ActionMessageParser"/> class. /// </summary> /// <param name="conventionManager">The convention manager.</param> /// <param name="messageBinder">The message binder.</param> /// <param name="defaultTrigger">The default trigger.</param> public ActionMessageParser(IConventionManager conventionManager, IMessageBinder messageBinder, UpdateSourceTrigger defaultTrigger) : base(conventionManager, messageBinder, defaultTrigger) { }
/// <summary> /// Initializes a new instance of the <see cref="DefaultViewModelDescription"/> class. /// </summary> /// <param name="conventionManager">The convention manager.</param> /// <param name="targetType">Type of the target.</param> public DefaultViewModelDescription(IConventionManager conventionManager, Type targetType) { this.conventionManager = conventionManager; this.targetType = targetType; properties = targetType.GetProperties(); }
/// <summary> /// Initializes a new instance of the <see cref="CommandMessageParser"/> class. /// </summary> /// <param name="conventionManager">The convention manager.</param> /// <param name="messageBinder">The binder.</param> /// <param name="defaultTrigger">The default trigger.</param> /// <param name="commandSource">The location that the parser will use to get the command.</param> public CommandMessageParser(IConventionManager conventionManager, IMessageBinder messageBinder, UpdateSourceTrigger defaultTrigger, CommandSource commandSource) : base(conventionManager, messageBinder, defaultTrigger) { this.commandSource = commandSource; }
/// <summary> /// Initializes a new instance of the <see cref="ActionMessageParser"/> class. /// </summary> /// <param name="conventionManager">The convention manager.</param> /// <param name="messageBinder">The message binder.</param> public ActionMessageParser(IConventionManager conventionManager, IMessageBinder messageBinder) : base(conventionManager, messageBinder) { }
/// <summary> /// Initializes a new instance of the <see cref="CommandMessageParser"/> class. /// </summary> /// <param name="messageBinder">The binder.</param> /// <param name="commandSource">The location that the parser will use to get the command.</param> public CommandMessageParser(IConventionManager conventionManager, IMessageBinder messageBinder, CommandSource commandSource) : base(conventionManager, messageBinder) { this.commandSource = commandSource; }
private static IEnumerable <ElementDescription> DefaultSelectElementsToInspectImplementation(IConventionManager conventionManager, DependencyObject root) { var queue = new Queue <DependencyObject>(); queue.Enqueue(root); while (queue.Count > 0) { var current = queue.Dequeue(); var currentName = current.GetName(); if (!string.IsNullOrEmpty(currentName)) { var currentType = current.GetType(); var currentConvention = conventionManager.GetElementConvention(currentType); if (currentConvention != null) { yield return new ElementDescription { Type = currentType, Name = currentName, Convention = currentConvention } } ; } var childCount = VisualTreeHelper.GetChildrenCount(current); if (childCount > 0) { for (var i = 0; i < childCount; i++) { var childDo = VisualTreeHelper.GetChild(current, i); if (childDo is UserControl) { continue; } queue.Enqueue(childDo); } } else { var contentControl = current as ContentControl; if (contentControl != null) { if (contentControl.Content != null && contentControl.Content is DependencyObject && !(contentControl.Content is UserControl)) { queue.Enqueue(contentControl.Content as DependencyObject); } } else { var itemsControl = current as ItemsControl; if (itemsControl != null) { itemsControl.Items.OfType <DependencyObject>() .Where(item => !(item is UserControl)) .Apply(queue.Enqueue); } } } } }
public void Configure(IEnumerable <Type> views, IEnumerable <Type> viewModels, IEnumerable <Type> attachments, IConventionManager conventionManager) { container.PropertyDependencySelector = new PropertyInjectionDisabler(); foreach (var type in views.Concat(viewModels).Concat(attachments)) { container.Register(type); } container.Initialize(registration => viewModels.Contains(registration.ServiceType), (factory, instance) => { var matchingAttachments = conventionManager.FindMatchingAttachments(instance) .SelectMany(factory.GetAllInstances); foreach (var attachment in matchingAttachments) { AttachmentHelper.Attach(attachment, instance); } }); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultResult"/> class. /// </summary> /// <param name="conventionManager">The convention manager.</param> /// <param name="outcome">The outcome of processing the message.</param> public DefaultResult(IConventionManager conventionManager, MessageProcessingOutcome outcome) { this.conventionManager = conventionManager; this.outcome = outcome; }