示例#1
0
        /// <summary>
        /// Call this within a transaction.
        /// </summary>
        /// <param name="originalSubject"></param>
        /// <param name="singleFco"></param>
        /// <param name="OutputSubDir"></param>
        public void UpdateResultsJson(
            MgaFCO singleFco,
            string OutputSubDir,
            DateTime time)
        {
            string jsonFile = Path.GetFullPath(Path.Combine(this.GetResultsFolder(), "results.metaresults.json"));

            AVM.DDP.MetaResults results = null;
            using (new MutexWrapper(jsonFile))
            {
                if (File.Exists(jsonFile))
                {
                    string content = "";
                    using (StreamReader reader = new StreamReader(jsonFile))
                    {
                        content = reader.ReadToEnd();
                    }

                    try
                    {
                        results = JsonConvert.DeserializeObject <AVM.DDP.MetaResults>(content);
                    }
                    catch (Newtonsoft.Json.JsonReaderException ex)
                    {
                        // Will this cause problems if we run it from the job manager??? Should we only log it istead?
                        throw new Exception(string.Format("{0} file is probably malformed. Not a valid json. {1}{2}", Path.GetFullPath(jsonFile), Environment.NewLine, ex.Message));
                    }

                    // TODO: remove broken links
                }
                else
                {
                    results = new AVM.DDP.MetaResults();
                }

                AVM.DDP.MetaResults.Result thisResult = new AVM.DDP.MetaResults.Result();

                thisResult.Summary = MakeRelativePath(
                    Path.GetDirectoryName(jsonFile),
                    Path.Combine(OutputSubDir, AVM.DDP.MetaTBManifest.TESTBENCH_FILENAME)).Replace('\\', '/');

                thisResult.Time = time.ToString("yyyy-MM-dd HH-mm-ss");

                if (string.IsNullOrWhiteSpace(singleFco.RegistryValue["TestBenchUniqueName"]) == false)
                {
                    thisResult.TestBench = singleFco.RegistryValue["TestBenchUniqueName"] + ".testbench.json";
                }

                Func <MgaFCO, CyPhy.TestBenchType> cast;
                if (TestbenchAndCompositeTypes.TryGetValue(singleFco.Meta.Name, out cast) && cast(singleFco) != null)
                {
                    CyPhy.TestBenchType testBench = cast(singleFco);

                    var tlsut = testBench.Children.TopLevelSystemUnderTestCollection.FirstOrDefault();
                    if (tlsut != null)
                    {
                        if (tlsut.AllReferred is CyPhy.ComponentAssembly)
                        {
                            var cfg = tlsut.Referred.ComponentAssembly;
                            //thisResult.Design = cfg.Name + ".metadesign.json";

                            var cid = cfg.Attributes.ConfigurationUniqueID;
                            //this.ConfigurationUniqueID = cid;

                            if (string.IsNullOrWhiteSpace(cid))
                            {
                                cid = Guid.NewGuid().ToString("B");
                                cfg.Attributes.ConfigurationUniqueID = cid;
                            }

                            if (!string.IsNullOrEmpty(cid))
                            {
                                try
                                {
                                    Guid guid = new Guid(cid);
                                    thisResult.DesignID = guid.ToString("B");
                                }
                                catch (System.FormatException ex)
                                {
                                    Trace.TraceError("{0} is not a vaild GUID.", cid);
                                    Trace.TraceError(ex.ToString());
                                }
                            }
                        }
                    }
                }

                results.Results.Add(thisResult);

                var dirname = Path.GetDirectoryName(jsonFile);
                if (Directory.Exists(dirname) == false)
                {
                    Directory.CreateDirectory(dirname);
                }

                using (StreamWriter writer = new StreamWriter(jsonFile))
                {
                    writer.WriteLine(JsonConvert.SerializeObject(results, Newtonsoft.Json.Formatting.Indented));
                }
            }
        }
