Ejemplo n.º 1
0
        private void GetIDsOfEverything(MgaFCO testbench)
        {
            Queue <MgaFCO> q = new Queue <MgaFCO>();

            q.Enqueue(testbench);
            var metaProject         = testbench.Meta.MetaProject;
            int componentRefId      = metaProject.RootFolder.GetDefinedFCOByNameDisp("ComponentRef", true).MetaRef;
            int componentId         = metaProject.RootFolder.GetDefinedFCOByNameDisp("Component", true).MetaRef;
            int testComponentId     = -1; // TODO //metaProject.RootFolder.GetDefinedFCOByNameDisp("TestComponent", true).MetaRef;
            int testBenchId         = metaProject.RootFolder.GetDefinedFCOByNameDisp("TestBench", true).MetaRef;
            int componentAssemblyId = metaProject.RootFolder.GetDefinedFCOByNameDisp("ComponentAssembly", true).MetaRef;
            int connectorId         = metaProject.RootFolder.GetDefinedFCOByNameDisp("Connector", true).MetaRef;

            Action <IMgaFCO> addComponentID = (fco) =>
            {
                mgaIdToDomainIDs[fco.ID] = new IDs()
                {
                    instanceGUID = (fco.Meta.Name == typeof(Tonka.Component).Name) ? fco.GetStrAttrByNameDisp("InstanceGUID") : null, // TestComponents do not have InstanceGUIDs
                    managedGUID  = fco.GetStrAttrByNameDisp("ManagedGUID")
                                                                                                                                      // ID = fco.GetIntAttrByNameDisp("ID").ToString()
                };
            };
            Action <IMgaFCO> addComponentRefID = (fco) =>
            {
                mgaIdToDomainIDs[fco.ID] = new IDs()
                {
                    instanceGUID = fco.GetStrAttrByNameDisp("InstanceGUID"),
                    // managedGUID
                    ID = fco.GetIntAttrByNameDisp("ID").ToString()
                };
            };
            Action <IMgaFCO> addComponentAssemblyID = (fco) =>
            {
                mgaIdToDomainIDs[fco.ID] = new IDs()
                {
                    // instanceGUID =
                    managedGUID = fco.GetStrAttrByNameDisp("ManagedGUID"),
                    ID          = fco.GetIntAttrByNameDisp("ID").ToString()
                };
            };

            while (q.Count > 0)
            {
                MgaFCO fco = q.Dequeue();
                if (fco.Meta.ObjType == GME.MGA.Meta.objtype_enum.OBJTYPE_REFERENCE)
                {
                    var reference = (MgaReference)fco;
                    var referred  = reference.Referred;
                    if (referred != null)
                    {
                        if (referred.Meta.MetaRef == componentAssemblyId)
                        {
                            if (reference.Meta.MetaRef == componentRefId)
                            {
                                addComponentRefID(reference);
                            }
                            else
                            {
                                addComponentAssemblyID(referred);
                            }
                            foreach (MgaFCO child in ((MgaModel)referred).ChildFCOs)
                            {
                                q.Enqueue(child);
                            }
                        }
                        else if (referred.Meta.MetaRef == componentId || referred.Meta.MetaRef == testComponentId)
                        {
                            addComponentRefID(reference);
                            foreach (MgaFCO child in ((MgaModel)referred).ChildFCOs)
                            {
                                q.Enqueue(child);
                            }
                        }
                    }
                }
                else if (fco.Meta.MetaRef == componentAssemblyId)
                {
                    addComponentAssemblyID(fco);
                    foreach (MgaFCO child in ((MgaModel)fco).ChildFCOs)
                    {
                        q.Enqueue(child);
                    }
                }
                else if (fco.Meta.MetaRef == testBenchId)
                {
                    foreach (MgaFCO child in ((MgaModel)fco).ChildFCOs)
                    {
                        q.Enqueue(child);
                    }
                }
                else if (fco.Meta.MetaRef == connectorId)
                {
                    foreach (MgaFCO child in ((MgaModel)fco).ChildFCOs)
                    {
                        if (child.Meta.Name == "SchematicModelPort")
                        {
                            mgaIdToDomainIDs[child.ID] = new IDs()
                            {
                                // instanceGUID =
                                // managedGUID =
                                ID          = child.GetStrAttrByNameDisp("ID"),
                                ConnectorID = fco.GetStrAttrByNameDisp("ID")
                            };
                        }
                    }
                }
                else if (fco.Meta.MetaRef == componentId || fco.Meta.MetaRef == testComponentId)
                {
                    addComponentID(fco);
                }
            }
        }
