示例#1
0
        public void Read1()
        {
            LauncherFactory launcherFactory = new LauncherFactory();
            AppInitializedDetectorFactory appInitializedDetectorFactory = new AppInitializedDetectorFactory();
            var localOps = new LocalOperations("m1", launcherFactory, appInitializedDetectorFactory, null);

            localOps.SetPlanRepo(TestPlanRepo.plans.Values);

            var server = new CLIServer("127.0.0.1", 6001, localOps);

            server.Start();


            var client = new TcpClient("localhost", 6001);

            SendReq(client, "001", "StartPlan p1");
            server.Tick();
            var resp001 = ReadResp(client, 1000);


            SendReq(client, "002", "GetAppState m1.a");
            server.Tick();
            var resp002 = ReadResp(client, 1000);

            SendReq(client, "003", "GetPlanState p1");
            server.Tick();
            var resp003 = ReadResp(client, 1000);

            SendReq(client, "004", "GetAllPlansState");
            server.Tick();
            var resp004 = ReadResp(client, 1000);

            SendReq(client, "005", "GetAllAppsState");
            server.Tick();
            var resp005 = ReadResp(client, 1000);


            client.Close();


            //Assert.IsNotNull(cfg.Plans[0].getAppDefs());
            //Assert.AreEqual( "m1.a", cfg.Plans[0].getAppDefs().First().AppIdTuple.ToString() );

            server.Stop();
        }
示例#2
0
文件: Mad.cs 项目: onixion/MAD
        public static int Main(string[] args)
        {
            if (!Directory.Exists(DATADIR))
            {
                Directory.CreateDirectory(DATADIR);
            }

            if (File.Exists(CONFFILE))
            {
                try
                {
                    MadConf.LoadConf(CONFFILE);

                    Console.WriteLine("(CONFIG) Config loaded.");
                    MainWindow.configStatus = "Config loaded.";
                }
                catch (Exception e)
                {
                    Console.WriteLine("(CONFIG) Config could not be loaded: " + e.Message);
                    MadConf.SetToDefault();
                    Console.WriteLine("(CONFIG) Config could not be loaded. Using default config.");
                    MainWindow.configStatus = "Loaded default config.";
                }
            }
            else
            {
                Console.WriteLine("(CONFIG) No config file found!");
                MadConf.SetToDefault();
                Console.WriteLine("(CONFIG) Loaded default config.");
                MadConf.SaveConf(CONFFILE);
                Console.WriteLine("(CONFIG) Saved default config to '" + CONFFILE + "'.");
                Console.WriteLine("(CONFIG) Default config may not use all possible features!");
            }

            Logger.Init();
            DB        db = new DB(DBFILE);
            JobSystem js = new JobSystem(db);

            js.OnNodeCountChange += new EventHandler(ModelHost.SyncHostList);
            ModelHost.Init(ref js);
            DHCPReader dhcpReader = new DHCPReader(js);

            if (args.Length == 0)
            {
                GUI_USED = true;
                Logger.Log("Programm Start. GUI Start.", Logger.MessageType.INFORM);
                GUILogic.RunGUI(js, db, dhcpReader);
            }
            else if (args.Length == 1)
            {
                switch (args[0])
                {
                case "-cli":
                    Logger.Log("Programm Start. CLI Start.", Logger.MessageType.INFORM);
                    CLI cli = new CLI(js, dhcpReader, db);
                    cli.Start();
                    break;

                case "-cliserver":
                    Logger.Log("Programm Start. CLI Server Start.", Logger.MessageType.INFORM);
                    try
                    {
                        CLIServer cliServer = new CLIServer(js, dhcpReader, db);
                        cliServer.Start();

                        Console.WriteLine("(SERVER) Listening on port " + cliServer.serverPort + " ...");
                        Logger.Log("CLIServer started on port " + cliServer.serverPort + " ..", Logger.MessageType.INFORM);

                        Console.ReadKey(false);
                        cliServer.Stop();
                        cliServer.Dispose();

                        Console.WriteLine("(SERVER) Stopped.");
                        Logger.Log("Server stopped.", Logger.MessageType.INFORM);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("(SERVER) Could not start: " + e.Message);
                        Logger.Log("CLIServer could not start: " + e.Message, Logger.MessageType.ERROR);
                    }

                    PressAnyKeyToClose();
                    break;

                default:
                    Console.WriteLine("ERROR! Argument '" + args[0] + "' not known!");
                    Logger.Log("Programm Aborted. False Call Argument!", Logger.MessageType.EMERGENCY);
                    break;
                }
            }
            else
            {
                Console.WriteLine("ERROR! Too many arguments!");
                Logger.Log("Programm Aborted. Too many arguments!", Logger.MessageType.EMERGENCY);
                PressAnyKeyToClose();
            }

            js.Shutdown();
            db.Dispose();

            Logger.Log("Programm Exited Successfully. See Ya!", Logger.MessageType.INFORM);
            Logger.ForceWriteToLog();
            Logger.Dispose();

            if (restart)
            {
                Application.Restart();
            }

            return(0);
        }