/// <summary> /// Returns true when there is a port of relationship elment one which is connected to a port /// of relationship element two /// </summary> /// <param name="rel"></param> /// <returns></returns> public bool RelationHasConnection(RelationshipElement rel) { // There is no simulationmodel if (!SimulationsModels.ContainsKey(rel.ValueFirst) || !SimulationsModels.ContainsKey(rel.ValueSecond)) { return(true); } SimulationModel firstSim = SimulationsModels[rel.ValueFirst]; SimulationModel secondSim = SimulationsModels[rel.ValueSecond]; // There are Relations which are not necassary if (!rel.IsCertainConnection || firstSim.Inputs.Count == 0 || secondSim.Inputs.Count == 0) { return(true); } // Checking if there is at least one connection if (hasConnectionToOtherValue(firstSim.Inputs, rel.ValueSecond) || hasConnectionToOtherValue(secondSim.Inputs, rel.ValueFirst) || hasConnectionToOtherValue(firstSim.PhysicalPorts, rel.ValueSecond)) { return(true); } return(false); }
/// <summary> /// Creates a new RelationshipElement by proccessing the given JToken and adds it to the given list. /// </summary> /// <param name="relationshipElements"></param> /// <param name="statement"></param> private static void createRelationshipElement(List <RelationshipElement> relationshipElements, JToken statement) { RelationshipElement relationshipElement = RelationshipElement.Parse(statement); relationshipElements.Add(relationshipElement); }
/// <summary> /// Checks the Datatypes of the connected In and Outputs and /// returns a list of strings with the names and /// the datatype of the in and output /// which are connected but do not share the same datatype. /// </summary> /// <param name="relationshipElement"></param> /// <param name="firstEle"></param> /// <param name="secondEle"></param> /// <returns></returns> public List <string> ReturnListWithMessageForDifferentDatatypes(RelationshipElement relationshipElement, string firstEle, string secondEle) { List <String> sameDatatype = new List <string>(); if (SimulationsModels.ContainsKey(firstEle) && SimulationsModels.ContainsKey(secondEle)) { foreach (var input in SimulationsModels[firstEle].Inputs.Concat(SimulationsModels[secondEle].Inputs)) { foreach (var connection in input.ConnectedTo) { if (!input.Datatype.Equals(connection.Datatype)) { sameDatatype.Add($"{input.IdShort}({input.Datatype})" + $"and {connection.IdShort}({connection.Datatype})" + $"are connected but do not share the same datatype"); } } } return(sameDatatype); } else { return(sameDatatype); } }
/// <summary> /// Compares the domains of the ports of the simulationmodels belonging to the given relationshiElement /// and connects if the domains are the same. /// If atleast one connetion is foudn true is returned. /// </summary> /// <param name="relationshipElement"></param> /// <param name="firstEle"></param> /// <param name="secondEle"></param> /// <param name="interfaceFirst"></param> /// <param name="interFaceSecond"></param> /// <returns></returns> public bool CheckCompatibleDomainsAndConnect(RelationshipElement relationshipElement, string firstEle, string secondEle, string interfaceFirst, string interFaceSecond) { if (SimulationsModels.ContainsKey(firstEle) && SimulationsModels.ContainsKey(secondEle)) { bool foundConnection = false; // Holen der Liste der Input Ports von ele1 List <IOput> inputsFirst = SimulationsModels[firstEle].GetInputsWithInterfaceName(interfaceFirst); // Hohlen der Liste der Input Ports von ele2 List <IOput> inputsSecond = SimulationsModels[secondEle].GetInputsWithInterfaceName(interFaceSecond); // Holen der Outputs von ele1 List <IOput> outputsFirst = SimulationsModels[firstEle].GetOutputsWithInterfaceName(interfaceFirst); // Holen der Outputs von ele2 List <IOput> outputsSecond = SimulationsModels[secondEle].GetOutputsWithInterfaceName(interFaceSecond); List <IOput> physicalFirst = SimulationsModels[firstEle].GetPhysicalPortsWithInterfaceName(interfaceFirst); List <IOput> physicalSecond = SimulationsModels[secondEle].GetPhysicalPortsWithInterfaceName(interFaceSecond); foundConnection = connectInputsAndOutputsByDomain(physicalFirst, physicalSecond); foundConnection = connectInputsAndOutputsByDomain(inputsFirst, outputsSecond) || foundConnection; foundConnection = connectInputsAndOutputsByDomain(inputsSecond, outputsFirst) || foundConnection; // Erstellen einer Liste, welche die Verbindungen enthält return(foundConnection); } else { return(false); } }
public static RelationshipElement Parse(JToken statement) { RelationshipElement relationshipElement = new RelationshipElement(); relationshipElement.IsCertainConnection = true; JToken locTokenFirst = statement.SelectToken("first.keys(0).value"); if (locTokenFirst != null) { relationshipElement.FirstAssetId = locTokenFirst.ToString(); } JToken locTokenSecond = statement.SelectToken("second.keys(0).value"); if (locTokenSecond != null) { relationshipElement.SecondAssetId = locTokenSecond.ToString(); } relationshipElement.SetValuesAccordingToAsset(); relationshipElement.FirstInterface = relationshipElement.ValueFirst + ((string)statement.SelectToken("first.keys(2).value")); relationshipElement.SecondInterface = relationshipElement.ValueSecond + ((string)statement.SelectToken("second.keys(2).value")); relationshipElement.IdShort = (string)statement.SelectToken("idShort"); if (relationshipElement.ValueFirst == null || relationshipElement.ValueSecond == null) { return(null); } return(relationshipElement); }
/// <summary> /// Parses the JToken into a RelationshipElement and returns the new created RelationshipElement /// </summary> /// <param name="valueFirst"></param> /// <param name="valueSecond"></param> /// <param name="idShort"></param> /// <param name="ReferenceToAsset"></param> /// <param name="interfaceFirst"></param> /// <param name="interfaceSecond"></param> /// <returns></returns> public static RelationshipElement Parse(string valueFirst, string valueSecond, string idShort, Dictionary <string, string> ReferenceToAsset, string interfaceFirst = null, string interfaceSecond = null) { RelationshipElement relationship = new RelationshipElement(); relationship.ValueFirst = valueFirst; relationship.ValueSecond = valueSecond; if (ReferenceToAsset.ContainsKey(relationship.ValueFirst)) { relationship.FirstAssetId = ReferenceToAsset[relationship.ValueFirst]; } if (ReferenceToAsset.ContainsKey(relationship.ValueSecond)) { relationship.SecondAssetId = ReferenceToAsset[relationship.ValueSecond]; } relationship.SetValuesAccordingToAsset(); relationship.IdShort = idShort; relationship.FirstInterface = interfaceFirst; relationship.SecondInterface = interfaceSecond; return(relationship); }
/// <summary> /// Checks the EClass ids of all connected in and output ports /// If they are not compatible the connection gets removed /// Returns a list of strings with the name, eclass id and /// unit of the in and output ports of all removed connections /// </summary> /// <param name="relationshipElement"></param> /// <param name="firstEle"></param> /// <param name="secondEle"></param> /// <returns></returns> public List <string> CheckeClassConnectionAndRemoveIncompatible(RelationshipElement relationshipElement, string firstEle, string secondEle) { EClass eClass = new EClass(); List <string> changed = new List <string>(); if (SimulationsModels.ContainsKey(firstEle) && SimulationsModels.ContainsKey(secondEle)) { foreach (var input in SimulationsModels[firstEle].Inputs.Concat(SimulationsModels[secondEle].Inputs)) { for (int i = input.ConnectedTo.Count - 1; i >= 0; i--) { var connection = input.ConnectedTo[i]; if (SimulationsModels[input.Owner].Mappings.Count != 0) { Console.WriteLine("---Mappings of " + input.Owner); foreach (var map in SimulationsModels[input.Owner].Mappings.Values) { Console.WriteLine(map.BasicId + " " + map.UnknownId); } } // Search for compatible Eclass IDs if (EClass.CheckEClassConnection(input.EclassID, connection.EclassID) || checkForMapping(input, connection, eClass)) { } // Not Compatible Eclass ids and connection gets removed. else { input.RemoveConnection(connection); changed.Add(input.IdShort + $"({input.EclassID})({input.Unit}) and " + connection.IdShort + $"({connection.EclassID})({connection.Unit})" + $"are connected but do not have compatible Eclass ID"); } } } } return(changed); }