public void OnCreateClientCommand(CreateClientCommand command) { CreatePartitionsIfRequired(); string username = command.Username; string url = HttpURLs.FromHostAndPort(command.Host, command.Port); // Check if client already exists if (!nameServiceDB.TryAddClient(username, url)) { Console.Error.WriteLine("Client with username {0} already exists", username); return; } PCSConnection connection = new PCSConnection(command.Host); connection.CreateClientAsync( username, command.Port, command.ScriptFile, nameServiceDB.ListServers(), config.Version) .ContinueWith(antecedent => { if (antecedent.Result) { Console.WriteLine( "[{0}] Client started at {1}:{2}", DateTime.Now.ToString("HH:mm:ss"), command.Host, command.Port); } else { // Remove inserted username if operation failed nameServiceDB.RemoveClient(username); } }); }
public void OnCreateServerCommand(CreateServerCommand command) { string serverId = command.ServerId; string url = HttpURLs.FromHostAndPort(command.Host, command.Port); // Check if server already exists if (!nameServiceDB.TryAddServer(serverId, url)) { Console.Error.WriteLine("Server with id {0} already exists", serverId); return; } PCSConnection connection = new PCSConnection(command.Host); connection.CreateServerAsync( serverId, command.Port, command.MinDelay, command.MaxDelay, config.Version) .ContinueWith(antecedent => { if (antecedent.Result) { Console.WriteLine( "[{0}] Server started at {1}:{2}", DateTime.Now.ToString("HH:mm:ss"), command.Host, command.Port); } else { // Remove inserted id if operation failed nameServiceDB.RemoveServer(serverId); } }); }