private void InitializeAgent() { //_agentRunner = new ProcRunner( "Dirigent.Agent.exe", "agent", // killOnDispose:_runGui ); // kill agent on GUi app dispose only if the gui will keep runnin (otherwise we are just the launcher of an agent and terminate immediately) //try //{ // if( _ac.ParentPid == -1 ) // _agentRunner.Launch(); // else // _agentRunner.Adopt( _ac.ParentPid ); // _agentRunner.StartKeepAlive(); //} //catch (Exception ex) //{ // log.Error(ex); // ExceptionDialog.showException(ex, "Dirigent Exception", ""); // _agentRunner = null; //} if (!_alreadyRunningTester.IsAgentAlreadyRunning()) { // istantiate the agent and tick it in its own thread try { _agent = new Agent( _ac.MachineId, _ac.MasterIP, _ac.MasterPort, PathUtils.GetRootForRelativePaths(_ac.SharedCfgFileName, _ac.RootForRelativePaths), _ac.LocalCfgFileName ); _agentThread = new Thread(() => { while (!_agent.WantsQuit) { _agent.Tick(); Thread.Sleep(_ac.TickPeriod); } _agent.Dispose(); _agent = null; }); _agentThread.Start(); } catch (Exception ex) { log.Error(ex); ExceptionDialog.showException(ex, "Dirigent Exception", ""); _agent = null; } } else { log.Error("Another instance of Dirigent Agent is already running!"); MessageBox.Show("Another instance of Dirigent Agent is already running on this machine!", "Dirigent", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
/// <summary> /// Executes a delegate and show exception window on exception /// </summary> private static void guardedOp(MethodInvoker mi) { try { mi.Invoke(); } catch (Exception ex) { log.Error(ex); ExceptionDialog.showException(ex, "Dirigent Exception", ""); } }
void ShowGUI() { if (string.IsNullOrEmpty(_ac.GuiAppExe)) { // show default GUI built in this app ShowMainForm(); } else // run external process { try { if (_guiRunner == null) { var optionReplTab = new Dictionary <string, string> { ["--clientId"] = _guiClientId }; _guiRunner = new ProcRunner(_ac.GuiAppExe, optionReplTab, true); _guiRunner.Launch(); } else // was already started { // re-launch if no longer running if (!_guiRunner.IsRunning) { _guiRunner.Launch(); } else // just tell it to unhide { _guiRunner.IsShown = true; } } } catch (Exception ex) { log.Error(ex); ExceptionDialog.showException(ex, "Dirigent Exception", ""); } } }
private void InitializeMaster() { if (_isMaster) { if (!_alreadyRunningTester.IsMasterAlreadyRunning()) { if (string.IsNullOrEmpty(_ac.SharedCfgFileName)) { var ex = new ConfigurationErrorException("SharedConfig not defined"); log.Error(ex); ExceptionDialog.showException(ex, "Dirigent Exception", ""); } // instantiate the master and tick it in its own thread _master = new Master( _ac, PathUtils.GetRootForRelativePaths(_ac.SharedCfgFileName, _ac.RootForRelativePaths) ); _masterThread = new Thread(() => { while (!_master.WantsQuit) { _master.Tick(); Thread.Sleep(_ac.MasterTickPeriod); } _master.Dispose(); _master = null; }); _masterThread.Start(); } else { log.Error("Another instance of Dirigent Master is already running!"); MessageBox.Show("Another instance of Dirigent Master is already running on this machine!", "Dirigent", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }