/// <summary> /// Adds the interface layer for the given instance to the dynamic binding context. /// </summary> public static void AddInterfaceLayer(this IDynamicBindingContext context, IProductElement element) { Guard.NotNull(() => context, context); Guard.NotNull(() => element, element); //TODO: If we ever allow automation to be defined on an extension point, // then for every pattern that implments and extension point, we must add a key to the cache for that extensionPoint.DefinitionId var layer = default(object); var key = new ToolkitInterfaceLayerCacheKey(element, element.DefinitionId); if (element.Root != null && element.Root.ProductState != null && element.Root.ProductState.PropertyBag != null && !element.Root.ProductState.PropertyBag.TryGetValue(key, out layer)) { layer = GetInterfaceLayer(element); if (layer != null) { element.Root.ProductState.PropertyBag[key] = layer; } } if (layer != null) { context.AddExportsFromInterfaces(layer); } }
/// <summary> /// Evaluates the binding with the additional exports provided in the given context. /// </summary> public bool Evaluate(IDynamicBindingContext context) { Guard.NotNull(() => context, context); var compositionContext = context as CompositionServiceBindingContext; if (compositionContext == null) { throw new ArgumentException(Resources.BindingFactory_UnsupportedDynamicContext); } // Since we're the only ones that can create the valid binding context, // and we're validating that the base FeatureComposition is a Delegating one // at CreateDynamicContext time, we can simply cast here. var delegatingComposition = (DelegatingCompositionService)this.CompositionService; try { using (var compositionService = new ContainerCompositionServiceAdapter(compositionContext.Container)) { delegatingComposition.CompositionService = compositionService; return(this.Evaluate()); } } finally { delegatingComposition.CompositionService = this.originalComposition; } }
/// <summary> /// Adds all interfaces implemented or inherited by the <paramref name="instance"/> as /// dynamic exports. /// </summary> public static void AddExportsFromInterfaces(this IDynamicBindingContext context, object instance) { Guard.NotNull(() => context, context); Guard.NotNull(() => instance, instance); foreach (var iface in instance.GetType().GetInterfaces()) { var addExport = AddExportMethod.MakeGenericMethod(iface); addExport.Invoke(context, new object[] { instance }); } }
public void Initialize() { this.tracer = Mock.Of<ITracer>(); this.context = Mock.Of<IDynamicBindingContext>(); this.valueProvider = Mock.Of<IValueProvider>(vp => (string)vp.Evaluate() == "Foo"); this.binding = Mock.Of<IDynamicBinding<IValueProvider>>(binding => binding.Evaluate(It.IsAny<IDynamicBindingContext>()) == true && binding.Value == this.valueProvider && binding.CreateDynamicContext() == this.context); this.bindingFactory = Mock.Of<IBindingFactory>(factory => factory.CreateBinding<IValueProvider>(It.IsAny<IBindingSettings>()) == this.binding); }
public void Initialize() { this.tracer = Mock.Of <ITracer>(); this.context = Mock.Of <IDynamicBindingContext>(); this.valueProvider = Mock.Of <IValueProvider>(vp => (string)vp.Evaluate() == "Foo"); this.binding = Mock.Of <IDynamicBinding <IValueProvider> >(binding => binding.Evaluate(It.IsAny <IDynamicBindingContext>()) == true && binding.Value == this.valueProvider && binding.CreateDynamicContext() == this.context); this.bindingFactory = Mock.Of <IBindingFactory>(factory => factory.CreateBinding <IValueProvider>(It.IsAny <IBindingSettings>()) == this.binding); }
private static void AddEventArgsToBindingContext(IEvent <EventArgs> args, IDynamicBindingContext context) { //context.AddInterfaceLayer(this.Owner); if (args != null) { // Export the entire event context.AddExport(args); if (args.EventArgs != null) { // Export the args and all its concrete types in the inheritance context.AddExportsFromInheritance(args.EventArgs); } } }
/// <summary> /// Adds all types of the instance and any of its base classes except for <see cref="object"/>. /// </summary> public static void AddExportsFromInheritance(this IDynamicBindingContext context, object instance) { Guard.NotNull(() => context, context); Guard.NotNull(() => instance, instance); var type = instance.GetType(); while (type != typeof(object)) { var addExport = AddExportMethod.MakeGenericMethod(type); addExport.Invoke(context, new object[] { instance }); type = type.BaseType; } }
/// <summary> /// Executes the command. /// </summary> /// <returns><b>true</b> if the wizard was not cancelled; otherwise <b>false</b>.</returns> internal bool ExecuteCommand(IDynamicBindingContext context) { if (this.Settings.CommandId != Guid.Empty) { var commandAutomation = this.ResolveAutomationReference <IAutomationExtension>(this.Settings.CommandId); if (commandAutomation == null) { tracer.Warn(Resources.EventAutomation_NoCommandFound, this.Settings.CommandId, this.Name); return(false); } commandAutomation.Execute(context); } return(true); }
/// <summary> /// Adds the automation extension to the context /// </summary> /// <param name="context"></param> /// <param name="extension"></param> public static void AddAutomation(this IDynamicBindingContext context, IAutomationExtension extension) { Guard.NotNull(() => context, context); Guard.NotNull(() => extension, extension); context.AddExport(extension); context.AddExportsFromInterfaces(extension); context.AddExportsFromInterfaces(extension.Owner); var mel = extension.Owner as ModelElement; if (mel != null) { context.AddExport(mel); } }
/// <summary> /// Executes the wizard. /// </summary> /// <returns><b>true</b> if the wizard was not cancelled; otherwise <b>false</b>.</returns> internal bool ExecuteWizard(IDynamicBindingContext context) { if (this.Settings.WizardId != Guid.Empty) { var wizardAutomation = this.ResolveAutomationReference <IWizardAutomationExtension>(this.Settings.WizardId); if (wizardAutomation == null) { tracer.Error(Resources.MenuAutomation_NoWizardFound, this.Settings.WizardId, this.Name); return(false); } wizardAutomation.Execute(context); return(!wizardAutomation.IsCanceled); } return(true); }
private void Execute(IDynamicBindingContext context, bool withAutomation) { if (withAutomation) { context.AddAutomation(this); } context.AddExport(this.Settings); context.AddInterfaceLayer(this.Owner); var isValid = this.CommandBinding.Evaluate(context); if (isValid) { tracer.Verbose(Resources.CommandAutomation_BindingEvaluatedTrue); this.CommandBinding.Value.Execute(); } else { tracer.Warn(Resources.CommandAutomation_BindingEvaluatedFalse, this.Name, ObjectDumper.ToString(this.CommandBinding.EvaluationResults, 5)); } }
/// <summary> /// Executes the automation behavior on a pre-build context /// </summary> public override void Execute(IDynamicBindingContext context) { this.Execute(); }
public void Execute(IDynamicBindingContext context) { this.Execute(); }
public void Execute(IDynamicBindingContext context) { }
/// <summary> /// Executes the automation behavior on a pre-build context /// </summary> public abstract void Execute(IDynamicBindingContext context);
/// <summary> /// Executes the automation behavior on a pre-build context /// </summary> public override void Execute(IDynamicBindingContext context) { Execute(context, true); }