/// <summary> /// Adds connectors to the solution that exists in the graph but nor yet in the solution. /// </summary> /// <param name="repo"></param> /// <param name="problemSpace"></param> /// <returns></returns> public Unit InstantiateMissingSolutionConnectors() { Graph.TraverseEdgesBF((source, edge, target) => { var connectorData = from connectorSource in source.Instance from connectorTarget in target.Instance from stype in edge.GetStereotype(ADTechnology.Technologies.AD.ConnectorStereotypes) select Tuple.Create(connectorSource, connectorTarget, stype); connectorData.ForEach((connectorSource, connectorTarget, stype) => { var connectsAlternativeToProblem = stype == ConnectorStereotypes.AddressedBy && connectorSource is OptionOccurrence; var alreadyExisting = connectorSource.Connectors.Any(c => { return(c.Is(stype) && (c.EaObject.SupplierID == connectorTarget.Id || c.EaObject.ClientID == connectorTarget.Id)); }); if (!connectsAlternativeToProblem && !alreadyExisting) { Repo.Connect(connectorSource, connectorTarget, stype); } }); }); return(Unit.Instance); }
public void InstantiateSolutionConnectors(ModelEntityRepository repo) { var allInstantiations = AllInstantiations().Run(); // connections between new instances var connections = from instantiation in allInstantiations from source in instantiation.Instance from connector in instantiation.Element.Connectors where connector.EaObject.ClientID == instantiation.Element.Id from connectorStype in connector.GetStereotype(ADTechnology.Technologies.AD.ConnectorStereotypes) from targetInstantiation in allInstantiations where connector.EaObject.SupplierID == targetInstantiation.Element.Id from target in targetInstantiation.Instance select Tuple.Create(source, connectorStype, target); // connections from new instances to referenced elements var referenceConnectionsFrom = from instantiation in allInstantiations from instance in instantiation.Instance from connector in instantiation.Element.Connectors where connector.EaObject.ClientID == instantiation.Element.Id from target in connector.Target(repo.GetElement) where !target.Is(ProblemSpace.Problem) && !target.Is(ProblemSpace.Option) select Tuple.Create(instance, connector.ReconstructStereotype(), target); // connections from referenced elements to new instances var referenceConnectionsTo = from instantiation in allInstantiations from instance in instantiation.Instance from connector in instantiation.Element.Connectors where connector.EaObject.SupplierID == instantiation.Element.Id from source in connector.Source(repo.GetElement) where !source.Is(ProblemSpace.Problem) && !source.Is(ProblemSpace.Option) select Tuple.Create(source, connector.ReconstructStereotype(), instance); connections .Concat(referenceConnectionsFrom) .Concat(referenceConnectionsTo) .ForEach((source, connectorStype, target) => { try { repo.Connect(source, target, connectorStype); } catch (Exception) { // TODO: proper error handling } }); }