Ejemplo n.º 2
0
        public string UpdateTestBenchJson(MgaFCO testBench)
        {
            string testBenchPath = Path.Combine(
                Path.GetDirectoryName(this.m_filename),
                "test-benches");

            if (Directory.Exists(testBenchPath) == false)
            {
                Directory.CreateDirectory(testBenchPath);
            }

            string jsonFileName = Path.GetFullPath(Path.Combine(
                                                       testBenchPath,
                                                       testBench.Name + ".testbench.json"));

            AVM.DDP.MetaTestBench metaTestBench = new AVM.DDP.MetaTestBench();
            metaTestBench.Name = testBench.Name;

            Dictionary <MgaFCO, AVM.DDP.MetaTestBench.Requirement> reqMap =
                new Dictionary <MgaFCO, AVM.DDP.MetaTestBench.Requirement>();

            Dictionary <MgaFCO, AVM.DDP.MetaTestBench.Metric> metricMap =
                new Dictionary <MgaFCO, AVM.DDP.MetaTestBench.Metric>();

            // TODO: metrics, parameters, requirements
            foreach (MgaFCO item in testBench.ChildObjects)
            {
                if (item.Meta.Name == typeof(CyPhy.Parameter).Name)
                {
                    AVM.DDP.MetaTestBench.Parameter p = new AVM.DDP.MetaTestBench.Parameter();
                    p.Name  = item.Name;
                    p.Value = item.GetStrAttrByNameDisp("Value");

                    p.Unit = (item as MgaReference).Referred != null ?
                             (item as MgaReference).Referred.Name :
                             "";

                    metaTestBench.Parameters.Add(p);
                }
                else if (item.Meta.Name == typeof(CyPhy.Metric).Name)
                {
                    AVM.DDP.MetaTestBench.Metric m = new AVM.DDP.MetaTestBench.Metric();
                    m.Name  = item.Name;
                    m.Value = null;

                    m.Unit = (item as MgaReference).Referred != null ?
                             (item as MgaReference).Referred.Name :
                             "";

                    metaTestBench.Metrics.Add(m);
                    metricMap.Add(item, m);
                }
                else if (item.Meta.Name == typeof(CyPhy.RequirementLinkRef).Name)
                {
                    MgaFCO requirement = (item as MgaReference).Referred;
                    if (requirement != null)
                    {
                        AVM.DDP.MetaTestBench.Requirement r = new AVM.DDP.MetaTestBench.Requirement();
                        r.Name             = requirement.Name;
                        r.SourceRepository = requirement.GetStrAttrByNameDisp("SourceRepository");
                        r.ID   = requirement.GetStrAttrByNameDisp("ID");
                        r.Text = requirement.GetStrAttrByNameDisp("Text");

                        metaTestBench.Requirements.Add(r);
                        reqMap.Add(item, r);
                    }
                }
            }

            // HACK: for testing only!
            metaTestBench.Metrics.ForEach(x => x.Requirement = metaTestBench.Requirements.FirstOrDefault());

            foreach (IMgaFCO item in testBench.ChildObjects)
            {
                // TODO: Metric2Requirement Link connection
            }

            using (new MutexWrapper(jsonFileName))
            {
                using (StreamWriter writer = new StreamWriter(jsonFileName))
                {
                    writer.WriteLine(JsonConvert.SerializeObject(
                                         metaTestBench,
                                         Newtonsoft.Json.Formatting.Indented,
                                         new JsonSerializerSettings()
                    {
                        PreserveReferencesHandling = PreserveReferencesHandling.Objects,
                    }));
                }
            }

            return(jsonFileName);
        }
