private static void CheckEnums(List <EnumerationData> enums, TypeSet t, Action CheckContents, ref ParameterType modifiedType, bool hidden) { EnumerationData Enumeration1 = new EnumerationData("enum1", ParameterType.Parse(hidden ? "e25f2768-ac00-4320-a558-12b51d85d771" : "f70fb4d1-59f5-4618-9bc4-8da19f943da2"), new[] { new EnumerationData.Element("value1", Guid.Parse("9ee98b1e-fb29-42c5-8a26-903a8aecacc0")), new EnumerationData.Element("value2", Guid.Parse("a3ed3b47-9985-4f17-b791-4155cc7196f4")) }); EnumerationData Enumeration2 = new EnumerationData("enum2", ParameterType.Parse(hidden ? "19bf99ff-98f2-4ab3-96d6-1f7e61d98ae7" : "a532c7c0-2806-4def-9fb2-5182b6803cbe"), new[] { new EnumerationData.Element("value1", Guid.Parse("e80fd4c3-eb10-4309-b683-79c3675b6fb8")), new EnumerationData.Element("value2", Guid.Parse("c0b0a09e-4825-479e-87dc-599bdacf045f")) }); EnumerationData Enumeration3 = new EnumerationData("enum3", ParameterType.Parse(hidden ? "b78e53cd-717b-446f-9ab2-fbbf5c41b067" : "aa274a73-95c1-4272-bb23-9c9cabeb183e"), new[] { new EnumerationData.Element("asd", Guid.Parse("27b59086-7e9b-4b7f-8796-a7a23eb727c1")), new EnumerationData.Element("sdasd", Guid.Parse("b08cf9e0-9d77-42cf-9f1c-a21def2b79d3")), new EnumerationData.Element("sdasd2", Guid.Parse("4f73eaad-86fe-4cbb-adbc-016724399ae5")) }); var a = Enumeration1; t.AddEnum(a, hidden); enums.Add(a); Assert.That(modifiedType, Is.EqualTo(a.TypeId)); modifiedType = null; CheckContents(); a = Enumeration2; t.AddEnum(a, hidden); enums.Add(a); Assert.That(modifiedType, Is.EqualTo(a.TypeId)); modifiedType = null; CheckContents(); a = Enumeration1; t.Remove(a.TypeId); enums.Remove(a); Assert.That(modifiedType, Is.EqualTo(a.TypeId)); modifiedType = null; CheckContents(); a = Enumeration3; t.AddEnum(a, hidden); enums.Add(a); Assert.That(modifiedType, Is.EqualTo(a.TypeId)); modifiedType = null; CheckContents(); EnumerationData Enum2Replacement = new EnumerationData("repeat", Enumeration2.TypeId, new[] { new EnumerationData.Element("asd", Guid.Parse("24be3852-b34f-4f20-ab72-3e391e939872")) }); t.ModifyEnum(Enum2Replacement); enums[enums.IndexOf(Enumeration2)] = Enum2Replacement; Assert.That(modifiedType, Is.EqualTo(Enum2Replacement.TypeId)); modifiedType = null; CheckContents(); EnumerationData Enumeration3Replacement = new EnumerationData("enum3 replacement", Enumeration3.TypeId, new[] { new EnumerationData.Element("asd", Guid.Parse("27b59086-7e9b-4b7f-8796-a7a23eb727c1")), new EnumerationData.Element("sdasd", Guid.Parse("b08cf9e0-9d77-42cf-9f1c-a21def2b79d3")), new EnumerationData.Element("sdasd2", Guid.Parse("4f73eaad-86fe-4cbb-adbc-016724399ae5")) }); t.RenameType(Enumeration3.TypeId, Enumeration3Replacement.Name); enums[enums.IndexOf(Enumeration3)] = Enumeration3Replacement; Assert.That(modifiedType, Is.EqualTo(Enumeration3Replacement.TypeId)); modifiedType = null; CheckContents(); }
/// <summary> /// Fill the data source from all the data stored in all domain files /// </summary> /// <param name="domains">All the domain files used to populate the datasource</param> public ConversationDataSource(IEnumerable <DomainData> domains) { domains = domains.Evaluate(); //Types must be generated before Nodes and can be generated before NodeTypes foreach (var domain in domains) { foreach (var typeData in domain.DynamicEnumerations) { m_types.AddDynamicEnum(typeData.TypeID, (name, guid) => typeData.Make(name, guid)); } foreach (var typeData in domain.Enumerations) { IEnumeration enumeration = typeData.Make(); m_enumerations.Add(enumeration); m_types.AddEnum(enumeration.TypeId, enumeration.Parameter); } foreach (var typeData in domain.Decimals) { m_types.AddDecimal(typeData.TypeID, typeData.Make); } foreach (var typeData in domain.Integers) { m_types.AddInteger(typeData.TypeID, typeData.Make); } } //NodeTypes must be generated before Nodes and can be generated before Types. NodeTypes may have interdependencies between files var nodeTypeData = domains.SelectMany(d => d.NodeTypes).ToList(); var duplicates = nodeTypeData.GroupBy(a => a.Guid).Where(g => g.Count() > 1); if (duplicates.Any()) { throw new Exception("The following node types have duplicate definitions: " + string.Join(", ", duplicates.Select(g => g.Key).ToArray())); } List <NodeType> nodeTypes = new List <NodeType> { }; nodeTypes.Add(m_nodeHeirarchy); //foreach (var data in nodeTypeData.Where(d => d.Parent == DomainGUIDS.CATEGORY_NONE).ToList()) //{ // var newNodeType = new NodeType(data.Name, data.Guid); // m_nodes.m_childTypes.Add(newNodeType); // nodeTypes.Add(newNodeType); // nodeTypeData.Remove(data); //} bool gotOne = true; while (nodeTypeData.Any() && gotOne) { gotOne = false; for (int i = 0; i < nodeTypes.Count; i++) { var parent = nodeTypes[i]; foreach (var data in nodeTypeData.Where(d => d.Parent == parent.Guid).ToList()) { var newNodeType = new NodeType(data.Name, data.Guid); parent.m_childTypes.Add(newNodeType); nodeTypes.Add(newNodeType); gotOne = true; nodeTypeData.Remove(data); } } } if (!gotOne) { //TODO: How to express this to the user? //Do they even need to know? It may just be autoresolved //throw new Exception("The following node types are ancestors of an unknown node type: " + string.Join(", ", nodeTypeData.Select(d => d.Guid).ToArray())); MessageBox.Show("The following node types are ancestors of an unknown node type: " + string.Join(", ", nodeTypeData.Select(d => d.Guid).ToArray())); foreach (var orphan in nodeTypeData) { m_nodeHeirarchy.m_childTypes.Add(new NodeType(orphan.Name, orphan.Guid)); } } //Connectors must be generated after Types but before Nodes Dictionary <ID <TConnectorDefinition>, ConnectorDefinitionData> connectorDefinitions = new Dictionary <ID <TConnectorDefinition>, ConnectorDefinitionData>() { { SpecialConnectors.Output.Id, SpecialConnectors.Output }, { SpecialConnectors.Input.Id, SpecialConnectors.Input }, }; foreach (var domain in domains) { foreach (var connector in domain.Connectors) { connectorDefinitions[connector.Id] = connector; } } //Nodes must be generated after NodeTypes, Types and Connectors foreach (var domain in domains) { foreach (var node in domain.Nodes) { var name = node.Name; var guid = node.Guid; Func <NodeData.ConnectorData, Func <IEditable, Output> > processConnector = c => { Func <IEditable, List <Parameter>, Output> a = connectorDefinitions[c.TypeID].Make(c.Id, ConversationConnectionRules.Instance); return(data => a(data, c.Parameters)); }; IEnumerable <Func <IEditable, Output> > connectors = node.Connectors.Select(processConnector).Evaluate(); var parameters = node.Parameters.Select <NodeData.ParameterData, Func <Parameter> >(p => () => p.Make(m_types.Make)).Evaluate(); var config = node.Config.ToDictionary(b => b.Name, b => b.Value, StringComparer.OrdinalIgnoreCase); var parent = m_nodeHeirarchy.Collapse(x => x.m_childTypes, x => x.Only()).SingleOrDefault(x => x.Guid == node.Type) ?? m_nodeHeirarchy; var nodeGenerator = new GenericEditableGenerator(name, guid, config, (id, ng) => new ExternalFunction(ng, id, connectors, parameters.Select(b => b()).ToArray())); parent.m_nodes.Add(nodeGenerator); m_nodes[guid] = nodeGenerator; } } }