Exemplo n.º 1
0
        private static Attribute[] BuildAttributes(INuPatternCompositionService service, Reference reference)
        {
            if (service != null)
            {
                // Find KindProvider for this kind
                var exportedProviderRef = service.GetExports <IReferenceKindProvider, IComponentMetadata>()
                                          .Where(provider => provider.Metadata.Id == reference.Kind)
                                          .Select(provider => provider.Value)
                                          .FirstOrDefault();

                if (exportedProviderRef != null)
                {
                    // Get attributes from Type of Provider
                    return(exportedProviderRef.GetType().GetCustomAttributes <Attribute>(true).ToArray());
                }
            }

            // Returns default attributes
            return(new Attribute[]
            {
                new BrowsableAttribute(true),
                new ReadOnlyAttribute(false),
                new CategoryAttribute(string.Empty),
                new DescriptionAttribute(reference.Kind),
                new DisplayNameAttribute(reference.Kind),
            });
        }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a new instance of the <see cref="CommandBinding"/> class.
 /// </summary>
 public CommandBinding(
     INuPatternCompositionService composition,
     string componentTypeId,
     params PropertyBinding[] propertyBindings)
     : base(composition, componentTypeId, propertyBindings)
 {
 }
Exemplo n.º 3
0
        public DynamicBinding(INuPatternCompositionService composition, string componentTypeId, params PropertyBinding[] propertyBindings)
            : base(composition, componentTypeId, propertyBindings)
        {
            var delegatingComposition = this.CompositionService as DelegatingCompositionService;

            if (delegatingComposition != null)
            {
                this.originalComposition = delegatingComposition.CompositionService;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a new instance of the <see cref="Binding{T}"/> class.
        /// </summary>
        /// <param name="composition"></param>
        /// <param name="componentTypeId"></param>
        /// <param name="propertyBindings"></param>
        public Binding(INuPatternCompositionService composition, string componentTypeId, params PropertyBinding[] propertyBindings)
        {
            Guard.NotNull(() => composition, composition);
            Guard.NotNullOrEmpty(() => componentTypeId, componentTypeId);

            this.componentTypeId  = componentTypeId;
            this.composition      = composition;
            this.propertyBindings = propertyBindings;

            ResolveComponentTypeId();

            composition.SatisfyImportsOnce(this);
        }
        public CommandSettingsValidations(INuPatternCompositionService composition)
        {
            Guard.NotNull(() => composition, composition);

            // We statically cache the lookups here.
            // TODO: this could be refactored into a separate global service.
            if (ValueProviders == null || Commands == null || Validators == null)
            {
                var valueProviders = composition.GetExports <IValueProvider, IComponentMetadata>();
                var commands       = composition.GetExports <ICommand, IComponentMetadata>();
                var validators     = composition.GetExports <ICommandValidationRule, ICommandValidationRuleMetadata>();

                ValueProviders = valueProviders.ToLookup(item => item.Metadata.Id, item => item.Metadata.ExportingType);
                Commands       = commands.ToLookup(item => item.Metadata.Id, item => item.Metadata.ExportingType);
                Validators     = validators.ToLookup(item => item.Metadata.CommandType.ToString(), item => item);
            }
        }
        public CommandSettingsValidations(INuPatternCompositionService composition)
        {
            Guard.NotNull(() => composition, composition);

            // We statically cache the lookups here.
            // TODO: this could be refactored into a separate global service.
            if (ValueProviders == null || Commands == null || Validators == null)
            {
                var valueProviders = composition.GetExports<IValueProvider, IComponentMetadata>();
                var commands = composition.GetExports<ICommand, IComponentMetadata>();
                var validators = composition.GetExports<ICommandValidationRule, ICommandValidationRuleMetadata>();

                ValueProviders = valueProviders.ToLookup(item => item.Metadata.Id, item => item.Metadata.ExportingType);
                Commands = commands.ToLookup(item => item.Metadata.Id, item => item.Metadata.ExportingType);
                Validators = validators.ToLookup(item => item.Metadata.CommandType.ToString(), item => item);
            }
        }
        public EventSettingsValidations(INuPatternCompositionService composition)
        {
            Guard.NotNull(() => composition, composition);

            // We statically cache the lookups here.
            // TODO: this could be refactored into a separate global service.
            if (ValueProviders == null || Conditions == null || Events == null)
            {
                var valueProviders = composition.GetExports<IValueProvider, IComponentMetadata>();
                var conditions = composition.GetExports<ICondition, IComponentMetadata>();
                var events = composition.GetExports<IObservableEvent, IIdMetadata>();

                ValueProviders = valueProviders.ToLookup(item => item.Metadata.Id, item => item.Metadata.ExportingType);
                Conditions = conditions.ToLookup(item => item.Metadata.Id, item => item.Metadata.ExportingType);

                // Unlike feature components, the events are exposed globally, and are not 
                // decorated by the feature runtime, so there's no way to get to its ExportingType.
                // So the only way to retrieve its actual type is to get its instantiated value.
                // Which is anyways guaranteed to work as otherwise they wouldn't exist 
                // in the global catalog at all ;)
                Events = events.ToLookup(item => item.Metadata.Id, item => new Lazy<Type>(() => item.Value.GetType()));
            }
        }
Exemplo n.º 8
0
        public MenuSettingsValidations(INuPatternCompositionService composition)
        {
            Guard.NotNull(() => composition, composition);

            // We statically cache the lookups here.
            // TODO: this could be refactored into a separate global service.
            if (ValueProviders == null || Conditions == null || Events == null)
            {
                var valueProviders = composition.GetExports <IValueProvider, IComponentMetadata>();
                var conditions     = composition.GetExports <ICondition, IComponentMetadata>();
                var events         = composition.GetExports <IObservableEvent, IIdMetadata>();

                ValueProviders = valueProviders.ToLookup(item => item.Metadata.Id, item => item.Metadata.ExportingType);
                Conditions     = conditions.ToLookup(item => item.Metadata.Id, item => item.Metadata.ExportingType);

                // Unlike feature components, the events are exposed globally, and are not
                // decorated by the feature runtime, so there's no way to get to its ExportingType.
                // So the only way to retrieve its actual type is to get its instantiated value.
                // Which is anyways guaranteed to work as otherwise they wouldn't exist
                // in the global catalog at all ;)
                Events = events.ToLookup(item => item.Metadata.Id, item => new Lazy <Type>(() => item.Value.GetType()));
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CompositionServiceBindingContext"/> class.
        /// </summary>
        public CompositionServiceBindingContext(INuPatternCompositionService compositionService)
        {
            try
            {
                // TODO: This should work as per suggestion BlueTab-PLATU10.
                this.SetupContainer(compositionService.GetExportedValue <ExportProvider>());

                return;
            }
            catch (ImportCardinalityMismatchException)
            {
                // TODO: \o/ when BlueTab-PLATU10 is fixed, this workaround should be removed.
                // Note: we don't go straight for this behavior because otherwise anything that uses dynamic
                // bindings would become untestable automatically.
                var defaultImplementation = compositionService as NuPatternCompositionService;
                if (defaultImplementation != null)
                {
                    var containerField = typeof(NuPatternCompositionService).GetField("container", BindingFlags.Instance | BindingFlags.NonPublic);
                    if (containerField == null)
                    {
                        throw new NotSupportedException(Resources.BindingFactory_DefaultCompositionServiceChanged);
                    }

                    var compositionContainer = containerField.GetValue(defaultImplementation) as CompositionContainer;
                    if (compositionContainer == null)
                    {
                        throw new NotSupportedException(Resources.BindingFactory_DefaultCompositionServiceContainerUnavailable);
                    }

                    this.SetupContainer(compositionContainer);

                    return;
                }
            }

            throw new NotSupportedException(Resources.BindingFactory_DynamicContextUnsupported);
        }
Exemplo n.º 10
0
 public void Initialize()
 {
     this.globalContainer    = VsIdeTestHostContext.ServiceProvider.GetService <SComponentModel, IComponentModel>();
     this.compositionService = VsIdeTestHostContext.ServiceProvider.GetService <INuPatternCompositionService>();
 }
Exemplo n.º 11
0
        // TODO: we must implement all the type conversion here, as well as the type loading and stuff.

        /// <summary>
        /// Initializes a new instance of the <see cref="ReferencePropertyDescriptor"/> class.
        /// </summary>
        /// <param name="reference">The property.</param>
        /// <param name="service">The <see cref="INuPatternCompositionService"/>.</param>
        public ReferencePropertyDescriptor(INuPatternCompositionService service, Reference reference)
            : base(reference.Kind, BuildAttributes(service, reference))
        {
            this.reference = reference;
        }
        // TODO: we must implement all the type conversion here, as well as the type loading and stuff.

        /// <summary>
        /// Initializes a new instance of the <see cref="ReferencePropertyDescriptor"/> class.
        /// </summary>
        /// <param name="reference">The property.</param>
        /// <param name="service">The <see cref="INuPatternCompositionService"/>.</param>
        public ReferencePropertyDescriptor(INuPatternCompositionService service, Reference reference)
            : base(reference.Kind, BuildAttributes(service, reference))
        {
            this.reference = reference;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DelegatingCompositionService"/> class.
 /// </summary>
 /// <param name="compositionService">The composition service.</param>
 public DelegatingCompositionService(INuPatternCompositionService compositionService)
 {
     this.CompositionService = compositionService;
 }
Exemplo n.º 14
0
 public ConditionBinding(INuPatternCompositionService featureComposition, string componentTypeId, params PropertyBinding[] propertyBindings)
     : base(featureComposition, componentTypeId, propertyBindings)
 {
 }
        private static Attribute[] BuildAttributes(INuPatternCompositionService service, Reference reference)
        {
            if (service != null)
            {
                // Find KindProvider for this kind
                var exportedProviderRef = service.GetExports<IReferenceKindProvider, IComponentMetadata>()
                    .Where(provider => provider.Metadata.Id == reference.Kind)
                    .Select(provider => provider.Value)
                    .FirstOrDefault();

                if (exportedProviderRef != null)
                {
                    // Get attributes from Type of Provider
                    return exportedProviderRef.GetType().GetCustomAttributes<Attribute>(true).ToArray();
                }
            }

            // Returns default attributes
            return new Attribute[]
                {
                    new BrowsableAttribute(true),
                    new ReadOnlyAttribute(false),
                    new CategoryAttribute(string.Empty),
                    new DescriptionAttribute(reference.Kind),
                    new DisplayNameAttribute(reference.Kind),
                };
        }
 public void Initialize()
 {
     this.globalContainer = VsIdeTestHostContext.ServiceProvider.GetService<SComponentModel, IComponentModel>();
     this.compositionService = VsIdeTestHostContext.ServiceProvider.GetService<INuPatternCompositionService>();
 }
Exemplo n.º 17
0
 static NuPatternCompositionService()
 {
     Instance = new NuPatternCompositionService(NuPatternGlobalContainer.Instance);
     // Publish our own service to the global container.
     NuPatternGlobalContainer.Instance.ComposeExportedValue <INuPatternCompositionService>(Instance);
 }
Exemplo n.º 18
0
        private PropertyBinding[] GetPropertyBindings(IEnumerable <IPropertyBindingSettings> properties, INuPatternCompositionService composition)
        {
            var bindings = new List <PropertyBinding>();

            if (properties == null)
            {
                return(bindings.ToArray());
            }

            foreach (var property in properties)
            {
                if (!string.IsNullOrEmpty(property.Value))
                {
                    bindings.Add(new FixedValuePropertyBinding(property.Name, property.Value));
                }
                else if (property.ValueProvider != null)
                {
                    bindings.Add(
                        new ValueProviderPropertyBinding(
                            property.Name,
                            new DynamicBinding <IValueProvider>(
                                composition,
                                property.ValueProvider.TypeId,
                                this.GetPropertyBindings(property.ValueProvider.Properties, composition))));
                }
            }

            return(bindings.ToArray());
        }
Exemplo n.º 19
0
        public BindingFactory(IBindingCompositionService compositionService)
        {
            Guard.NotNull(() => compositionService, compositionService);

            this.compositionService = compositionService;
        }