コード例 #1
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);
        }
コード例 #2
0
ファイル: MetaAvmProject.cs プロジェクト: neemask/meta-core
        public void 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.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 (StreamWriter writer = new StreamWriter(jsonFileName))
            {
                writer.WriteLine(JsonConvert.SerializeObject(
                    metaTestBench,
                    Newtonsoft.Json.Formatting.Indented,
                    new JsonSerializerSettings()
                    {
                        PreserveReferencesHandling = PreserveReferencesHandling.Objects,
                    }));
            }
        }