Esempio n. 1
0
        void DeinitializeMainForm()
        {
            if (mainForm != null)
            {
                // save main form's location and size
                if ((Control.ModifierKeys & Keys.Shift) == 0)
                {
                    mainForm.SaveWindowSettings("MainFormLocation");
                }

                mainForm.Close();
                mainForm.Dispose();
                mainForm = null;
            }

            if (client != null)
            {
                client.Dispose();
                client = null;
            }
        }
Esempio n. 2
0
        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");

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

            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)
            {
                ILaunchPlan startupPlan = AppHelper.GetPlanByName(planRepo, ac.startupPlanName);
                if (startupPlan != null)
                {
                    agent.LocalOps.SelectPlan(startupPlan);
                }
            }

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