private void StartAssemblyExe(CreoOpenMode mode, string guid, bool isComponentAssembly, string exeparams, string workingDir = null) { SyncedComponentData syncedCompData = null; if (!syncedComponents.TryGetValue(guid, out syncedCompData)) { GMEConsole.Warning.WriteLine("StartAssemblyExe(): Can't find guid " + guid); return; } string createAssemblyExe = Path.Combine(META.VersionInfo.MetaPath, "bin", "CAD", "Creo", "bin", "CADCreoParametricMetaLink.exe"); if (File.Exists(createAssemblyExe) == false) { GMEConsole.Error.WriteLine(String.Format("Could not find CADCreoParametricMetaLink.exe at '{0}'", createAssemblyExe)); return; } if (workingDir == null) { workingDir = syncedCompData.WorkingDir; } try { File.Copy(Path.Combine(GetProjectDir(), "constraintdata.xml"), Path.Combine(workingDir, "constraintdata.xml")); } catch (Exception) { // not an issue } string logfile = Path.Combine(GetProjectDir(), "log", Path.ChangeExtension("MetaLink_CreoCreateAssembly_" + Path.GetRandomFileName(), "log")); string arguments = String.Format("-v debug -g -s 127.0.0.1:{4} -w \"{0}\" -l \"{1}\" {2}, -id {3}", workingDir, logfile, exeparams, syncedCompData.InstanceId, SocketQueue.port); arguments += " -d " + guid; ProcessStartInfo info = new ProcessStartInfo() { RedirectStandardOutput = true, RedirectStandardError = true, RedirectStandardInput = true, UseShellExecute = false, WindowStyle = ProcessWindowStyle.Hidden, CreateNoWindow = true, FileName = createAssemblyExe, Arguments = arguments // TODO -p ? }; if (mode == CreoOpenMode.OPEN_EMPTY) { info.Arguments += " -m passive"; } else if (!isComponentAssembly) { info.Arguments += " -m component"; } if (Configuration.ConfigProFile.Length > 0) { info.Arguments += " -c " + Configuration.ConfigProFile; } if (!string.IsNullOrWhiteSpace(syncedCompData.AuxDir)) { info.Arguments += String.Format(" -a \"{0}\"", syncedCompData.AuxDir); } Process createAssembly = new Process(); createAssembly.StartInfo = info; StringBuilder stdoutData = new StringBuilder(); StringBuilder stderrData = new StringBuilder(); createAssembly.OutputDataReceived += (o, args) => { lock (stdoutData) { stdoutData.Append(args.Data); stdoutData.Append(System.Environment.NewLine); } }; createAssembly.ErrorDataReceived += (o, args) => { lock (stderrData) { stderrData.Append(args.Data); stderrData.Append(System.Environment.NewLine); } }; createAssembly.EnableRaisingEvents = true; createAssembly.Exited += (o, args) => { lock (stderrData) { if (GMEConsole != null && createAssembly.ExitCode != 0) { string message = String.Format("CADCreoParametricMetaLink exited with code {0}", createAssembly.ExitCode); // CADCreoParametricMetaLink attempts to log everything in its log file // Ignore stderr if it doesn't contain anything useful string stdErrString = stderrData.ToString(); if (Regex.Match(stdErrString, "\\S").Success) { string errlog = "CADCreoParametricCreateAssembly_err.log"; using (StreamWriter writer = new StreamWriter(errlog)) { writer.Write(stdErrString); writer.Close(); } message += String.Format(", the logfile is {0} ", errlog); } GMEConsole.Error.WriteLine(message); SyncControl.Invoke((System.Action)(() => StartupFailureCallback(stdErrString, logfile))); } } }; LastStartedInstance = syncedCompData; createAssembly.Start(); if (TestMode_CreoJobObject != IntPtr.Zero) { JobObjectPinvoke.AssignProcessToJobObject(createAssembly, TestMode_CreoJobObject); } createAssembly.BeginOutputReadLine(); createAssembly.BeginErrorReadLine(); createAssembly.StandardInput.Close(); GMEConsole.Info.WriteLine("Creo is starting, the logfile is " + SmartLogger.GetGMEConsoleFileLink(logfile)); ShowStartupDialog(true); // createAssembly.WaitForExit(10 * 1000); }
public bool Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode) { this.Logger.WriteInfo("CyPhyElaborate 2.0 started."); PumpMessages(); bool success = this.Check(currentobj); if (success == false) { this.Logger.WriteError("CyPhyElaborate 2.0 context is invalid."); return(success); } System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); try { this.ElaborateContext(currentobj); } catch (ElaboratorException ex) { this.Logger.WriteError(ex.Message); this.Logger.WriteError("CyPhyElaborate 2.0 finished with errors."); PumpMessages(); // make sure we abort the transaction throw ex; } catch (NotSupportedException ex) { this.Logger.WriteError(ex.Message); this.Logger.WriteError("CyPhyElaborate 2.0 finished with errors."); PumpMessages(); throw ex; } sw.Stop(); this.Logger.WriteDebug("Time: {0}", sw.Elapsed.ToString("c")); sw.Restart(); this.Logger.WriteInfo("CyPhyFormulaEvaluator 1.0 started"); try { // create formula evaluator type // FIXME: calling the elaborator is faster than calling the formula evaluator Type typeFormulaEval = Type.GetTypeFromProgID("MGA.Interpreter.CyPhyFormulaEvaluator"); IMgaComponentEx formulaEval = Activator.CreateInstance(typeFormulaEval) as IMgaComponentEx; // empty selected object set Type typeMgaFCOs = Type.GetTypeFromProgID("Mga.MgaFCOs"); MgaFCOs selectedObjs = Activator.CreateInstance(typeMgaFCOs) as MgaFCOs; // initialize formula evauator formulaEval.Initialize(project); // automation means no UI element shall be shown by the interpreter formulaEval.ComponentParameter["automation"] = "true"; // do not write to the console formulaEval.ComponentParameter["console_messages"] = "off"; // do not expand nor collapse the model formulaEval.ComponentParameter["expanded"] = "true"; // do not generate the post processing python scripts // FIXME: Why should we generate them ??? formulaEval.ComponentParameter["do_not_generate_post_processing"] = "true"; formulaEval.ComponentParameter["traceability"] = Traceability; // call the formula evaluator and update all parameters starting from the current object try { formulaEval.InvokeEx(project, currentobj, selectedObjs, 128); numericLeafNodes = (string[])formulaEval.ComponentParameter["numericLeafNodes"]; this.Logger.WriteInfo("CyPhyFormulaEvaluator 1.0 finished"); } catch (COMException e) { success = false; this.Logger.WriteError(e.Message); this.Logger.WriteError("CyPhyFormulaEvaluator 1.0 finished with errors"); } } catch (Exception ex) { this.Logger.WriteInfo("CyPhyFormulaEvaluator 1.0 failed"); this.Logger.WriteDebug(ex.ToString()); } sw.Stop(); this.Logger.WriteDebug("Formula evaluator runtime: {0}", sw.Elapsed.ToString("c")); if (UnrollConnectors) { sw.Restart(); this.Logger.WriteInfo("ConnectorUnroller started"); try { var kindCurrentObj = currentobj.MetaBase.Name; if (kindCurrentObj == "ComponentAssembly") { using (Unroller unroller = new Unroller(currentobj.Project, Traceability, Logger)) { unroller.UnrollComponentAssembly(currentobj as MgaModel); } } else if (kindCurrentObj == "TestBench") { using (Unroller unroller = new Unroller(currentobj.Project, Traceability, Logger)) { unroller.UnrollTestBench(currentobj as MgaModel); } } this.Logger.WriteInfo("ConnectorUnroller finished"); } catch (Exception ex) { this.Logger.WriteInfo(ex.Message); this.Logger.WriteDebug(ex.ToString()); this.Logger.WriteError("ConnectorUnroller failed. Check " + SmartLogger.GetGMEConsoleFileLink(this.Logger.LogFilenames[0], "detailed log") + " for details."); success = false; } sw.Stop(); this.Logger.WriteDebug("ConnectorUnroller runtime: {0}", sw.Elapsed.ToString("c")); } this.Logger.WriteInfo("CyPhyElaborate 2.0 finished."); PumpMessages(); return(success); }