private void InitializeMaster() { if (AppConfig.BoolFromString(ac.isMaster)) { masterRunner = new MasterRunner(); masterRunner.MasterPort = ac.masterPort; masterRunner.CLIPort = ac.cliPort; masterRunner.StartupPlan = ac.startupPlanName; masterRunner.SharedConfigFile = ac.sharedCfgFileName; try { masterRunner.Launch(); masterRunner.StartKeepAlive(); } catch (Exception ex) { log.Error(ex); ExceptionDialog.showException(ex, "Dirigent Exception", ""); masterRunner = null; } } }
void InitializeMainForm() { log.InfoFormat("Running with machineId={0}, masterIp={1}, masterPort={2}", ac.machineId, ac.masterIP, ac.masterPort); Dirigent.Agent.Core.Agent agent; bool runningAsRemoteControlGui = (ac.machineId == "none"); string rootForRelativePaths = System.IO.Path.GetDirectoryName(System.IO.Path.GetFullPath(ac.sharedCfgFileName)); if (runningAsRemoteControlGui) // running just as observation GUI? { // we act like agent with no apps assigned // generate unique GUID to avoid matching any machineId in the launch plans string machineId = "remoteControlGui-" + Guid.NewGuid().ToString(); client = new Dirigent.Net.AutoconClient(machineId, ac.masterIP, ac.masterPort); agent = new Dirigent.Agent.Core.Agent(machineId, client, false, rootForRelativePaths); // don't go local if not connected } else // running as local app launcher { string clientId = "agent-" + ac.machineId; client = new Dirigent.Net.AutoconClient(clientId, ac.masterIP, ac.masterPort); agent = new Dirigent.Agent.Core.Agent(ac.machineId, client, true, rootForRelativePaths); InitializeFolderWatchers(agent, rootForRelativePaths); } IEnumerable <ILaunchPlan> planRepo = (ac.scfg != null) ? ac.scfg.Plans : null; // if there is some local plan repo defined, use it for local operations if (planRepo != null) { agent.LocalOps.SetPlanRepo(planRepo); } // start given plan if provided if (planRepo != null) { agent.LocalOps.SelectPlan(ac.startupPlanName); } var callbacks = new GuiAppCallbacks(); callbacks.isConnectedDeleg = client.IsConnected; callbacks.onTickDeleg = agent.tick; mainForm = new frmMain(agent.Control, planRepo, ac.machineId, client.Name, notifyIcon, !runningAsRemoteControlGui, callbacks); // restore saved location if SHIFT not held if ((Control.ModifierKeys & Keys.Shift) == 0) { string initLocation = Properties.Settings.Default.MainFormLocation; mainForm.RestoreWindowSettings(initLocation); } else // for default I just want the form to start in the top-left corner. { Point topLeftCorner = new Point(0, 0); mainForm.Location = topLeftCorner; } // if form is user-closed, don't destroy it, just hide it callbacks.onCloseDeleg += (e) => { if (e.CloseReason == CloseReason.UserClosing) { // prevent window closing e.Cancel = true; mainForm.Hide(); } }; // show the form if it should not stay hidden if (!AppConfig.BoolFromString(ac.startHidden)) { Show(); } }