Inheritance: IInterpreterMainParameters
        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 = XSD2CSharp.AvmXmlSerializer.Deserialize<avm.Design>(xml);
            Assert.NotNull(design);

            return design;
        }
        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;
        }
        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();
            }
        }
Beispiel #4
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();
            }
        }
Beispiel #5
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;
            Description = "Description: " + ProgId;
            Help = "Help: " + 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;
                string _description = MgaComponent.ComponentParameter["description"] as string;
                string _help = MgaComponent.ComponentParameter["help"] as string;
                if (_name != null)
                {
                    Name = _name;
                }
                if (_description != null)
                {
                    Description = _description;
                }
                if (_help != null)
                {
                    Help = _help;
                }
            }
            else
            {
                isValid = false;
            }
        }
Beispiel #6
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("CyPhyPET must be called from a Parametric Exploration.");
                    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));


                // Check if the PCCPropertyInputEditor should be opend.
                // If so return after this transaction
                bool doReturn = false;

                int VK_CONTROL = 0x11;
                // If control was held, try to open GUI. 
                if ((bool)((GetKeyState(VK_CONTROL) & 0x8000) == 0x8000))
                {
                    MgaGateway.PerformInTransaction(delegate
                    {
                        doReturn = this.TryOpenPCCPropertyInputEditor();
                    }, abort: false);
                }

                if (doReturn)
                {
                    return;
                }

                string interpreterProgID = "";

                // 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));
                    var testBenchRef = currentobj.ChildObjects.Cast<MgaFCO>().Where(c => c.MetaRole.Name == typeof(CyPhyClasses.TestBenchRef).Name).FirstOrDefault();
                    if (testBenchRef != null)
                    {
                        var tbRef = CyPhyClasses.TestBenchRef.Cast(testBenchRef);
                        if (tbRef.AllReferred is CyPhy.TestBench)
                        {
                            var testBench = CyPhyClasses.TestBenchRef.Cast(testBenchRef).Referred.TestBench;
                            interpreterProgID = Rules.Global.GetInterpreterProgIDFromTestBench(testBench);
                        }
                        else if (tbRef.AllReferred is CyPhy.TestBenchType)
                        {
                            // Assume CyPhy2CAD_CSharp for all other types of test-benches for now.
                            interpreterProgID = "MGA.Interpreter.CyPhy2CAD_CSharp";
                        }
                    }
                });

                if (string.IsNullOrEmpty(kindName) == false && kindName != typeof(CyPhyClasses.ParametricExploration).Name)
                {
                    this.Logger.WriteFailed("CyPhyPET must be called from a Parametric Exploration.");
                    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(CyPhyPET.CyPhyPETSettings),
                    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;
                }

                // External Interpreter configuration
                if (interpreterProgID == "MGA.Interpreter.CyPhy2Modelica_v2")
                {
                    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;
                    }
                }
                else if (interpreterProgID == "MGA.Interpreter.CyPhy2CAD_CSharp")
                {
                    var cyPhy2CAD_CSharp = new META.ComComponent("MGA.Interpreter.CyPhy2CAD_CSharp");
                    if (cyPhy2CAD_CSharp.DoGUIConfiguration(parameters.ProjectDirectory) == false)
                    {
                        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);

            }
            finally
            {
                if (this.Logger != null)
                {
                    this.Logger.Dispose();
                    this.Logger = null;
                }
                if (MgaGateway != null &&
                    MgaGateway.territory != null)
                {
                    MgaGateway.territory.Destroy();
                }
                MgaGateway = null;
                project = null;
                currentobj = null;
                selectedobjs = null;
                //GMEConsole = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
        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(CyPhy2RF_Settings),
                    this.ComponentProgID);

                // get interpreter config through GUI
                var config = this.DoGUIConfiguration(preConfig, previousConfig);
                if (config == null)
                {
                    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)
            {
                Logger.WriteError("Interpretation failed {0}<br>{1}", ex.Message, ex.StackTrace);
            }
            finally
            {
                if (MgaGateway != null && MgaGateway.territory != null)
                {
                    MgaGateway.territory.Destroy();
                }
                MgaGateway = null;
                project = null;
                currentobj = null;
                selectedobjs = null;
                if (Logger != null)
                {
                    Logger.Dispose();
                    Logger = null;
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
        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();
            }
        }
        public IInterpreterResult Main(IInterpreterMainParameters parameters)
        {
            if (parameters.config == null)
            {
                throw new ArgumentNullException("Parameter 'parameters' cannot be null.");
            }
            if (false == (parameters.config is CyPhy2CADPCB_Settings))
            {
                throw new ArgumentException("Parameter 'parameters' is not of type CyPhy2CADPCB_Settings.");
            }

            this.mainParameters = parameters;
            
            try
            {
                // Call into CyPhy2CAD.
                // - Pass same context variables.
                // - Call the Main function so that no GUI is needed.
                // - Catch the "runcommand" that they pass out.

                CyPhy2CAD_CSharp.CyPhy2CAD_CSharpInterpreter cyphy2cad = new CyPhy2CAD_CSharp.CyPhy2CAD_CSharpInterpreter()
                {
                    InteractiveMode = true,   // JS: will be false in the future
                };
                cyphy2cad.Initialize(parameters.Project);

                String auxDir = Path.Combine(parameters.ProjectDirectory,
                                             "CAD");

                var cyphy2cad_parameters = new InterpreterMainParameters()
                {
                    config = new CyPhy2CAD_CSharp.CyPhy2CADSettings()
                    {
                        OutputDirectory = parameters.OutputDirectory,
                        AuxiliaryDirectory = auxDir
                    },
                    CurrentFCO = parameters.CurrentFCO,
                    OutputDirectory = parameters.OutputDirectory,
                    Project = parameters.Project,
                    ProjectDirectory = parameters.ProjectDirectory,
                    SelectedFCOs = parameters.SelectedFCOs                    
                };

                this.Logger.WriteInfo("CyPhy2CADPCB cadauxdir [{0}]", auxDir);

                this.Logger.WriteDebug("Running CyPhy2CAD.Main(...)");
                var cyphy2cad_result = cyphy2cad.Main(cyphy2cad_parameters);
                this.Logger.WriteDebug("Completed CyPhy2CAD.Main(...)");

                this.Logger.WriteInfo("CyPhy2CADPCB Layout.json path: [{0}]", (this.mainParameters.config as CyPhy2CADPCB_Settings).GetLayoutPath);
                GenerateScriptFiles(parameters.OutputDirectory);
                GenerateRunBatFile(parameters.OutputDirectory);

                this.result.RunCommand = "runAddComponentToPcbConstraints.bat";  //cyPhy2CAD_RunCommand
                this.result.Success = true;

                this.Logger.WriteInfo("CyPhy2CADPCB finished successfully.");
            }
            catch (Exception ex)
            {
                this.result.Success = false;
                this.Logger.WriteError("CyPhy2CADPCB has failed! ", ex.ToString());
            }
            finally
            {
                this.Logger.WriteInfo("Generated files are here: <a href=\"file:///{0}\" target=\"_blank\">{0}</a>", parameters.OutputDirectory);
            }
            return this.result;
        }
        public void MainInTransaction(InterpreterMainParameters parameters)
        {
            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)
                {
                    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();
                }
            }

        }
        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);
                    }

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

                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(CyPhy2Schematic_Settings),
                                                                           this.ComponentProgID);
                CyPhy2Schematic_Settings settings = (settings_ != null) ? settings_ as CyPhy2Schematic_Settings : new CyPhy2Schematic_Settings();

                // Set configuration based on Workflow Parameters. This will override all [WorkflowConfigItem] members.
                settings = InitializeSettingsFromWorkflow(settings);
                
                // Don't skip GUI -- we've been invoked directly here.
                settings.skipGUI = null;

                // 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
            {
                if (MgaGateway != null &&
                    MgaGateway.territory != null)
                {
                    MgaGateway.territory.Destroy();
                }
                DisposeLogger();
                MgaGateway = null;
                project = null;
                currentobj = null;
                selectedobjs = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
        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);
            }

        }
        public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param)
        {
            if (this.enabled == false)
            {
                return;
            }

            try
            {
                this.Logger = new CyPhyGUIs.GMELogger(project, this.ComponentName);
                // Need to call this interpreter in the same way as the MasterInterpreter will call it.
                // initialize main parameters

                if (currentobj == null)
                {
                    this.Logger.WriteError("CyPhy2Modelica_v2 must be invoked on a Test Bench.");
                    return;
                }

                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));

                // 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 = Modelica.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(CyPhy2Modelica_v2Settings),
                    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);
            }
            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();
            }
        }