Esempio n. 1
0
        public void MainInTransaction(InterpreterMainParameters parameters)
        {
            this.mainParameters = (InterpreterMainParameters)parameters;
            if (GMEConsole == null)
            {
                GMEConsole = GMEConsole.CreateFromProject(mainParameters.Project);
            }

            var    currentObject          = mainParameters.CurrentFCO;
            var    currentOutputDirectory = mainParameters.OutputDirectory;
            string artifactName           = string.Empty;
            string metaBaseName           = currentObject.MetaBase.Name;

            if (metaBaseName == typeof(CyPhyClasses.DesignContainer).Name)
            {
                artifactName = ExportToFile(CyPhyClasses.DesignContainer.Cast(currentObject), currentOutputDirectory);
            }
            else if (metaBaseName == typeof(CyPhyClasses.ComponentAssembly).Name)
            {
                artifactName = ExportToFile(CyPhyClasses.ComponentAssembly.Cast(currentObject), currentOutputDirectory);
            }
            else if (IsTestBenchType(metaBaseName))
            {
                artifactName = ExportToFile(CyPhyClasses.TestBenchType.Cast(currentObject), currentOutputDirectory);
            }

            if (!string.IsNullOrWhiteSpace(artifactName))
            {
                var manifest = AVM.DDP.MetaTBManifest.OpenForUpdate(currentOutputDirectory);
                manifest.AddArtifact(Path.GetFileName(artifactName), "Design Model");
                manifest.Serialize(currentOutputDirectory);
            }
        }
Esempio n. 2
0
        public avm.Design Convert(String pathDE)
        {
            MgaObject objDE = null;

            proj.PerformInTransaction(delegate
            {
                objDE = proj.get_ObjectByPath(pathDE);
            });
            Assert.NotNull(objDE);

            var interp = new CyPhyDesignExporter.CyPhyDesignExporterInterpreter();

            interp.Initialize(proj);
            InterpreterMainParameters param = new InterpreterMainParameters()
            {
                OutputDirectory = PathTest,
                CurrentFCO      = objDE as MgaFCO,
                Project         = proj
            };
            var result = interp.Main(param);

            Assert.True(result.Success);

            // Load the new .adm file
            var pathAdm = Path.Combine(PathTest,
                                       pathDE.Split('/').Last() + ".adm");
            var xml    = File.ReadAllText(pathAdm);
            var design = OpenMETA.Interchange.AvmXmlSerializer.Deserialize <avm.Design>(xml);

            Assert.NotNull(design);

            return(design);
        }
Esempio n. 3
0
        public void PCB_Manufacturing()
        {
            /* What do we want to do?
             * Let's load the model and run the test bench.
             * Then check the output folder.
             * Verify that it contains the stuff that we expect.
             */

            var    pathTestbench = "/@TestBenches|kind=Testing|relpos=0/PCB_Manufacturing|kind=TestBench|relpos=0";
            String testName      = System.Reflection.MethodBase.GetCurrentMethod().Name;
            String pathOutput    = Path.Combine(project.GetRootDirectoryPath(),
                                                "output",
                                                testName);

            if (Directory.Exists(pathOutput))
            {
                Directory.Delete(pathOutput);
            }
            Directory.CreateDirectory(pathOutput);

            MgaFCO objTestBench = null;

            project.PerformInTransaction(delegate
            {
                objTestBench = project.get_ObjectByPath(pathTestbench) as MgaFCO;
                Assert.NotNull(objTestBench);

                var interpreter = new CyPhy2PCBMfg.CyPhy2PCBMfgInterpreter();
                interpreter.Initialize(project);
                var parameters = new InterpreterMainParameters()
                {
                    CurrentFCO       = objTestBench,
                    SelectedFCOs     = null,
                    Project          = project,
                    OutputDirectory  = pathOutput,
                    ProjectDirectory = project.GetRootDirectoryPath()
                };
                interpreter.Main(parameters);
            });

            // Check that files were copied from the design path to the output path.
            string[] copiedFileNames =
            {
                "BomTable.csv",
                "pcb_mfg.cam",
                "reference_designator_mapping_table.html",
                "schema.brd",
                "schema.sch"
            };

            foreach (string filename in copiedFileNames)
            {
                var pathCopiedFile = Path.Combine(pathOutput, filename);
                Assert.True(File.Exists(pathCopiedFile));
                var fileContents = File.ReadAllText(pathCopiedFile);
                Assert.False(String.IsNullOrWhiteSpace(fileContents));
            }
        }
