コード例 #1
0
        public async Task GetServerByIdTest()
        {
            // Arrange
            await _repo.AddServer(fooServer1);

            // Act
            var server = await _repo.GetServerById(fooServer1.Id);

            await _repo.RemoveServer(fooServer1.Id);

            // Assert
            Assert.NotNull(server);
            Assert.Equal(fooServer1.Id, server.Id);
        }
コード例 #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);
        }
コード例 #3
0
        public R.ResultVm <bool> AddServer(ServerOnlyVm server)
        {
            var rv = new ResultVm <bool>().FromEmptyFailure();

            Demand <string> .That(server.Name, "server.Name").HasNonEmptyValue().Result(rv);

            if (rv.Errors.Count == 0)
            {
                try
                {
                    return(new ResultVm <bool>().FromSuccessObject(_repo.AddServer(server.ToDataModel())));
                }
                catch (Exception ex)
                {
                    return(new ResultVm <bool>().FromException(ex));
                }
            }
            else
            {
                return(rv);
            }
        }