Example #1
0
        private static PuppetMaster execute(string l, PuppetMaster p)
        {
            string id;
            Uri    uri;

            string[] splited = l.Split(new char[] { ' ' });
            string   cmd     = splited[0];
            int      delay;

            switch (cmd)
            {
            case "Server":

                /*Compare here if the ip is the localhost is the same as requested ip, if it is executes below if not executes sendToPCS(l,ip,port)*/

                id = splited[1];
                if (p.getServers().ContainsKey(id))
                {
                    break;
                }

                uri = new Uri(splited[2]);
                p.getUrls().Add(uri);
                p.getNames().Add(id);
                p.getUrlsD().Add(id, uri);
                int    min_delay = Int32.Parse(splited[3]);
                int    max_delay = Int32.Parse(splited[4]);
                Server s         = new Server(id, uri, min_delay, max_delay, 1, 2);
                p.getServers().Add(id, s);
                p.setNumS(p.getNumS() + 1);

                break;

            case "Client":

                id = splited[1];
                if (p.getClients().ContainsKey(id))
                {
                    break;
                }

                uri = new Uri(splited[2]);
                string script = splited[3];

                Client c = new Client(id, uri, script, p.getUrls(), p.getNames());
                p.getClients().Add(id, c);
                break;

            /* in this next commands, check if the ip is the same as localhost, if not need to get the information from PCS*/
            case "Wait":
                Int32.TryParse(splited[1], out delay);
                System.Threading.Thread.Sleep(delay);
                break;
            }
            return(p);
        }