private static async Task EnrichWithEnabledPlugins(Server server, IPluginRepository pluginRepository, IPluginServerRepository pluginServerRepository) { if (server != null) { var pluginsServer = await pluginServerRepository.AllByServerId(server.Id); var plugins = new List <Plugin>(); foreach (var pluginServer in pluginsServer) { plugins.Add(await pluginRepository.Get(pluginServer.PluginId)); } server.EnabledPlugins = plugins.ToArray(); } }
public async Task <Server> Add(Server server) { var servers = await _serverRepository.All(); var jars = await _jarService.GetAll(); if (servers.Any(s => s.Name == server.Name)) { throw new Exception("The name of the server must be unique."); } if (jars.All(j => j.Id != server.JarFile)) { throw new Exception("That jar file does not exist."); } var createdServer = await _serverRepository.Add(server); var libServer = _mapper.Map <Server, McWrapperLib.Server>(createdServer); libServer.ServerPath = Path.Combine(ServerPath, libServer.Id.ToString()); libServer.JarFilePath = await _jarService.GetJarPath(server.JarFile); try { var javaExecutable = (await _mcWrapperRepository.Get("JavaExecutable")).Value; libServer.JavaExecutable = javaExecutable; var result = ServerManager.CreateServer(libServer); if (result) { return(createdServer); } await _serverRepository.Remove(createdServer.Id); throw new Exception("ERROR: CONTACT CREATOR OF McWrapper!"); } catch (Exception) { await _serverRepository.Remove(createdServer.Id); throw new Exception("ERROR: There was no JavaExecutable setting found in the database."); } }