private CommandModel CreateDefaultElementCollectionAddCommand(ElementCollectionViewModel collection) { if (collection.IsPolymorphicCollection || HasMultipleAddCommands(collection.CollectionElementType)) { return(builder.Resolve <DefaultElementCollectionAddCommand>(new DependencyOverride(typeof(ElementCollectionViewModel), collection))); } return(CreateDefaultCollectionElementAddCommand(collection.CollectionElementType, collection)); }
/// <summary> /// Creates a <see cref="CollectionElementViewModel"/> based on a <see cref="ConfigurationElement"/>. /// </summary> /// <param name="parent">The parent of the created element.</param> /// <param name="containedElement">The <see cref="ConfigurationElement"/> for the contained element.</param> /// <returns> /// The created <see cref="CollectionElementViewModel"/> or a derived custom view model specified by the <see cref="ViewModelAttribute"/>. /// </returns> public virtual CollectionElementViewModel CreateCollectionElement(ElementCollectionViewModel parent, ConfigurationElement containedElement) { IEnumerable <Attribute> metadataForCreatingViewModel = TypeDescriptor.GetAttributes(containedElement).OfType <Attribute>(); return(CreateViewModelInstance <CollectionElementViewModel>( builder, metadataForCreatingViewModel, new DependencyOverride(typeof(ElementCollectionViewModel), parent), new DependencyOverride(typeof(ConfigurationElement), containedElement), new DependencyOverride(typeof(SectionViewModel), this))); }
private IEnumerable <CommandModel> CreateCustomAddCommands(Type elementType, ElementCollectionViewModel collection) { var customAddCommandAttributes = TypeDescriptor.GetAttributes(elementType).OfType <CommandAttribute>() .Where(x => x.CommandPlacement == CommandPlacement.ContextAdd) .Where(x => x.Replace != CommandReplacement.DefaultAddCommandReplacement); foreach (var customAddCommandAttribute in customAddCommandAttributes) { yield return((CommandModel)builder.Resolve(customAddCommandAttribute.CommandModelType, new DependencyOverride(customAddCommandAttribute.GetType(), customAddCommandAttribute), new DependencyOverride(typeof(ConfigurationElementType), new ConfigurationElementType(elementType)), new DependencyOverride(typeof(ElementCollectionViewModel), collection))); } }
/// <summary> /// Initializes a new instance of <see cref="CollectionElementViewModel"/>. /// </summary> /// <param name="containingCollection">The collection containing this element.</param> /// <param name="thisElement">The <see cref="ConfigurationElement"/> modeled by the <see cref="CollectionElementViewModel"/>.</param> /// <param name="additionalAttributes">Additional <see cref="Attribute"/> items to apply when describing this <paramref name="thisElement"/>.</param> public CollectionElementViewModel(ElementCollectionViewModel containingCollection, ConfigurationElement thisElement, IEnumerable <Attribute> additionalAttributes) : base(containingCollection, thisElement, additionalAttributes) { this.containingCollection = containingCollection; configurationCollectionAttribute = containingCollection.Attributes.OfType <ConfigurationCollectionAttribute>().First(); var overrides = new Dictionary <Type, object>() { { typeof(ElementCollectionViewModel), containingCollection }, { typeof(CollectionElementViewModel), this } }; MoveUp = ContainingSection.CreateCommand <MoveUpCommand>(overrides); MoveDown = ContainingSection.CreateCommand <MoveDownCommand>(overrides); }
///<summary> /// Initializes an instance of DefaultElementCollectionAddCommand. /// </summary> ///<param name="collection">The collection that will be affected by the add command.</param> ///<param name="uiService"><see cref="IUIServiceWpf"/> for displaying messages.</param> public DefaultElementCollectionAddCommand(ElementCollectionViewModel collection, IUIServiceWpf uiService) : base(uiService) { this.collection = collection; this.section = collection.ContainingSection; if (this.collection.IsPolymorphicCollection) { childCommands = this.collection.PolymorphicCollectionElementTypes .SelectMany(x => section.CreateCollectionElementAddCommand(x, collection)) .OrderBy(x => x.Title) .ToArray(); } else { childCommands = section.CreateCollectionElementAddCommand(collection.CollectionElementType, collection).ToArray(); } }
private CommandModel CreateDefaultCollectionElementAddCommand(Type elementType, ElementCollectionViewModel collection) { var replaceCommandAttribute = TypeDescriptor.GetAttributes(elementType) .OfType <CommandAttribute>() .Where(x => x.CommandPlacement == CommandPlacement.ContextAdd) .Where(x => x.Replace == CommandReplacement.DefaultAddCommandReplacement) .FirstOrDefault(); if (replaceCommandAttribute != null) { return((CommandModel)builder.Resolve(replaceCommandAttribute.CommandModelType, new DependencyOverride(replaceCommandAttribute.GetType(), replaceCommandAttribute), new DependencyOverride <ConfigurationElementType>(new ConfigurationElementType(elementType)), new DependencyOverride <ElementCollectionViewModel>(collection))); } return(builder.Resolve <DefaultCollectionElementAddCommand>( new DependencyOverride <ConfigurationElementType>(new ConfigurationElementType(elementType)), new DependencyOverride <ElementCollectionViewModel>(collection))); }
///<summary> /// Creates the add command for an <see cref="ElementCollectionViewModel"/>. ///</summary> ///<param name="attributes">The attributes to consider when creating the command.</param> ///<param name="collection">The <see cref="ElementCollectionViewModel"/> to create the add command for.</param> ///<returns> /// If there is a replacement add command in the <paramref name="attributes"/> set, a command of that type is returned. ///<br/> /// If the collection is a polymorphic collection or there are multiple add commands, then a command of type <see cref="DefaultElementCollectionAddCommand"/> will be returned. /// <br/> /// If the collection is not polymorphic, then the add command for the <see cref="ElementCollectionViewModel.CollectionElementType"/> is returned /// since the collection only has one type that can be added for it and we don't want the user to navigate multiple menus unnecessarily. ///</returns> /// <exception>Errors in creating the underlying object may result in a <see cref="ResolutionFailedException"/></exception> public virtual CommandModel CreateElementCollectionAddCommands(IEnumerable <Attribute> attributes, ElementCollectionViewModel collection) { var addCommandReplacement = attributes.OfType <CommandAttribute>().Where(x => x.Replace == CommandReplacement.DefaultAddCommandReplacement).FirstOrDefault(); if (addCommandReplacement != null) { return((CommandModel)builder.Resolve(addCommandReplacement.CommandModelType, new DependencyOverride(addCommandReplacement.GetType(), addCommandReplacement), new DependencyOverride(typeof(ElementCollectionViewModel), collection))); } return(CreateDefaultElementCollectionAddCommand(collection)); }
/// <summary> /// Creates the collection element add command(s) for the given element type within the <see cref="ElementCollectionViewModel"/>. /// </summary> /// <param name="elementType">The <see cref="ConfigurationElement"/> <see cref="Type"/> to create add commands for.</param> /// <param name="collection">The collection to which new elements of <paramref name="elementType"/> will be added.</param> /// <returns>The set of add commands.</returns> /// <exception>Errors in creating the underlying object may result in a <see cref="ResolutionFailedException"/></exception> public virtual IEnumerable <CommandModel> CreateCollectionElementAddCommand(Type elementType, ElementCollectionViewModel collection) { yield return(CreateDefaultCollectionElementAddCommand(elementType, collection)); foreach (var customCommand in CreateCustomAddCommands(elementType, collection)) { yield return(customCommand); } }
protected DefaultCollectionElementAddCommand(CommandAttribute commandAttribute, ConfigurationElementType configurationElementType, ElementCollectionViewModel collection, IUIServiceWpf uiService) : base(commandAttribute, uiService) { Guard.ArgumentNotNull(configurationElementType, "configurationElementType"); this.ConfigurationElementType = configurationElementType.ElementType; this.ElementCollectionModel = collection; commandPlacement = commandAttribute.CommandPlacement; }
public DefaultCollectionElementAddCommand(ConfigurationElementType configurationElementType, ElementCollectionViewModel collection, IUIServiceWpf uiService) : base(uiService) { Guard.ArgumentNotNull(configurationElementType, "configurationElementType"); this.ConfigurationElementType = configurationElementType.ElementType; this.ElementCollectionModel = collection; commandPlacement = CommandPlacement.ContextAdd; }
public TypePickingCollectionElementAddCommand(IUIServiceWpf uiService, IAssemblyDiscoveryService discoveryService, TypePickingCommandAttribute commandAttribute, ConfigurationElementType configurationElementType, ElementCollectionViewModel elementCollectionModel) : base(commandAttribute, configurationElementType, elementCollectionModel, uiService) { Guard.ArgumentNotNull(commandAttribute, "commandAttribute"); this.discoveryService = discoveryService; this.propertyToSet = commandAttribute.Property; if (propertyToSet == null) { throw new ArgumentException( "Target ConfigurationElement must have an accessible property named TypeName or a specified property of type string."); } }
public CollectionElementViewModel(ElementCollectionViewModel containingCollection, ConfigurationElement thisElement) : this(containingCollection, thisElement, Enumerable.Empty <Attribute>()) { }