internal void AddReferenceItem(GenericReferenceItem[] mirrorItems, IGraphItem item, NodeConfigSectionBase mirrorSection) { var current = mirrorItems.FirstOrDefault(p => p.SourceIdentifier == item.Identifier); if (current != null && !mirrorSection.AllowDuplicates) { return; } var newMirror = Activator.CreateInstance(mirrorSection.SourceType) as GenericReferenceItem; newMirror.Node = this; Node.Repository.Add(newMirror); newMirror.SourceIdentifier = item.Identifier; //Node.Project.AddItem(newMirror); }
private GraphItemConfiguration CreateSectionConfiguration(PropertyInfo property, Section section) { var sectionConfig = new NodeConfigSectionBase { Name = section.Name, IsProxy = section is ProxySection, Visibility = section.Visibility, SourceType = property.PropertyType.GetGenericParameter(), AddCommandType = section.AddCommandType }; var referenceSection = section as ReferenceSection; if (referenceSection != null) { sectionConfig.AllowDuplicates = referenceSection.AllowDuplicates; sectionConfig.AllowAdding = !referenceSection.Automatic; sectionConfig.ReferenceType = referenceSection.ReferenceType ?? sectionConfig.SourceType.GetGenericParameter() ?? property.PropertyType.GetGenericParameter(); sectionConfig.IsEditable = referenceSection.Editable; sectionConfig.HasPredefinedOptions = referenceSection.HasPredefinedOptions; if (sectionConfig.ReferenceType == null) { throw new Exception(string.Format("Reference Section on property {0} doesn't have a valid ReferenceType.", property.Name)); } //sectionConfig.GenericSelector = (node) => //{ //}; } if (sectionConfig.IsProxy || referenceSection == null) { var property1 = property; if (sectionConfig.IsProxy) { sectionConfig.AllowAdding = false; } sectionConfig.GenericSelector = (node) => { var enumerator = property1.GetValue(node, null) as IEnumerable; if (enumerator == null) { return(null); } return(enumerator.Cast <IGraphItem>()); }; } else if (referenceSection != null) { var possibleSelectorProperty = NodeType.GetProperty("Possible" + property.Name); if (possibleSelectorProperty != null) { sectionConfig.GenericSelector = (node) => { var propertyN = NodeType.GetProperty("Possible" + property.Name); var enumerator = propertyN.GetValue(node, null) as IEnumerable; if (enumerator == null) { return(null); } return(enumerator.OfType <IGraphItem>()); }; } else { sectionConfig.GenericSelector = (node) => { return(node.Repository.AllOf <IGraphItem>().Where(p => referenceSection.ReferenceType.IsAssignableFrom(p.GetType()))); }; } } return(sectionConfig); }
public void AddReferenceItem(IGraphItem item, NodeConfigSectionBase mirrorSection) { AddReferenceItem(PersistedItems.Where(p => p.GetType() == mirrorSection.ReferenceType).Cast <GenericReferenceItem>().ToArray(), item, mirrorSection); }