Exemplo n.º 1
0
        public void StartClient(string username, RemotingAddress clientRA, RemotingAddress serverRA, string scriptFile)
        {
            if (Program.clientProcesses.ContainsKey(username))
            {
                throw new RemotingException($"PCS: Client with username '{ username }' already exists.");
            }

            var procPath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory() +
                                                         @"\..\..\..\Client\bin\Debug\Client.exe"));

            Console.WriteLine($"Starting client:\n\t" +
                              $"Username: {username}\n\t" +
                              $"Client URL: {clientRA.ToString()}\n\t" +
                              $"Server URL: {serverRA.ToString()}\n\t" +
                              $"Script path: {scriptFile}\n\t" +
                              $"Proc. path: {procPath}");

            Process client = RunProcess(procPath,
                                        $"{username} {clientRA.ToString()} {serverRA.ToString()} {scriptFile}");

            client.Exited += new EventHandler(delegate(Object o, EventArgs a)
            {
                Program.clientProcesses.Remove(username);
                Console.WriteLine($"Client '{username}' has exited.");
                try
                {
                    PM.InformClientExited(username);
                }
                catch (Exception ex)
                {
                    Utilities.WriteError($"Error informing PM that client exited: {ex.Message}.");
                }
            });

            Program.clientProcesses.Add(username, client);
        }