public ChooseTypeForm(IDictionary <String, TypeVisualUnit> units, string rootTypeName) { InitializeComponent(); this.rootTypeName = rootTypeName; this.units = new Dictionary <String, TypeVisualUnit>(units); TypeVisualUtilities.GetChildrenAndParentsDictonaryOfTypes(this.units, out childrenDictionary, out parentsDictionary); showRootType(); }
/// <summary> /// Returns the Id of the node type with the specified name. It looks in the types pointed by the TypesRoot node. /// </summary> /// <param name="typeName">Type name to compare possible results to.</param> /// <returns>The Id of the node pointing to the type. Empty if node is not found</returns> private Guid GetIdFromTypeName(string typeName) { foreach (var edge in provider.GetNode(Constants.TypesNodeId, NodeAccess.Read).Edges.Values) { if (edge.Data.Semantic.Equals(EdgeType.Contains)) { var node = provider.GetNode(edge.ToNodeId, NodeAccess.Read); string nodeData = TypeVisualUtilities.GetTypeNameFromAssemblyName((string)node.Data); if (typeName.Equals(nodeData)) { return(edge.ToNodeId); } } } return(Guid.Empty); }
/// <summary> /// Returns the name of the type that represents the root of the database (the representation of the Data Model) /// </summary> /// <returns></returns> public string getRootTypeName() { var typeNode = provider.GetNode(GetRootTypeId(), NodeAccess.Read); return(TypeVisualUtilities.GetTypeNameFromAssemblyName((string)typeNode.Data)); }
/// <summary> /// Recursively fills the units dictionary with a TypeVisualisationUnit of the Guid - typeNodeId. /// </summary> /// <param name="typeNodeId"></param> /// <param name="units"></param> /// <param name="ignoreTypeNames"></param> private void GetTypeVisualUnitsRecursive(Guid typeNodeId, IDictionary <String, TypeVisualUnit> units, ICollection <string> ignoreTypeNames) { TypeVisualUnit unit = null; string typeName = null; ICollection <TypeVisualProperty> scalarProperties = new List <TypeVisualProperty>(); ICollection <TypeVisualProperty> nonScalarProperties = new List <TypeVisualProperty>(); if (!typeNodeId.Equals(Guid.Empty)) { var typeNode = provider.GetNode(typeNodeId, NodeAccess.Read); typeName = TypeVisualUtilities.GetTypeNameFromAssemblyName((string)typeNode.Data); if (!ignoreTypeNames.Contains(typeName)) { ignoreTypeNames.Add(typeName); foreach (var edge in typeNode.Edges.Values) { if (edge.Data.Semantic.Equals(EdgeType.Property)) { //setting name and type bool isScalar; var nodeProperty = provider.GetNode(edge.ToNodeId, NodeAccess.Read); var nodePropertyType = provider.GetNode(nodeProperty.Edges.Values[0].ToNodeId, NodeAccess.Read); string propertyTypeName = TypeVisualUtilities.GetTypeNameFromAssemblyName((string)nodePropertyType.Data); string collectionKey, collectionValue; PropertyCollectionType collectionType = TypeVisualUtilities.CheckIfCollectionOrDictionary(propertyTypeName, out collectionKey, out collectionValue); //checking if property is a collection and if property is scalar. if (collectionType != PropertyCollectionType.NotACollection) { if (!typesService.IsSupportedScalarTypeName(collectionValue)) { Guid genericArgumentTypeId = GetIdFromTypeName(collectionValue); if (!genericArgumentTypeId.Equals(Guid.Empty)) { //ignoreTypeNames.Add(typeName); GetTypeVisualUnitsRecursive(genericArgumentTypeId, units, ignoreTypeNames); } isScalar = false; } else { isScalar = true; } propertyTypeName = collectionValue; } else if (!typesService.IsSupportedScalarTypeName(propertyTypeName)) { //ignoreTypeNames.Add(typeName); GetTypeVisualUnitsRecursive(nodeProperty.Edges.Values[0].ToNodeId, units, ignoreTypeNames); isScalar = false; } else { isScalar = true; } //setting additional property attributes bool isImmutable, isPrimaryKey; PropertyAttribute propAttribute; isImmutable = edge.Data.Flags.Equals(EdgeFlags.Permanent); isPrimaryKey = nodeProperty.Values.ContainsKey(Constants.TypeMemberPrimaryKeyId); if (isImmutable && isPrimaryKey) { propAttribute = PropertyAttribute.PrimaryKeyAndImmutableProperty; } else if (isImmutable) { propAttribute = PropertyAttribute.ImmutableProperty; } else if (isPrimaryKey) { propAttribute = PropertyAttribute.PrimaryKeyProperty; } else { propAttribute = PropertyAttribute.None; } //adding the property to either scalar or non-scalar lists. TypeVisualProperty property = new TypeVisualProperty((string)nodeProperty.Data, propertyTypeName, propAttribute, collectionType, collectionKey); if (isScalar) { scalarProperties.Add(property); } else { nonScalarProperties.Add(property); } } else if (edge.Data.Semantic.Equals(EdgeType.Contains)) { var nodeProperty = provider.GetNode(edge.ToNodeId, NodeAccess.Read); TypeVisualProperty property = new TypeVisualProperty((string)nodeProperty.Data, TypeVisualProperty.EnumType, PropertyAttribute.None, PropertyCollectionType.NotACollection, ""); scalarProperties.Add(property); } } unit = new TypeVisualUnit(typeName, scalarProperties, nonScalarProperties); units.Add(unit.Name, unit); } } }