Esempio n. 1
0
        private void crashBtn_Click(object sender, EventArgs e)
        {
            if (serverListBox.SelectedItem == null || serverListBox.SelectedItem.ToString() == "")
            {
                MessageBox.Show("Must select a server from the list.");
                return;
            }

            string serverID = serverListBox.SelectedItem.ToString();

            IServerPM server = Program.GetServer(serverID);

            if (server == null)
            {
                MessageBox.Show($"Server '{serverID}' is disconnected.");
                Program.RemoveServerFromList(serverID);
                return;
            }

            try
            {
                server.Crash();
            }
            catch (System.Net.Sockets.SocketException)
            {
                MessageBox.Show($"Server '{serverID}' has been crashed.");
                Program.RemoveServerFromList(serverID);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Esempio n. 2
0
        private static IServerPM ConnectToServer(string serverID, RemotingAddress serverRA)
        {
            if (!serverList.Exists(x => x.Item2 == serverRA))
            {
                if (serverList.Exists(x => x.Item1 == serverID))
                {
                    throw new ApplicationException($"Server with ID '{serverID}' already exists.");
                }

                IServerPM server = (IServerPM)Activator.GetObject(typeof(IServerPM), serverRA.ToString());
                if (server == null)
                {
                    throw new ApplicationException("Could not locate Server: " + serverRA.ToString());
                }

                serverList.Add(new Tuple <string, RemotingAddress, IServerPM>(serverID, serverRA, server));
                //Add server to replication servers list
                remoteServerList.Add(new Tuple <string, RemotingAddress>(serverID, serverRA));

                return(server);
            }
            else
            {
                throw new ApplicationException("Already connected to server: " + serverRA.ToString());
            }
        }
Esempio n. 3
0
        private void addRoomBtn_Click(object sender, EventArgs e)
        {
            if (serverListBox.SelectedItem == null || serverListBox.SelectedItem.ToString() == "")
            {
                MessageBox.Show("Must select a server from the list.");
                return;
            }

            string serverID = serverListBox.SelectedItem.ToString();

            if (nameTb.Text == "")
            {
                MessageBox.Show("Room name cannot be empty.");
                return;
            }

            if (locationCb.Text == "")
            {
                MessageBox.Show("Room location cannot be empty.");
                return;
            }

            if (capacityNUD.Value < 1)
            {
                MessageBox.Show("Room capacity must be bigger than 0.");
                return;
            }

            string name     = nameTb.Text;
            string location = locationCb.Text;
            uint   capacity = Convert.ToUInt32(capacityNUD.Value);

            IServerPM server = Program.GetServer(serverID);

            if (server == null)
            {
                MessageBox.Show($"Server '{serverID}' is disconnected.");
                Program.RemoveServerFromList(serverID);
                return;
            }

            try
            {
                server.AddRoom(location, capacity, name);
            }
            catch (System.Net.Sockets.SocketException)
            {
                MessageBox.Show($"Server '{serverID}' is disconnected.");
                Program.RemoveServerFromList(serverID);
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            MessageBox.Show($"Room '{name}' for {location} has been created.");
        }
Esempio n. 4
0
        public static void CreateServer(string serverID, RemotingAddress serverRA,
                                        uint maxFaults, uint minDelay, uint maxDelay)
        {
            if (serverList.Exists(x => x.Item1 == serverID))
            {
                throw new ApplicationException($"Server with ID '{serverID}' already exists.");
            }

            RemotingAddress pcsRA = new RemotingAddress(serverRA.address, PCSPort, PCSChannel);

            IPCS pcs = GetPCS(pcsRA);

            try
            {
                pcs.StartServer(serverID, serverRA, maxFaults, minDelay, maxDelay);
            }
            catch (System.Net.Sockets.SocketException)
            {
                MessageBox.Show($"Connection with PCS on remoting address '{pcsRA.ToString()}' was lost.\n" +
                                "If the PCS has been restarted you may try again.");
                Program.RemovePCSFromList(pcsRA);
                return;
            }

            IServerPM server = ConnectToServer(serverID, serverRA);

            //Replication
            //Inform new server of all existing servers
            server.SendExistingServersList(remoteServerList);
            //Inform all existing servers of new server
            foreach (Tuple <string, RemotingAddress, IServerPM> serv in serverList)
            {
                serv.Item3.BroadcastNewServer(new Tuple <string, RemotingAddress>(serverID, serverRA));
            }


            // Fill location list
            if (serverList.Count == 1)
            {
                mainForm.manageServersPage.FillLocationCb(server.GetLocationsPM());
            }

            mainForm.manageServersPage.AddServerToList(serverID);
        }
Esempio n. 5
0
        public void ExecCommands()
        {
            foreach (var command in commands)
            {
                MessageBox.Show("PM Will Execute... " + command[0]);

                if (command[0].Equals("crash", StringComparison.OrdinalIgnoreCase))
                {
                    IServerPM server = Program.GetServer(command[1]);

                    try
                    {
                        server.Crash();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        //return;
                    }
                }
                else if (command[0].Equals("freeze", StringComparison.OrdinalIgnoreCase))
                {
                    IServerPM server = Program.GetServer(command[1]);

                    try
                    {
                        server.Freeze();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        //return;
                    }
                }
                else if (command[0].Equals("unfreeze", StringComparison.OrdinalIgnoreCase))
                {
                    IServerPM server = Program.GetServer(command[1]);

                    try
                    {
                        server.Unfreeze();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        //return;
                    }
                }
                else if (command[0].Equals("wait", StringComparison.OrdinalIgnoreCase))
                {
                    Utilities.Wait(Int32.Parse(command[1]));
                }
                else if (command[0].Equals("status", StringComparison.OrdinalIgnoreCase))
                {
                    Program.PrintStatus();
                }
                else if (command[0].Equals("server", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        Program.CreateServer(command[1], RemotingAddress.FromString(command[2]),
                                             Convert.ToUInt32(command[3]), Convert.ToUInt32(command[4]), Convert.ToUInt32(command[5]));
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show($"Error creating server: {ex.Message}",
                                        "Error",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                        //return;
                    }
                }
                else if (command[0].Equals("client", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        Program.CreateClient(command[1], RemotingAddress.FromString(command[2]),
                                             RemotingAddress.FromString(command[3]), command[4]);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show($"Error creating client: {ex.Message}",
                                        "Error",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                        //return;
                    }
                }
                else if (command[0].Equals("AddRoom", StringComparison.OrdinalIgnoreCase))
                {
                    if (Program.serverList.Count == 0)
                    {
                        MessageBox.Show($"Cannot add room '{command[3]}' because there are no servers running.",
                                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        continue;//return;
                    }

                    try
                    {
                        Program.serverList[0].Item3.AddRoom(command[1], Convert.ToUInt32(command[2]), command[3]);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        //return;
                    }
                }

                foreach (string s in command)
                {
                    Utilities.WriteDebug(s + " ");
                }
                Console.Write("\r\n");

                //MessageBox.Show("PM Executed: " + command[0]);
            }
        }