Ejemplo n.º 1
0
        private void createRes_Click(object sender, EventArgs e)
        {
            string        initiator = usersBox.Text.Split(',')[0];
            List <string> usersList = usersBox.Text.Split(',').ToList <string>();
            List <int>    slotsList = slotsBox.Text.Split(',').ToList().ConvertAll <int>(Convert.ToInt32);
            string        desc      = descBox.Text;

            ReservationRequest rr = new ReservationRequest();

            rr.Description = desc;
            rr.Users       = usersList;
            rr.Slots       = slotsList;
            IClientFacade icf = (IClientFacade)pms.getClientFacadeList()[initiator];

            try
            {
                if (icf != null)
                {
                    icf.CreateReservation(rr);  //There is an exception unhandled here.
                }
                else
                {
                    show("Unable to get Client Facade of Initiator");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("[PMS-EXCEPTION] " + ex.ToString());
            }
        }
Ejemplo n.º 2
0
        private void readCalMenuItem_Click(object sender, EventArgs e)
        {
            //fetch selected username
            string username = treeView1.SelectedNode.Text;

            if (username.Equals("Servers") || username.Equals("Clients"))
            {
                return;
            }

            string parent = treeView1.SelectedNode.Parent.Text;

            if (parent.Equals("Servers"))
            {
                MessageBox.Show("You are messing with me rite?");
            }

            else if (parent.Equals("Clients"))
            {
                ClientMetadata      cm       = (ClientMetadata)pms.getClientsList()[username];
                IClientFacade       fs       = (IClientFacade)pms.getClientFacadeList()[username];
                List <CalendarSlot> calendar = fs.ReadCalendar();

                show("Calendar for " + username + ":");
                foreach (CalendarSlot slot in calendar)
                {
                    show(slot);
                }
            }
            else
            {
                return;
            }
        }
Ejemplo n.º 3
0
        protected async Task CreateContainerAsync(IClientFacade client, INetworkSetup network)
        {
            var container = await client.GetExistingContainerAsync(Options.Name);

            ContainerId = container is null
                ? await client.CreateContainerAsync(Options, network)
                : container.Id;
        }
        public NetworkSetup(IClientFacade client)
        {
            if (client is null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            _client = client;
        }
Ejemplo n.º 5
0
        public ContainerPool(IClientFacade client, INetworkSetup network)
        {
            if (client is null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            _client  = client;
            _network = network;
        }
Ejemplo n.º 6
0
        public async Task DiscardAsync(IClientFacade client)
        {
            if (ContainerId == null || !Options.RemoveContainerOnExit)
            {
                return;
            }

            await client.KillContainerAsync(ContainerId);

            await client.RemoveContainerAsync(ContainerId);
        }
Ejemplo n.º 7
0
        public virtual async Task ConfigureAsync(IClientFacade client, INetworkSetup network)
        {
            try
            {
                if (network != default)
                {
                    await network.CreateNetworkAsync();
                }

                var existingContainer = await client.GetExistingContainerAsync(Options.Name);

                if (existingContainer == default)
                {
                    await DownloadImageAsync(client);
                    await CreateContainerAsync(client, network);
                }
                else
                {
                    ContainerId = existingContainer.Id;
                }

                if (!existingContainer?.IsRunning ?? true)
                {
                    await client.StartContainerAsync(ContainerId);
                }

                await WaitContainerAsync();

                DefineAsReady();
            }
            catch (DockerApiException ex)
            {
                if (ex.Message.Contains("code=Conflict"))
                {
                    await WaitContainerAsync();

                    DefineAsReady();
                }
                else
                {
                    throw new InvalidOperationException("Something unexpected happened during image setup.", ex);
                }
            }
        }
Ejemplo n.º 8
0
        public bool registerClient(string username, string ip_addr, int port)
        {
            //creating a ClientMetadata object to store client information
            ClientMetadata cm = new ClientMetadata();

            cm.Username = username;
            cm.IP_Addr  = ip_addr;
            cm.Port     = port;

            //adding the client metadata to the global hashtable so that it can be used later on
            clients_list.Add(username, cm);

            IClientFacade facadeService = connectToClientFacadeService(cm);

            clientFacadeList.Add(username, facadeService);

            //update the Clients tree in PuppetGUI
            Gui.updateClientsTree(cm, null);

            return(true);
        }
Ejemplo n.º 9
0
        private IClientFacade connectToClientFacadeService(ClientMetadata cm)
        {
            //connect to PuppetMaster here
            String connectionString = "tcp://" + cm.IP_Addr + ":" + cm.Port + "/" + cm.Username + "/" + Common.Constants.CLIENT_FACADE_SERVICE;

            IDictionary RemoteChannelProperties = new Dictionary <string, string>();

            RemoteChannelProperties["name"] = cm.Username;

            TcpChannel client_channel = new TcpChannel(RemoteChannelProperties, null, null);

            ChannelServices.RegisterChannel(client_channel, true);

            //TODO: uncomment and fix this to make it work
            IClientFacade facadeService = (IClientFacade)Activator.GetObject(
                typeof(IClientFacade),
                connectionString);


            return(facadeService);
        }
Ejemplo n.º 10
0
        private void connectMenuItem_Click(object sender, EventArgs e)
        {
            //fetch selected username
            string username = treeView1.SelectedNode.Text;

            if (username.Equals("Servers") || username.Equals("Clients"))
            {
                return;
            }

            string parent = treeView1.SelectedNode.Parent.Text;


            if (parent.Equals("Servers"))
            {
                ServerMetadata sm  = (ServerMetadata)pms.getServersList()[username];
                IServerFacade  isf = (IServerFacade)pms.getServerFacadeList()[username];
                isf.Connect(); /*commented because Server Facade is not implemented yet*/
                //show(username + " is now connected");
                treeView1.SelectedNode.ImageIndex         = 0;
                treeView1.SelectedNode.SelectedImageIndex = 0;
            }

            else if (parent.Equals("Clients"))
            {
                ClientMetadata cm = (ClientMetadata)pms.getClientsList()[username];
                IClientFacade  fs = (IClientFacade)pms.getClientFacadeList()[username];
                fs.Connect(); //EXCEPTION UNHANDLED - WASIF CHECK THIS
                show(username + " has been connected");
                treeView1.SelectedNode.ImageIndex         = 0;
                treeView1.SelectedNode.SelectedImageIndex = 0;
            }
            else
            {
                return;
            }
        }
 public ClientController(IClientFacade clientFacade)
 {
     _clientFacade = clientFacade;
 }
Ejemplo n.º 12
0
        private void readEventFileAndDispatchEvents()
        {
            string line = string.Empty;

            System.IO.StreamReader sr = new
                                        System.IO.StreamReader(openFileDialog1.FileName);
            while ((line = sr.ReadLine()) != null)
            {
                show(line);
                string              opcode = line.Split(' ')[0];
                string              username;
                IClientFacade       icf;
                IServerFacade       sf;
                List <CalendarSlot> clientCalendar;
                //TODO: fetch initiator from Users list

                switch (opcode)
                {
                case "disconnect":
                    username = line.Split(' ')[1];

                    if (username.StartsWith("central"))
                    {
                        ServerMetadata sm  = (ServerMetadata)pms.getServersList()[username];
                        IServerFacade  isf = (IServerFacade)pms.getServerFacadeList()[username];
                        while (isf == null)
                        {
                            show("Trying to disconnect server: " + username);
                            isf = (IServerFacade)pms.getServerFacadeList()[username];
                            Thread.Sleep(100);
                        }

                        try
                        {
                            isf.Disconnect();
                            changeIconToDisconnected(username, null);
                        }
                        catch (Exception ioe)
                        {
                            MessageBox.Show(ioe.ToString());
                        }
                    }
                    else
                    {
                        icf = (IClientFacade)pms.getClientFacadeList()[username];
                        while (icf == null)
                        {
                            show("Trying to disconnect client: " + username);
                            icf = (IClientFacade)pms.getClientFacadeList()[username];
                            Thread.Sleep(1000);
                        }

                        try
                        {
                            icf.Disconnect();
                        }
                        catch (Exception ee)
                        {
                            show("Exception: " + ee.Message);
                        }

                        changeIconToDisconnected(username, null);
                    }
                    break;


                case "connect":

                    username = line.Split(' ')[1].Trim();
                    string ip   = line.Split(' ')[2].Split(':')[0].Trim();
                    int    port = Convert.ToInt32(line.Split(' ')[2].Split(':')[1]);

                    icf = (IClientFacade)pms.getClientFacadeList()[username];
                    sf  = (IServerFacade)pms.getServerFacadeList()[username];

                    if (icf != null)     //means the client has already been created
                    {
                        show("Trying to reconnect to client: " + username);
                        icf.Connect();
                        changeIconToConnected(username, null);
                    }

                    else if (sf != null)
                    {
                        show("Reconnecting to server: " + username);
                        sf.Connect();
                        changeIconToConnected(username, null);
                    }
                    else     //means a new process needs to be started
                    {
                        if (username.StartsWith("central"))
                        {
                            string           path      = server_dir;
                            ProcessStartInfo startInfo = new ProcessStartInfo();


                            startInfo.FileName    = path + "Server.exe";
                            startInfo.Arguments   = username + " " + port;
                            startInfo.WindowStyle = ProcessWindowStyle.Minimized;
                            Process process = new Process();
                            process.StartInfo = startInfo;
                            process.Start();
                            processes.Add(process);


                            //TODO: save the PIDS of all processes and kill them on exit

                            //if server  is online, we move on to the next event. If not, we wait until the server is online
                            IServerFacade isf = (IServerFacade)pms.getServerFacadeList()[username];
                            while (isf == null)
                            {
                                Thread.Sleep(500);
                                isf = (IServerFacade)pms.getServerFacadeList()[username];
                            }
                        }
                        else     //means its a client
                        {
                            string           path      = client_dir;
                            ProcessStartInfo startInfo = new ProcessStartInfo();

                            startInfo.FileName    = path + "Client.exe";
                            startInfo.Arguments   = username + " " + port;
                            startInfo.WindowStyle = ProcessWindowStyle.Minimized;
                            Process process = new Process();
                            process.StartInfo = startInfo;
                            process.Start();
                            processes.Add(process);

                            //if client  is online, we move on to the next event. If not, we wait until the client is online
                            IClientFacade cf = (IClientFacade)pms.getClientFacadeList()[username];
                            while (cf == null)
                            {
                                Thread.Sleep(500);
                                cf = (IClientFacade)pms.getClientFacadeList()[username];
                            }
                        }
                    }

                    break;

                case "readCalendar":
                    username = line.Split(' ')[1].Trim();
                    icf      = (IClientFacade)pms.getClientFacadeList()[username];
                    try
                    {
                        clientCalendar = icf.ReadCalendar();
                        show("Calendar for " + username + ":");
                        foreach (CalendarSlot slot in clientCalendar)
                        {
                            show(slot);
                        }
                    }
                    catch (Exception ee)
                    {
                        show("Exception: " + ee.Message);
                    }
                    break;

                case "reservation":
                    //reservation {GroupMeeting; user1, user2; 13, 25 }
                    string        data      = line.Split('{')[1].Split('}')[0].Trim();
                    string        desc      = data.Split(';')[0].Trim();
                    string        initiator = data.Split(';')[1].Split(',')[0].Trim();
                    List <string> usersList = data.Split(';')[1].Trim().Split(',').Select(s => s.Trim()).ToList <string>();
                    List <int>    slotsList = data.Split(';')[2].Trim().Split(',').Select(s => s.Trim()).ToList <string>().ConvertAll <int>(Convert.ToInt32);

                    ReservationRequest rr = new ReservationRequest();
                    rr.Description = desc;
                    rr.Users       = usersList;
                    rr.Slots       = slotsList;
                    icf            = (IClientFacade)pms.getClientFacadeList()[initiator];
                    while (icf == null)
                    {
                        show("Trying to reconnect to initiator: " + initiator);
                        icf = (IClientFacade)pms.getClientFacadeList()[initiator];
                        Thread.Sleep(100);
                    }

                    try
                    {
                        icf.CreateReservation(rr);
                    }
                    catch (Exception e)
                    {
                        show("Error on create reservation: " + e.Message);
                    }

                    Thread.Sleep(1000);
                    break;

                case "wait":
                    int seconds = Convert.ToInt32(line.Split(' ')[1].Trim());
                    show("Sleeping for " + seconds + " second(s)");
                    Thread.Sleep(seconds * 1000);
                    break;

                case "shutdown":
                    show("Shutting down all processes in 2 seconds");
                    Thread.Sleep(2000);


                    //killing all clients
                    foreach (Process pp in processes)
                    {
                        string userName = pp.StartInfo.Arguments.Split(' ')[0].Trim();

                        if (!userName.StartsWith("central"))
                        {
                            ((IClientFacade)pms.getClientFacadeList()[userName]).Disconnect();
                            pp.Kill();
                            removeNodeFromTreeView(userName, null);
                            show("Killed " + pp.StartInfo.Arguments);
                        }
                    }

                    //killing all servers
                    foreach (Process p in processes)
                    {
                        string userName = p.StartInfo.Arguments.Split(' ')[0].Trim();

                        if (userName.StartsWith("central"))
                        {
                            try
                            {
                                ((IServerFacade)pms.getServerFacadeList()[userName]).Disconnect();
                            }
                            catch (Exception ee)
                            {
                                show(ee.Message);
                            }
                            p.Kill();
                            removeNodeFromTreeView(userName, null);
                            show("Killed " + p.StartInfo.Arguments);
                        }
                    }

                    //cleaning up
                    pms.cleanUp();

                    //RemotingServices.Unmarshal(objRef);
                    //objRef = null;
                    //pms = null;

                    processes.Clear();

                    //unregistering channels
                    UnregisterChannels();

                    show(" ");
                    show("----------------------SHUTDOWN COMPLETE--------------------");
                    show(" ");
                    break;
                }
            }

            sr.Close();
        }
Ejemplo n.º 13
0
 public ClientApiController(IClientFacade clientFacade)
 {
     this._clientFacade = clientFacade;
 }
Ejemplo n.º 14
0
 public ClientController()
 {
     this.clientFacade = new ClientFacade();
 }
Ejemplo n.º 15
0
 protected virtual async Task DownloadImageAsync(IClientFacade client)
 => await client.DownloadImageAsync(Options.ImageName, Options.ImageTag);
Ejemplo n.º 16
0
 public ClientsController(ILogger <ClientsController> logger, IClientFacade clientFacade, IAccountFacade accountFacade)
 {
     this._logger        = logger;
     this._clientFacade  = clientFacade;
     this._accountFacade = accountFacade;
 }
Ejemplo n.º 17
0
 public AppNetworkSetup(IClientFacade client)
     : base(client)
 {
 }