private IEnumerable <Usage> ConnectedNodesUsages(IConversationNode node) { HashSet <Id <NodeTypeTemp> > nodeIds = new HashSet <Id <NodeTypeTemp> >(); nodeIds.UnionWith(node.Data.Connectors.SelectMany(t => t.Connections).Select(t => t.Parent).Where(n => n.NodeTypeId == DomainIDs.NodeGuid).Select(n => Id <NodeTypeTemp> .ConvertFrom(n.NodeId))); return(NodeDefinitionsUsages(nodeIds)); }
/// <summary> /// Is this node the connector part of a node definition /// </summary> private bool IsConnector(IConversationNode node) { return(m_project.DomainDataSource.IsConnector(node.Data.NodeTypeId)); }
public override IEnumerable <Usage> Usages(IConversationNode node) { /* * Category * * Integer * Decimal * Dynamic Enumeration * Enumeration * Localized String * * Enumeration Value * * Connector Definition * Connection Definition * * Integer Parameter * Decimal Parameter * String Parameter * Localized String Parameter * Boolean Parameter * Audio Parameter * Enumeration Parameter * Dynamic Enumeration Parameter * * Input * Output * Custom Connectors* * * Node */ Id <NodeTypeTemp> id = node.Data.NodeTypeId; BaseType type = BaseType.BaseTypes.SingleOrDefault(t => t.NodeType == id); //It's a category if (id == DomainIDs.CategoryGuid) { return(CategoryUsage(node.Data.NodeId)); } //It's a type definition else if (type != null) { return(DerivedTypeUsage(node.Data.NodeId, type)); } //It's an enum value defintion (i.e. part of a type definition but also usable as a default value else if (id == DomainIDs.EnumerationValueDeclaration) { return(EnumerationValueUsage(node)); } //It's a connector definition used to define custom connectors else if (id == DomainIDs.ConnectorDefinitionGuid) { return(ConnectorDefinitionsUsages(Id <TConnectorDefinition> .ConvertFrom(node.Data.NodeId).Only())); } else if (id == DomainIDs.ConnectionDefinitionGuid) { return(ConnectionDefinitionUsages(node.Data)); } //It's a parameter else if (BaseType.BaseTypes.Any(t => t.ParameterNodeType == id)) { var connectors = ConnectorDefinitionsUsages(node.Data.Connectors.SelectMany(t => t.Connections).Select(t => t.Parent).Where(n => n.NodeTypeId == DomainIDs.ConnectorDefinitionGuid).Select(a => Id <TConnectorDefinition> .ConvertFrom(a.NodeId))); var nodes = ConnectedNodesUsages(node); return(connectors.Concat(nodes)); } //It's a connector part of a node definition else if (IsConnector(node)) { return(ConnectedNodesUsages(node)); } //It's a plain old node definition else if (id == DomainIDs.NodeGuid) { return(NodeDefinitionsUsages(Id <NodeTypeTemp> .ConvertFrom(node.Data.NodeId).Only())); } else { //This node is of a type unknown to the domain domain (i.e. it's presumably in the conversation domain) return(Enumerable.Empty <Usage>()); } }
public abstract IEnumerable <Usage> Usages(IConversationNode node);
/// <summary> /// All usages of enumeration value. Usages can take two forms: /// 1. Conversation nodes which have parameters for which the user has selected this value /// 2. Domain parameter nodes for which the user has selected this value as the default /// </summary> /// <param name="node">The node declaring the enumeration value</param> private IEnumerable <Usage> EnumerationValueUsage(IConversationNode node) { List <Usage> result = new List <Usage>(); //Find all the enum declarations for which this is a value var enumDeclarationNodes = node.Data.Connectors.SelectMany(t => t.Connections).Select(t => t.Parent).Where(n => n.NodeTypeId == BaseType.Enumeration.NodeType); foreach (var enumDeclarationNode in enumDeclarationNodes) { var enumTypeID = enumDeclarationNode.NodeId; //All the nodes in the conversation that have parameters with this value foreach (var conversationFile in m_project.Conversations) { foreach (var n in conversationFile.Nodes) { var parameters = n.Data.Parameters; var filteredEnumParameters = parameters.Where(p => p.TypeId == ParameterType.Basic.ConvertFrom(enumTypeID)).Cast <IEnumParameter>(); var filteredSetParameters = parameters.Where(p => p.TypeId == ParameterType.ValueSetType.ConvertFrom(enumTypeID)).Cast <ISetParameter>(); var usingEnumParameters = filteredEnumParameters.Where(p => p.Value == node.Data.NodeId.Guid); foreach (var p in usingEnumParameters) { result.Add(new Usage(n, conversationFile, "Node " + n.Data.Name + " with Enum parameter " + p.Name)); } var usingSetParameters = filteredSetParameters.Where(p => p.Value.Contains(node.Data.NodeId.Guid)); foreach (var p in usingSetParameters) { result.Add(new Usage(n, conversationFile, "Node " + n.Data.Name + " with Set parameter " + p.Name)); } } } //All parameters in the domain for which this is the default value foreach (var domainFile in m_project.DomainFiles) { foreach (var n in domainFile.Nodes) { if (n.Data.NodeTypeId == BaseType.Enumeration.ParameterNodeType) { var typeParameter = n.Data.Parameters.Single(p => p.Id == DomainIDs.PARAMETER_TYPE) as IEnumParameter; if (typeParameter.Value == enumTypeID.Guid) { var defaultParameter = n.Data.Parameters.Single(p => p.Id == DomainIDs.ParameterDefault) as IDynamicEnumParameter; var expectedValue = (node.Data.Parameters.Single(p => p.Id == DomainIDs.EnumerationValueParameter) as IStringParameter).Value; if (defaultParameter.Value == expectedValue) { result.Add(new Usage(n, domainFile, "Enum parameter definition " + n.Data.Parameters.Where(x => x.Id == DomainIDs.ParameterName).Single().ValueAsString() + " default value")); } } } if (n.Data.NodeTypeId == BaseType.Set.ParameterNodeType) { var typeParameter = n.Data.Parameters.Single(p => p.Id == DomainIDs.PARAMETER_TYPE) as IEnumParameter; if (typeParameter.Value == enumTypeID.Guid) { var defaultParameter = n.Data.Parameters.Single(p => p.Id == DomainIDs.ParameterDefault) as ISetParameter; var expectedValue = node.Data.NodeId; if (defaultParameter.Value.Contains(expectedValue.Guid)) { result.Add(new Usage(n, domainFile, "Set parameter definition " + n.Data.Parameters.Where(x => x.Id == DomainIDs.ParameterName).Single().ValueAsString() + " default value")); } } } } } } return(result); }