Пример #1
0
        public async Task GetServerByNameTest()
        {
            // Arrange
            await _repo.AddServer(fooServer1);

            // Act
            var server = await _repo.GetServerByName(fooServer1.Name);

            await _repo.RemoveServer(fooServer1.Id);

            // Assert
            Assert.NotNull(server);
            Assert.Equal(fooServer1.Name, server.Name);
        }
Пример #2
0
        public async Task <MinecraftServer> NewServer(string name)
        {
            var server = await _repo.GetServerByName(name);

            if (server != null)
            {
                // TODO: Add better error handling here
                throw new Exception("Server already exists");
            }
            server = new MinecraftServer()
            {
                Id          = ObjectId.GenerateNewId().ToString(),
                DateCreated = DateTime.UtcNow,
                IsRunning   = false,
                Name        = name,
                MaxRamMB    = 2048,
                MinRamMB    = 2048,
                TimesRan    = 0,
            };

            // Build the server path
            var buildPath       = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var serverDirectory = Directory.CreateDirectory(Path.Combine(buildPath, server.Id));

            server.ServerPath = serverDirectory.FullName;

            // Copy in server jar
            var serverJarPath = Path.Combine(serverDirectory.FullName, "server.jar");
            var jarPath       = Path.Combine(buildPath, "LargeFiles", "server.jar");

            File.Copy(jarPath, serverJarPath, true);

            // Copy in eula
            var eulaPath    = Path.Combine(buildPath, server.Id, "eula.txt");
            var newEulaPath = Path.Combine(buildPath, "LargeFiles", "eula.txt");

            File.Copy(newEulaPath, eulaPath, true);

            // Set server properties of db object
            var properties = new ServerProperties();

            server.Properties = properties as Properties;

            // Add server to database
            await _repo.AddServer(server);

            return(server);
        }