示例#1
0
        /// <summary>
        /// Connects the ports of the inputs list with the ports of the outputs list in case the domains are the same.
        /// Returns true in case at least one connection is found.
        /// </summary>
        /// <param name="inputs"></param>
        /// <param name="outputs"></param>
        /// <returns></returns>
        private bool connectInputsAndOutputsByDomain(List <IOput> inputs, List <IOput> outputs)
        {
            bool foundConnection = false;

            foreach (var input in inputs)
            {
                foreach (var output in outputs)
                {
                    if (input.Domain.Equals(output.Domain))
                    {
                        if (output.IsPhysical)
                        {
                            if (EClass.CheckEClassConnection(output.EclassID, input.EclassID) ||
                                EClass.CheckEClassConnection(input.EclassID, output.EclassID))
                            {
                                output.AddPhysicalConnection(input);
                                foundConnection = true;
                            }
                        }
                        else
                        {
                            input.AddConnection(output);

                            foundConnection = true;
                        }
                    }
                }
            }
            return(foundConnection);
        }
示例#2
0
        public bool CreateSMD(string host, string machine)
        {
            if (SemanticPort.GetInstance() == null)
            {
                logs.Enqueue("Missing semantic ID csv");
                Console.WriteLine("Missing semantic ID csv");
            }
            else
            {
                if (EClass.InitEclass(logs) && SemanticPort.GetInstance() != null)
                {
                    try
                    {
                        if (exporter.CreateSMD(host, machine))
                        {
                            List <SimulationModel> noFmu = exporter.GetSimulationModelsWithoutFMU();
                            foreach (var sim in noFmu)
                            {
                                Console.WriteLine($"SimulationModel {sim.Name} has no Fmu");
                                Console.WriteLine();
                                logs.Enqueue($"SimulationModel {sim.Name} has no Fmu");
                                logs.Enqueue("");
                            }

                            foreach (var warning in SimulationModel.Warnings)
                            {
                                Console.WriteLine(warning);
                                logs.Enqueue(warning);
                            }
                        }
                        else
                        {
                            Console.WriteLine($"Could not find or read {machine}." +
                                              $" Please check the name of the AAS and structure of the aasx");
                            logs.Enqueue($"Could not find or read {machine}." +
                                         $" Please check the name of the AAS and structure of the aasx");
                            return(false);
                        }
                    }
                    catch (AggregateException e)
                    {
                        print("No Connection:" + e.Message);
                        Console.WriteLine();
                        logs.Enqueue("No Connection:" + e.Message);
                        logs.Enqueue("");
                        return(false);
                    }

                    return(true);
                }
                else
                {
                    Console.WriteLine("No mappings.csv found or does not contain all rows");
                    logs.Enqueue("No mappings.csv found or does not contain all rows");
                    return(false);
                }
            }
            return(false);
        }
示例#3
0
        /// <summary>
        /// Sets the eclass id
        /// </summary>
        /// <param name="value_IO"></param>
        public void SetEClass(JToken value_IO)
        {
            JToken locToken = value_IO.SelectToken("semanticId.keys[0].value");

            if (locToken != null)
            {
                this.EclassID = locToken.ToString();
                this.Unit     = EClass.GetUnitForEclassId(this.EclassID);
            }
            else
            {
                EclassID = "";
            }
        }
示例#4
0
        /// <summary>
        /// Checks for mappings for the in or output port and returns true in case there is a mapping.
        /// </summary>
        /// <param name="input"></param>
        /// <param name="output"></param>
        /// <param name="eClass"></param>
        /// <returns></returns>
        private bool checkForMapping(IOput input, IOput output, EClass eClass)
        {
            SimulationModel simulationModel = SimulationsModels[input.Owner];
            bool            result          = simulationModel.Mappings.ContainsKey(input.EclassID) &&
                                              EClass.CheckEClassConnection(simulationModel.Mappings[input.EclassID].BasicId, output.EclassID);

            // Check output ports only if mapping was not already found in input ports
            if (result == false)
            {
                simulationModel = SimulationsModels[output.Owner];
                result          = simulationModel.Mappings.ContainsKey(output.EclassID) &&
                                  EClass.CheckEClassConnection(input.EclassID, simulationModel.Mappings[output.EclassID].BasicId);
            }
            return(result);
        }
示例#5
0
        /// <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);
        }
示例#6
0
        /// <summary>
        /// Initializes all necessary dictionaries and in case of success returns true.
        /// </summary>
        /// <returns></returns>
        public static bool InitEclass(Queue <string> log)
        {
            InputEclassIds  = new Dictionary <string, EClass>();
            OutputEclassIds = new Dictionary <string, EClass>();
            PortEclassIds   = new Dictionary <string, EClass>();

            foreach (var pair in IdTables.InputEclassUnits)
            {
                EClass eClassIn = new EClass();
                eClassIn.Id   = pair.Key;
                eClassIn.Unit = pair.Value;

                InputEclassIds.Add(eClassIn.Id, eClassIn);

                if (!PortEclassIds.ContainsKey(eClassIn.Id))
                {
                    PortEclassIds.Add(eClassIn.Id.Trim(), eClassIn);
                }
            }

            foreach (var pair in IdTables.OutputEclassUnits)
            {
                EClass eClassOut = new EClass();
                eClassOut.Id = pair.Key;
                if (!eClassOut.Id.Equals("") && !eClassOut.Id.Equals("?"))
                {
                    eClassOut.Unit = pair.Value;
                    OutputEclassIds.Add(eClassOut.Id, eClassOut);

                    if (!PortEclassIds.ContainsKey(eClassOut.Id))
                    {
                        PortEclassIds.Add(eClassOut.Id.Trim(), eClassOut);
                    }
                }
            }
            return(true);
        }