Esempio n. 4
0
        public void MainInTransaction(InterpreterMainParameters parameters, bool exportPackage = false)
        {
            this.mainParameters = (InterpreterMainParameters)parameters;

            Boolean disposeLogger = false;

            if (Logger == null)
            {
                Logger        = new GMELogger(mainParameters.Project, "CyPhyDesignExporter");
                disposeLogger = true;
            }

            var    currentObject          = mainParameters.CurrentFCO;
            var    currentOutputDirectory = mainParameters.OutputDirectory;
            string artifactName           = string.Empty;
            string metaBaseName           = currentObject.MetaBase.Name;

            try
            {
                if (metaBaseName == typeof(CyPhyClasses.DesignContainer).Name)
                {
                    artifactName = ExportToFile(CyPhyClasses.DesignContainer.Cast(currentObject), currentOutputDirectory);
                }
                else if (metaBaseName == typeof(CyPhyClasses.ComponentAssembly).Name)
                {
                    if (exportPackage)
                    {
                        artifactName = ExportToPackage(CyPhyClasses.ComponentAssembly.Cast(currentObject), currentOutputDirectory);
                    }
                    else
                    {
                        artifactName = ExportToFile(CyPhyClasses.ComponentAssembly.Cast(currentObject), currentOutputDirectory);
                    }
                }
                else if (IsTestBenchType(metaBaseName))
                {
                    artifactName = ExportToFile(CyPhyClasses.TestBenchType.Cast(currentObject), currentOutputDirectory);
                }

                if (!string.IsNullOrWhiteSpace(artifactName))
                {
                    var manifest = AVM.DDP.MetaTBManifest.OpenForUpdate(currentOutputDirectory);
                    manifest.AddArtifact(Path.GetFileName(artifactName), "Design Model");
                    manifest.Serialize(currentOutputDirectory);
                }
            }
            finally
            {
                if (disposeLogger)
                {
                    DisposeLogger();
                }
            }
        }
