private void Build(IModelRoot modelRoot) { var inheritanceTrees = InheritanceTreeCache.Get(modelRoot.TopHierarchyTypes.ToArray()); foreach (var tree in inheritanceTrees) { if (!tree.TreeRebuilded) { tree.RebuildTree(true); } } var mergePaths = InheritanceTree.MergePaths(inheritanceTrees); var dependencyImplementationFlatList = InheritanceTree.GetDependencyImplementationFlatList(mergePaths); foreach (var @interface in dependencyImplementationFlatList) { IPropertiesBuilder propertiesBuilder = PropertiesBuilder.Build(@interface); lock (sync) { propertiesBuilders.Add(@interface, propertiesBuilder); } } // process rest types (e.g. with no inheritance defined) foreach (var @interface in modelRoot.PersistentTypes.Except(dependencyImplementationFlatList)) { IPropertiesBuilder propertiesBuilder = PropertiesBuilder.Build(@interface); lock (sync) { propertiesBuilders.Add(@interface, propertiesBuilder); } } }
public override ReadOnlyCollection <IPropertyBase> GetAllProperties(bool includeInheritance) { if (!includeInheritance) { return(base.GetAllProperties(false)); } var inheritanceTree = InheritanceTreeCache.Get(this); var distinctByName = new IdentityProjectionEqualityComparer <IPropertyBase, string>(property => property.Name); var flatList = inheritanceTree.GetFlatList(InheritanceListMode.WholeTree); var inheritanceList = flatList.Reverse().Select((node, i) => new { pos = i, @interface = node.Interface }); var allProps = (from item in inheritanceList orderby item.pos select [email protected]).SelectMany(list => list).Concat(this.AllProperties); var result = allProps.Distinct(distinctByName).ToList(); return(new ReadOnlyCollection <IPropertyBase>(result)); }
private void Prepare() { thisInterface = persistentType as IInterface; if (thisInterface == null) { return; } //inheritanceTree = thisInterface.GetInheritanceTree(); inheritanceTree = InheritanceTreeCache.Get(thisInterface); if (!inheritanceTree.TreeRebuilded) { inheritanceTree.RebuildTree(); } allInheritanceTypes = inheritanceTree.GetFlatList(InheritanceListMode.WholeTree); PrepareTypeAttributes(); PrepareProperties(); PreparePropertiesTypeAttributes(); }
public override void ExecCommand(MenuCommand menuCommand) { CurrentModelSelection currentSelection = GetCurrentSelectedPersistentType(); IInterface sourceInterface = currentSelection.CurrentPersistentType as IInterface; FormImplementInterface.ImplementData resultData; var helperDic = new Dictionary <IInterface, FormImplementInterface.InterfaceTreeItem>(); var sourceInterfaceItem = new FormImplementInterface.InterfaceTreeItem(sourceInterface.Name, sourceInterface); helperDic.Add(sourceInterface, sourceInterfaceItem); var currentInterfaceItem = sourceInterfaceItem; int currentLevel = 0; var inheritanceTree = InheritanceTreeCache.Get(sourceInterface); //sourceInterface.GetInheritanceTree(); if (!inheritanceTree.TreeRebuilded) { inheritanceTree.RebuildTree(false); } inheritanceTree.IterateTree(false, delegate(InheritanceTreeIterator iterator) { if (iterator.Level != currentLevel) { currentLevel = iterator.Level; currentInterfaceItem = helperDic[iterator.Parent.Interface]; } var childItem = new FormImplementInterface.InterfaceTreeItem(iterator.Current.Interface.Name, iterator.Current.Interface); childItem.Parent = currentInterfaceItem; currentInterfaceItem.Childs.Add(childItem); if (!helperDic.ContainsKey(iterator.Current.Interface)) { helperDic.Add(iterator.Current.Interface, childItem); } }); if (FormImplementInterface.DialogShow("Implement interface into new Entity or Structure", "Type name", sourceInterfaceItem, out resultData)) { PersistentTypeKind typeKind = resultData.EntityKind == EntityKind.Entity ? PersistentTypeKind.Entity : PersistentTypeKind.Structure; var rootItem = resultData.Root; IInterface rootInterface = (IInterface)rootItem.Data; (sourceInterface as PersistentType).Store.MakeActionWithinTransaction( string.Format( "Implementing root interface '{0}' (with in/direct inheritances) to new '{1}' named '{2}'", rootInterface.Name, typeKind, resultData.Name), delegate { IEntityBase newEntity = rootInterface.ImplementToNewType(typeKind, resultData.Name, ImplementTypeOptions.Default); if (newEntity != null) { foreach (var interfaceToImplementItem in resultData.Selection.Where(item => item.Parent == null)) { IInterface interfaceToImplement = (IInterface)interfaceToImplementItem.Data; if (interfaceToImplement != rootInterface) { interfaceToImplement.ImplementToType(newEntity, ImplementTypeOptions.Default); } } Owner.SelectModelElement((ModelElement)newEntity); } }); } }