private void validateSearchAndReturn() { if (!units.Keys.Contains(tbSearch.Text)) lblError.Visible = true; else { ResultType = units[tbSearch.Text]; this.DialogResult = DialogResult.OK; } }
/// <summary> /// Returns a collection of children and parent types of each type. This information is stored in IDictionaries, where the key is a Type, and the value is a collection of either children or parents types for the type that is the key. /// <para>Children of a type are all types that are referenced by the type in question.</para> /// <para>Parents of a type are all types that reference the type in question</para> /// </summary> /// <param name="typeUnits">Collection of types from which the information about child and parent types are built.</param> /// <param name="childrenDictionary">Dictionary of children types for the type represented by the key.</param> /// <param name="parentsDictionary">Dictionary of parent types for the type represented by the key.</param> public static void GetChildrenAndParentsDictonaryOfTypes(IDictionary <String, TypeVisualUnit> typeUnits, out IDictionary <TypeVisualUnit, ICollection <TypeVisualUnit> > childrenDictionary, out IDictionary <TypeVisualUnit, ICollection <TypeVisualUnit> > parentsDictionary) { childrenDictionary = new Dictionary <TypeVisualUnit, ICollection <TypeVisualUnit> >(); parentsDictionary = new Dictionary <TypeVisualUnit, ICollection <TypeVisualUnit> >(); foreach (TypeVisualUnit type in typeUnits.Values) { try { //typeUnitsDictionary.Add(type.Name, type); childrenDictionary.Add(type, new List <TypeVisualUnit>()); parentsDictionary.Add(type, new List <TypeVisualUnit>()); } catch (ArgumentException) { throw new ArgumentException("Duplicate types in the types collection."); } } foreach (TypeVisualUnit type in typeUnits.Values) { foreach (TypeVisualProperty property in type.NonScalarProperties) { string propertyType = property.Type; TypeVisualUnit child = typeUnits[propertyType]; if (!childrenDictionary[type].Contains(child)) { childrenDictionary[type].Add(child); } if (!parentsDictionary[child].Contains(type)) { parentsDictionary[child].Add(type); } } } }
/// <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); } } }
private void changeCurrentTypeAndRefreshLists(TypeVisualUnit currentType) { CurrentType = currentType; tbCurrentType.Text = CurrentType.ToString(); fillListBoxes(); }