Esempio n. 5
0
        public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param)
        {
            if (this.enabled == false)
            {
                return;
            }

            try
            {
                // Need to call this interpreter in the same way as the MasterInterpreter will call it.
                // initialize main parameters
                var parameters = new InterpreterMainParameters()
                {
                    Project        = project,
                    CurrentFCO     = currentobj,
                    SelectedFCOs   = selectedobjs,
                    StartModeParam = param
                };

                this.mainParameters         = parameters;
                parameters.ProjectDirectory = project.GetRootDirectoryPath();

                // set up the output directory
                MgaGateway.PerformInTransaction(delegate
                {
                    string outputDirName = project.Name;
                    if (currentobj != null)
                    {
                        outputDirName = currentobj.Name;
                    }

                    var outputDirAbsPath = Path.GetFullPath(Path.Combine(
                                                                parameters.ProjectDirectory,
                                                                "results",
                                                                outputDirName));

                    parameters.OutputDirectory = outputDirAbsPath;

                    if (Directory.Exists(outputDirAbsPath))
                    {
                        Logger.WriteWarning("Output directory {0} already exists. Unexpected behavior may result.", outputDirAbsPath);
                    }
                    else
                    {
                        Directory.CreateDirectory(outputDirAbsPath);
                    }
                });

                PreConfigArgs preConfigArgs = new PreConfigArgs()
                {
                    ProjectDirectory = parameters.ProjectDirectory,
                    Project          = parameters.Project
                };

                // call the preconfiguration with no parameters and get preconfig
                var preConfig = this.PreConfig(preConfigArgs);

                // get previous GUI config
                var settings_ = META.ComComponent.DeserializeConfiguration(parameters.ProjectDirectory,
                                                                           typeof(CyPhy2CADPCB_Settings),
                                                                           this.ComponentProgID);
                CyPhy2CADPCB_Settings settings = (settings_ != null) ? settings_ as CyPhy2CADPCB_Settings : new CyPhy2CADPCB_Settings();

                // Set configuration based on Workflow Parameters. This will override all [WorkflowConfigItem] members.
                settings = InitializeSettingsFromWorkflow(settings);

                // get interpreter config through GUI
                var config = this.DoGUIConfiguration(preConfig, settings);
                if (config == null)
                {
                    Logger.WriteWarning("Operation canceled by the user.");
                    return;
                }

                // if config is valid save it and update it on the file system
                META.ComComponent.SerializeConfiguration(parameters.ProjectDirectory, config, this.ComponentProgID);

                // assign the new configuration to mainParameters
                parameters.config = config;

                // call the main (ICyPhyComponent) function
                this.Main(parameters);
            }
            catch (Exception ex)
            {
                Logger.WriteError("Interpretation failed {0}<br>{1}", ex.Message, ex.StackTrace);
            }
            finally
            {
                DisposeLogger();
                MgaGateway   = null;
                project      = null;
                currentobj   = null;
                selectedobjs = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
Esempio n. 6
0
        public IInterpreterResult Main(IInterpreterMainParameters parameters)
        {
            result.RunCommand = "runCADJob.bat";
            result.Labels     = "Creo&&CADCreoParametricCreateAssembly.exev1.4&&" + JobManager.Job.DefaultLabels;
            var ProjectIsNotInTransaction = (parameters.Project.ProjectStatus & 8) == 0;

            if (ProjectIsNotInTransaction)
            {
                parameters.Project.BeginTransactionInNewTerr();
            }
            Dictionary <string, string> workflowParameters = new Dictionary <string, string>();
            var workflowRef = parameters
                              .CurrentFCO
                              .ChildObjects
                              .OfType <MgaReference>()
                              .FirstOrDefault(x => x.Meta.Name == "WorkflowRef");

            if (workflowRef != null)
            {
                string Parameters = workflowRef.Referred
                                    .ChildObjects
                                    .OfType <MgaAtom>()
                                    .FirstOrDefault(x => x.Meta.Name == "Task")
                                    .StrAttrByName["Parameters"];
                try
                {
                    workflowParameters = (Dictionary <string, string>)Newtonsoft.Json.JsonConvert.DeserializeObject(Parameters, typeof(Dictionary <string, string>));
                    if (workflowParameters == null)
                    {
                        workflowParameters = new Dictionary <string, string>();
                    }
                }
                catch (Newtonsoft.Json.JsonReaderException)
                {
                }
            }
            META.AnalysisTool.ApplyToolSelection(this.ComponentProgID, workflowParameters, this.result, parameters, modifyLabels: false);
            if (ProjectIsNotInTransaction)
            {
                parameters.Project.AbortTransaction();
            }

            this.CopySTL = workflowParameters.ContainsValue("FreedLinkageAssembler");



            var resultzip = CyPhy2CAD_CSharp.Properties.Resources.ResultZip;

            result.ZippyServerSideHook = Encoding.UTF8.GetString(resultzip);
            result.LogFileDirectory    = Path.Combine(parameters.OutputDirectory, "log");

            this.mainParameters = (InterpreterMainParameters)parameters;
            if (this.mainParameters.config == null)
            {
                var config = META.ComComponent.DeserializeConfiguration(this.mainParameters.ProjectDirectory, typeof(CyPhy2CADSettings), this.ComponentProgID) as CyPhy2CADSettings;
                if (config != null)
                {
                    this.mainParameters.config = config;
                    settings = config;
                }
                else
                {
                    this.mainParameters.config = new CyPhy2CADSettings();
                }
            }
            if (this.result.Traceability == null)
            {
                this.result.Traceability = new META.MgaTraceability();
            }

            // getting traceability from caller, like master interpreter
            if (this.mainParameters.Traceability != null)
            {
                this.mainParameters.Traceability.CopyTo(this.result.Traceability);
            }

            //CyPhy2CAD_CSharp.CyPhy2CADSettings configSettings = (CyPhy2CAD_CSharp.CyPhy2CADSettings)parameters.config;
            //settings = configSettings;

            settings = (CyPhy2CAD_CSharp.CyPhy2CADSettings) this.mainParameters.config;
            settings.OutputDirectory = parameters.OutputDirectory;
            Automation = true;
            Logger.Instance.AddLogMessage("Main:Aux Directory is: " + settings.AuxiliaryDirectory, Severity.Info);
            Logger.Instance.AddLogMessage("Output Directory is: " + settings.OutputDirectory, Severity.Info);
            MgaGateway.voidDelegate action = delegate
            {
                if (Elaborate(parameters.Project, parameters.CurrentFCO, parameters.SelectedFCOs, parameters.StartModeParam))
                {
                    result.Success = Main(parameters.Project, parameters.CurrentFCO, parameters.SelectedFCOs, Convert(parameters.StartModeParam));
                }
                else
                {
                    result.Success = false;
                    Logger.Instance.DumpLog(GMEConsole, LogDir);
                }
            };

            if ((parameters.Project.ProjectStatus & 8) == 0)
            {
                MgaGateway.PerformInTransaction(
                    d: action,
                    mode: transactiontype_enum.TRANSACTION_NON_NESTED,
                    abort: true);
            }
            else
            {
                action.Invoke();
            }

            return(result);
        }
Esempio n. 7
0
        public void InvokeEx(
            MgaProject project,
            MgaFCO currentobj,
            MgaFCOs selectedobjs,
            int param)
        {
            if (!enabled)
            {
                return;
            }

            if (currentobj == null)
            {
                GMEConsole.Error.WriteLine("Please select a CADTestBench, Ballistic Testbench, FEA Testbench, Blast Testbench or CadAssembly.");
                return;
            }

            string currentWorkDir = System.IO.Directory.GetCurrentDirectory();

            try
            {
                var parameters = new InterpreterMainParameters();
                this.mainParameters         = parameters;
                parameters.ProjectDirectory = Path.GetDirectoryName(currentobj.Project.ProjectConnStr.Substring("MGA=".Length));

                FetchSettings();

                // Show UI
                using (MainForm mf = new MainForm(settings))
                {
                    mf.ShowDialog();
                    DialogResult ok = mf.DialogResult;
                    if (ok == DialogResult.OK)
                    {
                        settings = mf.ConfigOptions;
                        parameters.OutputDirectory = settings.OutputDirectory;
                        parameters.config          = settings;
                    }
                    else
                    {
                        GMEConsole.Warning.WriteLine("Process was cancelled.");
                        return;
                    }
                }

                SaveSettings();

                MgaGateway.PerformInTransaction(delegate
                {
                    Elaborate(project, currentobj, selectedobjs, param);
                    Main(project, currentobj, selectedobjs, Convert(param));
                },
                                                abort: true);
            }
            finally
            {
                MgaGateway   = null;
                project      = null;
                currentobj   = null;
                selectedobjs = null;
                GMEConsole   = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
Esempio n. 8
0
        public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param)
        {
            this.paramInvoked    = param;
            this.ProjectFilename = project.ProjectConnStr.Substring("MGA=".Length);
            sotConfig.OriginalProjectFileName = this.ProjectFilename;

            if (!enabled)
            {
                return;
            }

            string currentWorkDir = System.IO.Directory.GetCurrentDirectory();

            try
            {
                this.Logger = new CyPhyGUIs.GMELogger(project, this.ComponentName);
                this.Logger.GMEConsoleLoggingLevel = SmartLogger.MessageType_enum.Debug;

                if (currentobj == null)
                {
                    this.Logger.WriteFailed("CyPhySOT must be called from a TestBenchSuite.");
                    return;
                }

                this.Logger.WriteInfo("Starting CyPhySoT...");
                System.Windows.Forms.Application.DoEvents();

                // Need to call this interpreter in the same way as the MasterInterpreter will call it.
                // initialize main parameters
                var parameters = new InterpreterMainParameters()
                {
                    Project        = project,
                    CurrentFCO     = currentobj,
                    SelectedFCOs   = selectedobjs,
                    StartModeParam = param,
                    VerboseConsole = true
                };

                this.mainParameters         = parameters;
                parameters.ProjectDirectory = Path.GetDirectoryName(currentobj.Project.ProjectConnStr.Substring("MGA=".Length));

                string kindName = string.Empty;

                // Set up the output directory and check Kind of currentObj.
                MgaGateway.PerformInTransaction(delegate
                {
                    string outputDirName = project.Name;
                    if (currentobj != null)
                    {
                        outputDirName = currentobj.Name;
                        kindName      = currentobj.MetaBase.Name;
                    }

                    parameters.OutputDirectory = Path.GetFullPath(Path.Combine(
                                                                      parameters.ProjectDirectory,
                                                                      "results",
                                                                      outputDirName));

                    //this.Parameters.PackageName = Modelica.Factory.GetModifiedName(currentobj.Name);
                });

                if (string.IsNullOrEmpty(kindName) == false && kindName != typeof(CyPhyClasses.TestBenchSuite).Name)
                {
                    this.Logger.WriteFailed("CyPhySOT must be called from a TestBenchSuite.");
                    return;
                }

                PreConfigArgs preConfigArgs = new PreConfigArgs();
                preConfigArgs.ProjectDirectory = parameters.ProjectDirectory;

                // call the preconfiguration with no parameters and get preconfig
                var preConfig = this.PreConfig(preConfigArgs);

                // get previous GUI config
                var previousConfig = META.ComComponent.DeserializeConfiguration(
                    parameters.ProjectDirectory,
                    typeof(CyPhySoTSettings),
                    this.ComponentProgID);

                // get interpreter config through GUI
                var config = this.DoGUIConfiguration(preConfig, previousConfig);
                if (config == null)
                {
                    this.Logger.WriteWarning("Operation cancelled by the user.");
                    return;
                }

                // if config is valid save it and update it on the file system
                META.ComComponent.SerializeConfiguration(parameters.ProjectDirectory, config, this.ComponentProgID);

                // assign the new configuration to mainParameters
                parameters.config = config;

                // call the main (ICyPhyComponent) function
                this.Main(parameters);
            }
            catch (Exception ex)
            {
                this.Logger.WriteError("{0} has finished with critical errors see log file {1}.", this.ComponentName, this.logFileName);
                this.Logger.WriteError(ex.ToString());
            }
            finally
            {
                if (this.Logger != null)
                {
                    this.Logger.Dispose();
                    this.Logger = null;
                }
                MgaGateway   = null;
                project      = null;
                currentobj   = null;
                selectedobjs = null;

                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
Esempio n. 9
0
        public void CodeGenerator_CreateDirectivitySimulation_CheckGeneratedFiles()
        {
            string testbenchPath = "/@RFTest|kind=Testing|relpos=0/@DipoleTest|kind=TestBench|relpos=0";
            string testName      = System.Reflection.MethodBase.GetCurrentMethod().Name;
            string pathOutput    = Path.Combine(testPath, "output", testName);

            if (Directory.Exists(pathOutput))
            {
                Directory.Delete(pathOutput);
            }
            Directory.CreateDirectory(pathOutput);

            // Run the interpreter
            CyPhy2RF.CyPhy2RFInterpreter interpreter = null;
            InterpreterMainParameters    parameters  = null;

            project.PerformInTransaction(delegate
            {
                var objTestbench = project.get_ObjectByPath(testbenchPath);
                Assert.NotNull(objTestbench);

                var testbench = ISIS.GME.Dsml.CyPhyML.Classes.TestBench.Cast(objTestbench);
                Assert.NotNull(testbench);

                interpreter = new CyPhy2RF.CyPhy2RFInterpreter();
                interpreter.Initialize(project);

                parameters = new InterpreterMainParameters()
                {
                    CurrentFCO       = testbench.Impl as MgaFCO,
                    SelectedFCOs     = null,
                    Project          = project,
                    OutputDirectory  = pathOutput,
                    ProjectDirectory = project.GetRootDirectoryPath(),
                    config           = new CyPhy2RF.CyPhy2RF_Settings()
                    {
                        doDirectivity = "true"
                    }
                };
            });

            interpreter.Main(parameters);

            // Check batch file (directivity)
            string batchFileName = Path.Combine(testPath, "output", testName, "run_dir_simulation.cmd");

            Assert.True(File.Exists(batchFileName), "Batch file '" + batchFileName + "' not found.");

            // Check OpenEMS input XML file
            string simulationXmlFileName = Path.Combine(testPath, "output", testName, "openEMS_input.xml");

            Assert.True(File.Exists(simulationXmlFileName), "Simulation input file '" + simulationXmlFileName + "' not found.");

            // Check NF2FF input XML file
            string nf2ffXmlFileName = Path.Combine(testPath, "output", testName, "openEMS_input.xml");

            Assert.True(File.Exists(nf2ffXmlFileName), "NF2FF input file '" + nf2ffXmlFileName + "' not found.");

            // Run FDTD postprocess
            Process p      = new Process();
            int     result = -1;

            try
            {
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.FileName        = batchFileName;
                p.StartInfo.CreateNoWindow  = true;
                p.Start();
                p.WaitForExit();
                result = p.ExitCode;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Assert.True(result == 0, "Running openEMS simulations failed.");

            // Check metrics in manifest
            string manifestPath = Path.Combine(testPath, "output", testName);
            var    manifest     = AVM.DDP.MetaTBManifest.OpenForUpdate(Path.Combine(manifestPath));

            Assert.True(manifest.Metrics.FirstOrDefault(m => m.Name == "Directivity") != null, String.Format("Directivity metric in manifest file not found in {0}", manifestPath));
        }
Esempio n. 10
0
        private MfgBom.Bom.MfgBom RunInterpreter(string pathTestbench, String pathOutput, int design_quantity)
        {
            if (Directory.Exists(pathOutput))
            {
                Directory.Delete(pathOutput);
            }
            Directory.CreateDirectory(pathOutput);

            CyPhy2MfgBom.CyPhy2MfgBomInterpreter interpreter = null;
            InterpreterMainParameters            parameters  = null;

            project.PerformInTransaction(delegate
            {
                var objTestbench = project.get_ObjectByPath(pathTestbench);
                Assert.NotNull(objTestbench);

                var testbench = ISIS.GME.Dsml.CyPhyML.Classes.TestBench.Cast(objTestbench);
                Assert.NotNull(testbench);

                interpreter = new CyPhy2MfgBom.CyPhy2MfgBomInterpreter();
                interpreter.Initialize(project);
                parameters = new InterpreterMainParameters()
                {
                    CurrentFCO       = testbench.Impl as MgaFCO,
                    SelectedFCOs     = null,
                    Project          = project,
                    OutputDirectory  = pathOutput,
                    ProjectDirectory = project.GetRootDirectoryPath()
                };
            });

            interpreter.Main(parameters);

            // Load manifest
            string pathManifest = Path.Combine(pathOutput, "testbench_manifest.json");

            Assert.True(File.Exists(pathManifest));
            var manifest = AVM.DDP.MetaTBManifest.OpenForUpdate(pathOutput);

            Assert.Equal(2, manifest.Artifacts.Count);

            // This metric should be created, whether it's provided or not
            Assert.Equal(1, manifest.Metrics.Count(m => m.Name == "part_cost_per_design"));


            // Check batch file
            var pathBatchFile = Path.Combine(pathOutput, "runBomCostAnalysis.bat");

            Assert.True(File.Exists(pathBatchFile));
            var batchContents = File.ReadAllText(pathBatchFile);

            Assert.False(String.IsNullOrWhiteSpace(batchContents));


            // Check request
            var artifactRequest = manifest.Artifacts.FirstOrDefault(a => a.Tag == "CyPhy2MfgBom::CostEstimationRequest");

            Assert.NotNull(artifactRequest);
            var pathRequest = Path.Combine(pathOutput, artifactRequest.Location);

            Assert.True(File.Exists(pathRequest));

            string strRequest = System.IO.File.ReadAllText(pathRequest);
            var    request    = MfgBom.CostEstimation.CostEstimationRequest.Deserialize(strRequest);

            Assert.NotNull(request);
            Assert.NotNull(request.bom);
            Assert.Equal(design_quantity, request.design_quantity);


            // Check BOM
            var artifactBom = manifest.Artifacts.FirstOrDefault(a => a.Tag == "CyPhy2MfgBom::BOM");

            Assert.NotNull(artifactBom);
            var pathBom = Path.Combine(pathOutput, artifactBom.Location);

            Assert.True(File.Exists(pathBom));

            string strBom = System.IO.File.ReadAllText(pathBom);
            var    bom    = MfgBom.Bom.MfgBom.Deserialize(strBom);

            Assert.NotNull(bom);
            return(bom);
        }
Esempio n. 11
0
 public void MainInTransaction(InterpreterMainParameters parameters)
 {
     MainInTransaction(parameters, false);
 }
Esempio n. 12
0
        public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param)
        {
            if (!enabled)
            {
                return;
            }

            try
            {
                // Need to call this interpreter in the same way as the MasterInterpreter will call it.
                // initialize main parameters
                var parameters = new InterpreterMainParameters()
                {
                    Project        = project,
                    CurrentFCO     = currentobj,
                    SelectedFCOs   = selectedobjs,
                    StartModeParam = param
                };

                this.mainParameters         = parameters;
                parameters.ProjectDirectory = Path.GetDirectoryName(currentobj.Project.ProjectConnStr.Substring("MGA=".Length));

                // set up the output directory
                MgaGateway.PerformInTransaction(delegate
                {
                    string outputDirName = project.Name;
                    if (currentobj != null)
                    {
                        outputDirName = currentobj.Name;
                    }

                    parameters.OutputDirectory = Path.GetFullPath(Path.Combine(
                                                                      parameters.ProjectDirectory,
                                                                      "results",
                                                                      outputDirName));

                    //this.Parameters.PackageName = SystemC.Factory.GetModifiedName(currentobj.Name);
                });

                PreConfigArgs preConfigArgs = new PreConfigArgs();
                preConfigArgs.ProjectDirectory = parameters.ProjectDirectory;

                // call the preconfiguration with no parameters and get preconfig
                var preConfig = this.PreConfig(preConfigArgs);

                // get previous GUI config
                var previousConfig = META.ComComponent.DeserializeConfiguration(
                    parameters.ProjectDirectory,
                    typeof(CyPhy2Simulink_Settings),
                    this.ComponentProgID);

                // get interpreter config through GUI
                var config = this.DoGUIConfiguration(preConfig, previousConfig);
                if (config == null)
                {
                    GMEConsole.Warning.WriteLine("Operation cancelled by the user.");
                    return;
                }

                // if config is valid save it and update it on the file system
                META.ComComponent.SerializeConfiguration(parameters.ProjectDirectory, config, this.ComponentProgID);

                // assign the new configuration to mainParameters
                parameters.config = config;

                // call the main (ICyPhyComponent) function
                this.Main(parameters);
            }
            catch (Exception ex)
            {
                GMEConsole.Error.WriteLine("Interpretation failed {0}<br>{1}", ex.Message, ex.StackTrace);
            }
            finally
            {
                MgaGateway   = null;
                project      = null;
                currentobj   = null;
                selectedobjs = null;
                GMEConsole   = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
Esempio n. 13
0
        public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param)
        {
            if (!enabled)
            {
                return;
            }

            try
            {
                // Create a new instance of the logger
                this.Logger = new CyPhyGUIs.GMELogger(project, this.ComponentName);

                if (currentobj == null)
                {
                    this.Logger.WriteFailed("CyPhyReliabilityAnalysis must be called from a Test Bench.");
                    return;
                }

                // Need to call this interpreter in the same way as the MasterInterpreter will call it.
                // initialize main parameters
                var parameters = new InterpreterMainParameters()
                {
                    Project        = project,
                    CurrentFCO     = currentobj,
                    SelectedFCOs   = selectedobjs,
                    StartModeParam = param,
                    VerboseConsole = true
                };

                this.mainParameters         = parameters;
                parameters.ProjectDirectory = Path.GetDirectoryName(project.ProjectConnStr.Substring("MGA=".Length));

                // Set up the output directory and check kind of currentObj.
                string kindName = string.Empty;
                MgaGateway.PerformInTransaction(delegate
                {
                    string outputDirName = project.Name;
                    if (currentobj != null)
                    {
                        outputDirName = currentobj.Name;
                        kindName      = currentobj.MetaBase.Name;
                    }

                    parameters.OutputDirectory = Path.GetFullPath(Path.Combine(
                                                                      parameters.ProjectDirectory,
                                                                      "results",
                                                                      outputDirName));
                });

                if (string.IsNullOrEmpty(kindName) == false && kindName != "TestBench")
                {
                    this.Logger.WriteFailed("CyPhyReliabilityAnalysis must be called from a Test Bench.");
                    return;
                }

                PreConfigArgs preConfigArgs = new PreConfigArgs();
                preConfigArgs.ProjectDirectory = parameters.ProjectDirectory;

                // call the preconfiguration with no parameters and get preconfig
                var preConfig = this.PreConfig(preConfigArgs);

                // get previous GUI config
                var previousConfig = META.ComComponent.DeserializeConfiguration(
                    parameters.ProjectDirectory,
                    typeof(CyPhyReliabilityAnalysisSettings),
                    this.ComponentProgID);

                // get interpreter config through GUI
                var config = this.DoGUIConfiguration(preConfig, previousConfig);
                if (config == null)
                {
                    this.Logger.WriteWarning("Operation cancelled by the user.");
                    return;
                }

                //#region CyPhy2Modelica_v2Configuration

                //var cyPhy2Modelica_v2 = new META.ComComponent("MGA.Interpreter.CyPhy2Modelica_v2");
                //if (cyPhy2Modelica_v2.DoGUIConfiguration(parameters.ProjectDirectory) == false)
                //{
                //    this.Logger.WriteWarning("Operation cancelled by the user.");
                //    return;
                //}
                //#endregion

                // TODO: put here any other interpreters that we have to call.

                // if config is valid save it and update it on the file system
                META.ComComponent.SerializeConfiguration(parameters.ProjectDirectory, config, this.ComponentProgID);

                // assign the new configuration to mainParameters
                parameters.config = config;

                // call the main (ICyPhyComponent) function
                this.Main(parameters);
            }
            finally
            {
                if (this.Logger != null)
                {
                    this.Logger.Dispose();
                    this.Logger = null;
                }
                MgaGateway   = null;
                project      = null;
                currentobj   = null;
                selectedobjs = null;
                //GMEConsole = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
Esempio n. 14
0
        public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param)
        {
            if (!enabled)
            {
                return;
            }

            try
            {
                if (currentobj == null)
                {
                    GMEConsole.Error.WriteLine("No model opened.");
                    return;
                }

                var parameters = new InterpreterMainParameters()
                {
                    Project        = project,
                    CurrentFCO     = currentobj,
                    SelectedFCOs   = selectedobjs,
                    VerboseConsole = true
                };

                parameters.ProjectDirectory = Path.GetDirectoryName(currentobj.Project.ProjectConnStr.Substring("MGA=".Length));

                MgaGateway.PerformInTransaction(delegate
                {
                    string outputDirName = project.Name;
                    if (currentobj != null)
                    {
                        outputDirName = currentobj.Name;
                    }

                    parameters.OutputDirectory = Path.GetFullPath(Path.Combine(
                                                                      parameters.ProjectDirectory,
                                                                      "results",
                                                                      outputDirName));
                });

                PreConfigArgs preConfigArgs = new PreConfigArgs();
                preConfigArgs.ProjectDirectory = parameters.ProjectDirectory;

                // call the preconfiguration with no parameters and get preconfig
                var preConfig = this.PreConfig(preConfigArgs);

                // get previous GUI config
                var previousConfig = META.ComComponent.DeserializeConfiguration(parameters.ProjectDirectory,
                                                                                typeof(CyPhyCarSettings),
                                                                                this.ComponentProgID);

                // get interpreter config through GUI
                var config = this.DoGUIConfiguration(preConfig, previousConfig);

                // if config is valid save it and update it on the file system
                META.ComComponent.SerializeConfiguration(parameters.ProjectDirectory, config, this.ComponentProgID);

                // assign the new configuration to mainParameters
                parameters.config = config;


                // call the main (ICyPhyComponent) function
                this.Main(parameters);
            }
            finally
            {
                MgaGateway   = null;
                project      = null;
                currentobj   = null;
                selectedobjs = null;
                GMEConsole   = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
Esempio n. 15
0
        public ComComponent(
            string progId,
            bool currentObjectRequired)
        {
            //MGALib.IMgaProject project;
            //bool mode;
            //project.Open("MGA=...mga", out mode);
            //project.GetFCOByID("id-");
            //run_interpreter;
            //project.Close(true);

            MainParameters        = new InterpreterMainParameters();
            WorkflowParameters    = new Dictionary <string, string>();
            CurrentObjectRequired = currentObjectRequired;
            ProgId = progId;

            // default values
            Name = ProgId;

            if (string.IsNullOrWhiteSpace(ProgId))
            {
                isValid = false;
                return;
            }

            Type = Type.GetTypeFromProgID(ProgId);

            if (Type != null)
            {
                isValid = true;
                try
                {
                    MgaComponent = Activator.CreateInstance(Type) as IMgaComponentEx;
                }
                catch (Exception)
                {
                    //MessageBox.Show(
                    //  String.Format("Error: Creating COM component {0}." +
                    //    Environment.NewLine + "Detailed exception message: {1}",
                    //    ProgId,
                    //    ex.Message),
                    //  "Error",
                    //  MessageBoxButtons.OK,
                    //  MessageBoxIcon.Error);
                    isValid = false;
                    return;
                }

                if (MgaComponent == null)
                {
                    isValid = false;
                    return;
                }

                string _name = MgaComponent.ComponentParameter["name"] as string;
                if (_name != null)
                {
                    Name = _name;
                }
            }
            else
            {
                isValid = false;
            }
        }