コード例 #1
0
        public void run()
        {
            log.InfoFormat("Running with machineId={0}, masterIp={1}, masterPort={2}", ac.machineId, ac.masterIP, ac.masterPort);

            using (var client = new Dirigent.Net.AutoconClient(ac.machineId, ac.masterIP, ac.masterPort))
            {
                string rootForRelativePaths = System.IO.Path.GetDirectoryName(System.IO.Path.GetFullPath(ac.sharedCfgFileName));
                var    agent = new Dirigent.Agent.Core.Agent(ac.machineId, client, true, 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);
                }

                // tick forever
                while (true)
                {
                    agent.tick();
                    Thread.Sleep(500);
                }
            }
        }
コード例 #2
0
ファイル: DaemonApp.cs プロジェクト: pjanec/dirigent
        public void run()
        {
            log.InfoFormat("Running with machineId={0}, masterIp={1}, masterPort={2}", ac.machineId, ac.masterIP, ac.masterPort);

            using (var client = new Dirigent.Net.AutoconClient(ac.machineId, ac.masterIP, ac.masterPort))
            {

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

                // tick forever
                while (true)
                {
                    agent.tick();
                    Thread.Sleep(500);
                }
            }
        }
コード例 #3
0
        void InitializeFolderWatchers(Dirigent.Agent.Core.Agent agent, string rootForRelativePaths)
        {
            // no local config file loaded
            if (ac.lcfg == null)
            {
                return;
            }

            foreach (var xmlCfg in ac.lcfg.folderWatcherXmls)
            {
                var fw = new FolderWatcher(xmlCfg, agent.Control, rootForRelativePaths);
                if (fw.Initialized)
                {
                    folderWatchers.Add(fw);
                }
            }
        }
コード例 #4
0
        static int consoleAppMain()
        {
            try
            {
                var ac = getAppConfig();

                if (ac.logFileName != "")
                {
                    SetLogFileName(Path.GetFullPath(ac.logFileName));
                }

                //var planRepo = getPlanRepo(ac);

                log.InfoFormat("Running with masterIp={0}, masterPort={1}", ac.masterIP, ac.masterPort);

                // use unique client id to avoid conflict with any other possible client
                string machineId = Guid.NewGuid().ToString();
                var    client    = new Dirigent.Net.Client(machineId, ac.masterIP, ac.masterPort);

                // first connect
                client.Connect();

                // use network-only agent (never local)
                string rootForRelativePaths = System.IO.Path.GetDirectoryName(System.IO.Path.GetFullPath(ac.sharedCfgFileName));
                var    agent = new Dirigent.Agent.Core.Agent(machineId, client, false, rootForRelativePaths);

                // let the agent receive the plan repository from master
                agent.tick();

                // process the console command
                MyCommandRepo cmdRepo = new MyCommandRepo(agent.Control);
                cmdRepo.ParseAndExecute(ac.nonOptionArgs);

                return(0); // everything OK
            }
            catch (Exception ex)
            {
                log.Error(ex);
                //Console.WriteLine(string.Format("Error: {0} [{1}]", ex.Message, ex.GetType().ToString()));
                Console.WriteLine(string.Format("Error: {0}", ex.Message));
                //ExceptionDialog.showException(ex, "Dirigent Exception", "");
                return(-1);
            }
        }
コード例 #5
0
        static bool Initialize()
        {
            try
            {
                var ac = getAppConfig();

                if (AppInstanceAlreadyRunning(ac.masterPort))
                {
                    throw new Exception("Another instance of Dirigent Master is already running!");
                }

                log.InfoFormat("Master running on port {0}", ac.masterPort);

                IEnumerable <ILaunchPlan> planRepo = (ac.scfg != null) ? ac.scfg.Plans : null;

                // start a local network-only agent
                // use unique client id to avoid conflict with any other possible client
                string machineId            = Guid.NewGuid().ToString();
                var    dirigClient          = new Dirigent.Net.Client(machineId, "127.0.0.1", ac.masterPort);
                string rootForRelativePaths = System.IO.Path.GetDirectoryName(System.IO.Path.GetFullPath(ac.sharedCfgFileName));
                agent = new Dirigent.Agent.Core.Agent(machineId, dirigClient, false, rootForRelativePaths);

                // start master server
                var s = new Server(ac.masterPort, agent.Control, planRepo, ac.startupPlanName);
                // server works through its ServerRemoteObject


                dirigClient.Connect(); // connect should succeed immediately (server runs locally)

                // start a telnet client server
                log.InfoFormat("Command Line Interface running on port {0}", ac.CLIPort);
                cliServer = new CLIServer("0.0.0.0", ac.CLIPort, agent.Control);
                cliServer.Start();

                return(true);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                //ExceptionDialog.showException(ex, "Dirigent Exception", "");
                return(false);
            }
        }
コード例 #6
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");

            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();
            }
        }
コード例 #7
0
ファイル: TrayApp.cs プロジェクト: pjanec/dirigent
        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();
            }
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: pjanec/dirigent
        static int consoleAppMain()
        {
            try
            {
                var ac = getAppConfig();

                if (ac.logFileName != "")
                {
                    SetLogFileName(Path.GetFullPath(ac.logFileName));
                }

                //var planRepo = getPlanRepo(ac);

                log.InfoFormat("Running with masterIp={0}, masterPort={1}", ac.masterIP, ac.masterPort);

                // use unique client id to avoid conflict with any other possible client
                string machineId = Guid.NewGuid().ToString();
                var client = new Dirigent.Net.Client(machineId, ac.masterIP, ac.masterPort);

                // first connect
                client.Connect();

                // use network-only agent (never local)
                var agent = new Dirigent.Agent.Core.Agent(machineId, client, false);

                // let the agent receive the plan repository from master
                agent.tick();

                // process the console command
                MyCommandRepo cmdRepo = new MyCommandRepo(agent.Control);
                cmdRepo.ParseAndExecute(ac.nonOptionArgs);

                return 0; // everything OK

            }
            catch (Exception ex)
            {
                log.Error(ex);
                //Console.WriteLine(string.Format("Error: {0} [{1}]", ex.Message, ex.GetType().ToString()));
                Console.WriteLine(string.Format("Error: {0}", ex.Message));
                //ExceptionDialog.showException(ex, "Dirigent Exception", "");
                return -1;
            }
        }