예제 #1
0
        /// <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);
            }
        }
예제 #2
0
        /// <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);
            }
        }