示例#2
0
        /// <summary>
        /// Call this within a transaction.
        /// </summary>
        /// <param name="originalSubject"></param>
        /// <param name="singleFco"></param>
        /// <param name="OutputSubDir"></param>
        public void UpdateResultsJson(
            MgaFCO singleFco,
            string OutputSubDir)
        {
            string jsonFile = Path.Combine(this.GetResultsFolder(), "results.metaresults.json");
            AVM.DDP.MetaResults results = null;
            bool createdNew;
            using (System.Threading.Mutex jsonFileMutex = new System.Threading.Mutex(false, "results_metaresults_mutex", out createdNew))
            {
                jsonFileMutex.WaitOne();
                try
                {
                    if (File.Exists(jsonFile))
                    {
                        string content = "";
                        using (StreamReader reader = new StreamReader(jsonFile))
                        {
                            content = reader.ReadToEnd();
                        }

                        try
                        {
                            results = JsonConvert.DeserializeObject<AVM.DDP.MetaResults>(content);
                        }
                        catch (Newtonsoft.Json.JsonReaderException ex)
                        {
                            // Will this cause problems if we run it from the job manager??? Should we only log it istead?
                            throw new Exception(string.Format("{0} file is probably malformed. Not a valid json. {1}{2}", Path.GetFullPath(jsonFile), Environment.NewLine, ex.Message));
                        }

                        // TODO: remove broken links
                    }
                    else
                    {
                        results = new AVM.DDP.MetaResults();
                    }

                    AVM.DDP.MetaResults.Result thisResult = new AVM.DDP.MetaResults.Result();

                    thisResult.Summary = MakeRelativePath(
                        Path.GetDirectoryName(jsonFile),
                        Path.Combine(OutputSubDir, AVM.DDP.MetaTBManifest.TESTBENCH_FILENAME)).Replace('\\', '/');

                    thisResult.Time = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");

                    thisResult.TestBench = singleFco.RegistryValue["TestBenchUniqueName"] + ".testbench.json";

                    Func<MgaFCO, CyPhy.TestBenchType> cast;
                    if (TestbenchAndCompositeTypes.TryGetValue(singleFco.Meta.Name, out cast))
                    {
                        CyPhy.TestBenchType testBench = cast(singleFco);

                        var tlsut = testBench.Children.TopLevelSystemUnderTestCollection.FirstOrDefault();
                        if (tlsut != null)
                        {
                            if (tlsut.AllReferred is CyPhy.ComponentAssembly)
                            {
                                var cfg = tlsut.Referred.ComponentAssembly;

                                var cid = cfg.Attributes.ConfigurationUniqueID;
                                //this.ConfigurationUniqueID = cid;

                                if (string.IsNullOrWhiteSpace(cid))
                                {
                                    cid = Guid.NewGuid().ToString("B");
                                    cfg.Attributes.ConfigurationUniqueID = cid;
                                }

                                if (!string.IsNullOrEmpty(cid))
                                {
                                    try
                                    {
                                        Guid guid = new Guid(cid);
                                        thisResult.DesignID = guid.ToString("B");
                                    }
                                    catch (System.FormatException ex)
                                    {
                                        Trace.TraceError("{0} is not a vaild GUID.", cid);
                                        Trace.TraceError(ex.ToString());
                                    }
                                }
                            }
                        }
                    }

                    results.Results.Add(thisResult);

                    var dirname = Path.GetDirectoryName(jsonFile);
                    if (Directory.Exists(dirname) == false)
                    {
                        Directory.CreateDirectory(dirname);
                    }

                    using (StreamWriter writer = new StreamWriter(jsonFile))
                    {
                        writer.WriteLine(JsonConvert.SerializeObject(results, Newtonsoft.Json.Formatting.Indented));
                    }
                }
                finally
                {
                    jsonFileMutex.ReleaseMutex();
                    jsonFileMutex.Dispose();
                }
            }
        }