Ejemplo n.º 3
0
        public void Initialize(
            MgaProject project,
            MgaMetaPart meta,
            MgaFCO obj)
        {
            // only store temporarily, they might be unavailable later
            myobj     = obj;
            mymetaobj = null;
            FCOKind   = myobj?.Meta?.Name;
            MetaKind  = meta.Name;

            // obtain the metaobject
            GetMetaFCO(meta, out mymetaobj);

            if (obj != null)
            {
                // concrete object
                name = myobj.Name;
                if (myobj.Meta.Name == "Task")
                {
                    // task
                    // get progid check whether it is already in the cache
                    TaskProgId = myobj.StrAttrByName["COMName"];
                    if (interpreters.Keys.Contains(TaskProgId) == false)
                    {
                        // create an instance
                        ComComponent task = new ComComponent(TaskProgId);
                        interpreters.Add(TaskProgId, task);
                    }
                    // save parameters
                    Parameters = myobj.StrAttrByName["Parameters"];
                    h          = IconHeight;
                    w          = IconWidth;
                }
                else if (myobj.Meta.Name == "WorkflowRef")
                {
                    // Workflow reference get the tasks
                    // TODO: get those in the right order
                    workflow.Clear();
                    MgaReference   wfRef     = myobj as MgaReference;
                    Queue <string> items     = new Queue <string>();
                    List <MgaAtom> tasks     = new List <MgaAtom>();
                    List <MgaFCO>  processed = new List <MgaFCO>();

                    if (wfRef.Referred != null)
                    {
                        HashSet <string> taskKinds = new HashSet <string>()
                        {
                            "ExecutionTask",
                            "Task"
                        };
                        tasks.AddRange(wfRef.Referred.ChildObjects.OfType <MgaAtom>().Where(atom => taskKinds.Contains(atom.Meta.Name)));

                        MgaAtom StartTask = null;

                        StartTask = tasks.
                                    Where(x => x.ExSrcFcos().Count() == 0).
                                    FirstOrDefault();

                        if (StartTask != null)
                        {
                            this.EnqueueTask(StartTask as MgaFCO);
                            processed.Add(StartTask as MgaFCO);

                            MgaFCO NextTask = StartTask.ExDstFcos().FirstOrDefault();

                            // avoid loops
                            while (NextTask != null &&
                                   processed.Contains(NextTask) == false)
                            {
                                processed.Add(NextTask as MgaFCO);
                                this.EnqueueTask(NextTask);
                                NextTask = NextTask.ExDstFcos().FirstOrDefault();
                            }
                        }
                    }
                    h = IconHeight;
                    if (workflow.Count > 0)
                    {
                        w = IconWidth * workflow.Count +
                            TaskPadding * (workflow.Count - 1);
                    }
                    else
                    {
                        w = IconWidth;
                    }
                }
                else if (myobj.Meta.Name == "MetricConstraint")
                {
                    h = 40;
                    w = 40;
                    MetricConstraint_TargetType = myobj.GetStrAttrByNameDisp("TargetType");
                }
            }
            else
            {
                // not a concreter object (maybe in part browser?)
                name = mymetaobj.DisplayedName;
                h    = IconHeight;
                w    = IconWidth;
                if (MetaKind == "MetricConstraint")
                {
                    h = 40;
                    w = 40;
                }
            }

            // to handle color and labelColor settings in GME
            if (!GetColorPreference(out color, "color"))
            {
                color = Color.Black;
            }
            if (!GetColorPreference(out labelColor, "nameColor"))
            {
                labelColor = Color.Black;
            }

            // null them for sure
            // myobj = null;
            mymetaobj = null;
        }