Exemple #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),
            });
        }
        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()));
            }
        }
        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()));
            }
        }
Exemple #6
0
 private void ResolveComponentTypeId()
 {
     this.lazyValue = composition.GetExports <T, IComponentMetadata>()
                      .FromComponentCatalog()
                      .FirstOrDefault(component => component.Metadata.Id == componentTypeId);
 }
        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),
                };
        }