示例#3
0
        /// <summary>
        /// Call this within a transaction.
        /// </summary>
        /// <param name="originalSubject"></param>
        /// <param name="singleFco"></param>
        /// <param name="OutputSubDir"></param>
        public void UpdateResultsJson(
            MgaFCO singleFco,
            string OutputSubDir)
        {
            string jsonFile = Path.Combine(Path.GetDirectoryName(this.m_filename), "results", "results.metaresults.json");
            AVM.DDP.MetaResults results = null;
            bool createdNew;
            using (System.Threading.Mutex jsonFileMutex = new System.Threading.Mutex(false, "results_metaresults_mutex", out createdNew))
            {
                jsonFileMutex.WaitOne();
                try
                {
                    if (File.Exists(jsonFile))
                    {
                        string content = "";
                        using (StreamReader reader = new StreamReader(jsonFile))
                        {
                            content = reader.ReadToEnd();
                        }
                        results = JsonConvert.DeserializeObject<AVM.DDP.MetaResults>(content);
                        // TODO: remove broken links
                    }
                    else
                    {
                        results = new AVM.DDP.MetaResults();
                    }

                    AVM.DDP.MetaResults.Result thisResult = new AVM.DDP.MetaResults.Result();

                    thisResult.Summary = MakeRelativePath(
                        Path.GetDirectoryName(jsonFile),
                        Path.Combine(OutputSubDir, AVM.DDP.MetaTBManifest.TESTBENCH_FILENAME)).Replace('\\', '/');

                    thisResult.Time = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");

                    thisResult.TestBench = singleFco.RegistryValue["TestBenchUniqueName"] + ".testbench.json";

                    if (singleFco.Meta.Name == typeof(CyPhy.TestBench).Name ||
                        singleFco.Meta.Name == typeof(CyPhy.ParametricExploration).Name ||
                        singleFco.Meta.Name == typeof(CyPhy.TestBenchSuite).Name)
                    {
                        CyPhy.TestBench testBench = null;
                        if (singleFco.Meta.Name == typeof(CyPhy.TestBench).Name)
                        {
                            testBench = ISIS.GME.Dsml.CyPhyML.Classes.TestBench.Cast(singleFco);
                        }
                        else if (singleFco.Meta.Name == typeof(CyPhy.ParametricExploration).Name)
                        {
                            var pet = ISIS.GME.Dsml.CyPhyML.Classes.ParametricExploration.Cast(singleFco);
                            testBench = pet.Children.TestBenchRefCollection.FirstOrDefault().Referred.TestBench;
                        }
                        else if (singleFco.Meta.Name == typeof(CyPhy.TestBenchSuite).Name)
                        {
                            var pet = ISIS.GME.Dsml.CyPhyML.Classes.TestBenchSuite.Cast(singleFco);
                            testBench = pet.Children.TestBenchRefCollection.FirstOrDefault().Referred.TestBench;
                        }

                        var tlsut = testBench.Children.TopLevelSystemUnderTestCollection.FirstOrDefault();
                        if (tlsut != null)
                        {
                            if (tlsut.Referred.ComponentAssembly != null)
                            {
                                var cfg = tlsut.Referred.ComponentAssembly;
                                thisResult.Design = cfg.Name + ".metadesign.json";

                                var cid = cfg.Attributes.ConfigurationUniqueID;
                                //this.ConfigurationUniqueID = cid;

                                if (string.IsNullOrWhiteSpace(cid))
                                {
                                    cid = Guid.NewGuid().ToString("B");
                                    cfg.Attributes.ConfigurationUniqueID = cid;
                                }

                                if (!string.IsNullOrEmpty(cid))
                                {
                                    try
                                    {
                                        Guid guid = new Guid(cid);
                                        thisResult.DesignID = guid.ToString("B");
                                    }
                                    catch (System.FormatException ex)
                                    {
                                        Trace.TraceError("{0} is not a vaild GUID.", cid);
                                        Trace.TraceError(ex.ToString());
                                    }
                                }
                            }
                        }
                    }

                    results.Results.Add(thisResult);

                    var dirname = Path.GetDirectoryName(jsonFile);
                    if (Directory.Exists(dirname) == false)
                    {
                        Directory.CreateDirectory(dirname);
                    }

                    using (StreamWriter writer = new StreamWriter(jsonFile))
                    {
                        writer.WriteLine(JsonConvert.SerializeObject(results, Newtonsoft.Json.Formatting.Indented));
                    }
                }
                finally
                {
                    jsonFileMutex.ReleaseMutex();
                }
            }
        }
