private static void CheckDecimals(List <DecimalData> decimals, TypeSet t, Action CheckContents, ref ParameterType modifiedType) { DecimalData Decimal1 = new DecimalData("decimal1", ParameterType.Parse("feea56b3-d51b-4c60-bb81-96c6e543e096"), 12, -1); DecimalData Decimal2 = new DecimalData("decimal2", ParameterType.Parse("1275ba4a-ff58-492c-ae6f-9e915eefb796"), 15, -1); DecimalData Decimal3 = new DecimalData("decimal3", ParameterType.Parse("729e3aa4-ce76-4dbd-95b8-549dbdec035a"), -123, -1231); var a = Decimal1; t.AddDecimal(a); decimals.Add(a); Assert.That(modifiedType, Is.EqualTo(a.TypeId)); modifiedType = null; CheckContents(); a = Decimal2; t.AddDecimal(a); decimals.Add(a); Assert.That(modifiedType, Is.EqualTo(a.TypeId)); modifiedType = null; CheckContents(); a = Decimal1; t.Remove(a.TypeId); decimals.Remove(a); Assert.That(modifiedType, Is.EqualTo(a.TypeId)); modifiedType = null; CheckContents(); a = Decimal3; t.AddDecimal(a); decimals.Add(a); Assert.That(modifiedType, Is.EqualTo(a.TypeId)); modifiedType = null; CheckContents(); DecimalData Decimal2Replacement = new DecimalData("decimal 2 replacement", ParameterType.Parse("1275ba4a-ff58-492c-ae6f-9e915eefb796"), 345, -345); t.ModifyDecimal(Decimal2Replacement); decimals[decimals.IndexOf(Decimal2)] = Decimal2Replacement; Assert.That(modifiedType, Is.EqualTo(Decimal2Replacement.TypeId)); modifiedType = null; CheckContents(); DecimalData Decimal3Replacement = new DecimalData("Decimal3Replaced", ParameterType.Parse("729e3aa4-ce76-4dbd-95b8-549dbdec035a"), -123, -1231); t.RenameType(Decimal3.TypeId, Decimal3Replacement.Name); decimals[decimals.IndexOf(Decimal3)] = Decimal3Replacement; Assert.That(modifiedType, Is.EqualTo(Decimal3Replacement.TypeId)); modifiedType = null; CheckContents(); }
public static TypeSet Make() { var result = new TypeSet(); result.AddInteger(BaseTypeInteger.Data); result.AddDecimal(BaseTypeDecimal.Data); result.AddLocalizedString(BaseTypeLocalizedString.Data); result.AddOther(StringParameter.ParameterType, "String", (name, id, def, document) => new StringParameter(name, id, def)); result.AddOther(BooleanParameter.ParameterType, "Boolean", (name, id, def, document) => new BooleanParameter(name, id, def)); result.AddOther(AudioParameter.ParameterType, "Audio", (name, id, def, document) => new AudioParameter(name, id)); return(result); }
/// <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; } } }