示例#4
0
        /// <summary>
        /// Call this within a transaction.
        /// </summary>
        /// <param name="originalSubject"></param>
        /// <param name="singleFco"></param>
        /// <param name="OutputSubDir"></param>
        public void UpdateResultsJson(
            MgaFCO singleFco,
            string OutputSubDir)
        {
            string jsonFile = Path.Combine(Path.GetDirectoryName(this.m_filename), "results", "results.metaresults.json");

            AVM.DDP.MetaResults results = null;
            bool createdNew;

            using (System.Threading.Mutex jsonFileMutex = new System.Threading.Mutex(false, "results_metaresults_mutex", out createdNew))
            {
                jsonFileMutex.WaitOne();
                try
                {
                    if (File.Exists(jsonFile))
                    {
                        string content = "";
                        using (StreamReader reader = new StreamReader(jsonFile))
                        {
                            content = reader.ReadToEnd();
                        }
                        results = JsonConvert.DeserializeObject <AVM.DDP.MetaResults>(content);
                        // TODO: remove broken links
                    }
                    else
                    {
                        results = new AVM.DDP.MetaResults();
                    }

                    AVM.DDP.MetaResults.Result thisResult = new AVM.DDP.MetaResults.Result();

                    thisResult.Summary = MakeRelativePath(
                        Path.GetDirectoryName(jsonFile),
                        Path.Combine(OutputSubDir, AVM.DDP.MetaTBManifest.TESTBENCH_FILENAME)).Replace('\\', '/');

                    thisResult.Time = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");

                    thisResult.TestBench = singleFco.RegistryValue["TestBenchUniqueName"] + ".testbench.json";

                    if (singleFco.Meta.Name == typeof(CyPhy.TestBench).Name ||
                        singleFco.Meta.Name == typeof(CyPhy.ParametricExploration).Name ||
                        singleFco.Meta.Name == typeof(CyPhy.TestBenchSuite).Name)
                    {
                        CyPhy.TestBench testBench = null;
                        if (singleFco.Meta.Name == typeof(CyPhy.TestBench).Name)
                        {
                            testBench = ISIS.GME.Dsml.CyPhyML.Classes.TestBench.Cast(singleFco);
                        }
                        else if (singleFco.Meta.Name == typeof(CyPhy.ParametricExploration).Name)
                        {
                            var pet = ISIS.GME.Dsml.CyPhyML.Classes.ParametricExploration.Cast(singleFco);
                            testBench = pet.Children.TestBenchRefCollection.FirstOrDefault().Referred.TestBench;
                        }
                        else if (singleFco.Meta.Name == typeof(CyPhy.TestBenchSuite).Name)
                        {
                            var pet = ISIS.GME.Dsml.CyPhyML.Classes.TestBenchSuite.Cast(singleFco);
                            testBench = pet.Children.TestBenchRefCollection.FirstOrDefault().Referred.TestBench;
                        }

                        var tlsut = testBench.Children.TopLevelSystemUnderTestCollection.FirstOrDefault();
                        if (tlsut != null)
                        {
                            if (tlsut.Referred.ComponentAssembly != null)
                            {
                                var cfg = tlsut.Referred.ComponentAssembly;
                                thisResult.Design = cfg.Name + ".metadesign.json";

                                var cid = cfg.Attributes.ConfigurationUniqueID;
                                //this.ConfigurationUniqueID = cid;

                                if (string.IsNullOrWhiteSpace(cid))
                                {
                                    cid = Guid.NewGuid().ToString("B");
                                    cfg.Attributes.ConfigurationUniqueID = cid;
                                }

                                if (!string.IsNullOrEmpty(cid))
                                {
                                    try
                                    {
                                        Guid guid = new Guid(cid);
                                        thisResult.DesignID = guid.ToString("B");
                                    }
                                    catch (System.FormatException ex)
                                    {
                                        Trace.TraceError("{0} is not a vaild GUID.", cid);
                                        Trace.TraceError(ex.ToString());
                                    }
                                }
                            }
                        }
                    }

                    results.Results.Add(thisResult);

                    var dirname = Path.GetDirectoryName(jsonFile);
                    if (Directory.Exists(dirname) == false)
                    {
                        Directory.CreateDirectory(dirname);
                    }

                    using (StreamWriter writer = new StreamWriter(jsonFile))
                    {
                        writer.WriteLine(JsonConvert.SerializeObject(results, Newtonsoft.Json.Formatting.Indented));
                    }
                }
                finally
                {
                    jsonFileMutex.ReleaseMutex();
                    jsonFileMutex.Dispose();
                }
            }
        }