Exemplo n.º 1
0
        public virtual IList <DeploymentDto> getDeployments(UriInfo uriInfo, int?firstResult, int?maxResults)
        {
            DeploymentQueryDto queryDto = new DeploymentQueryDto(ObjectMapper, uriInfo.QueryParameters);

            ProcessEngine   engine = ProcessEngine;
            DeploymentQuery query  = queryDto.toQuery(engine);

            IList <Deployment> matchingDeployments;

            if (firstResult != null || maxResults != null)
            {
                matchingDeployments = executePaginatedQuery(query, firstResult, maxResults);
            }
            else
            {
                matchingDeployments = query.list();
            }

            IList <DeploymentDto> deployments = new List <DeploymentDto>();

            foreach (Deployment deployment in matchingDeployments)
            {
                DeploymentDto def = DeploymentDto.fromDeployment(deployment);
                deployments.Add(def);
            }
            return(deployments);
        }
Exemplo n.º 2
0
 public Task <DeploymentDto> Deploy(DeploymentDto deployment)
 {
     return(Post <DeploymentDto, DeploymentDto>(
                $"{BaseUri}/{RouteConstants.PREFIX}/{RouteConstants.POST_DEPLOYMENT}", deployment));
 }
Exemplo n.º 3
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     Deployment = new DeploymentDto {
         Id = new Random().Next(100)
     };
 }
Exemplo n.º 4
0
 public Task <IActionResult> Post([FromBody] DeploymentDto deployment)
 {
     return(Ok(l => l.Deploy(deployment)));
 }
Exemplo n.º 5
0
        public async Task <DeploymentDto> Deploy(DeploymentDto deployment)
        {
            var arena = await _dbContext.Arenas.SingleOrDefaultAsync(x => x.Name == deployment.ArenaName);

            if (arena == null)
            {
                throw new BusinessException($"Arena '{deployment.ArenaName}' does not exist!");
            }

            var team = await _dbContext.Teams.SingleOrDefaultAsync(x => x.Name == deployment.TeamName);

            if (team == null)
            {
                throw new BusinessException($"Team '{deployment.TeamName}' does not exist!");
            }

            var bot = await _dbContext.Bots.SingleOrDefaultAsync(x => x.Name == deployment.BotName);

            if (bot == null)
            {
                throw new BusinessException($"Bot '{deployment.BotName}' does not exist!");
            }

            if (bot.MaximumPhysicalHealth < 0 || bot.MaximumStamina < 0)
            {
                throw new BusinessException($"Number of assigned bot points is not valid!");
            }

            var assignedPoints = bot.MaximumStamina + bot.MaximumPhysicalHealth;

            if (assignedPoints > arena.MaximumPoints)
            {
                throw new BusinessException($"Number of assigned bot points ({assignedPoints}) is larger than maximum allowed ({arena.MaximumPoints})!");
            }

            if (bot.Script.Contains("CSharpCompilation"))
            {
                throw new BusinessException($"Script blocked!");
            }

            var lastDeployment = await _dbContext.Deployments
                                 .Where(x => x.Team.Id == team.Id)
                                 .OrderByDescending(x => x.DeploymentDateTime)
                                 .FirstOrDefaultAsync(x => x.Arena.Id == arena.Id);

            if (lastDeployment != null && !team.Predator)
            {
                var timeSinceLastDeployment = DateTime.UtcNow - lastDeployment.DeploymentDateTime;
                if (timeSinceLastDeployment < arena.DeploymentRestriction && !bot.Predator)
                {
                    throw new BusinessException($"Deployment restriction of {arena.DeploymentRestriction} applies!");
                }
            }

            var existingBots = await _dbContext.Deployments.Where(x => x.Arena.Id == arena.Id)
                               .Select(x => x.Bot)
                               .Where(x => x.CurrentPhysicalHealth > 0)
                               .Select(b => new { b.LocationX, b.LocationY }).ToListAsync();

            var randomGenerator = new Random();
            var locationFound   = false;

            while (!locationFound)
            {
                bot.LocationX   = (Int16)randomGenerator.Next(0, arena.Width);
                bot.LocationY   = (Int16)randomGenerator.Next(0, arena.Height);
                bot.Orientation = (Orientation)randomGenerator.Next(0, 4);
                if (!existingBots.Any(l => l.LocationX == bot.LocationX && l.LocationY == bot.LocationY))
                {
                    locationFound = true;
                }
            }

            var deploymentEntity = new Deployment
            {
                Arena = arena,
                Team  = team,
                Bot   = bot,
                DeploymentDateTime = DateTime.UtcNow
            };

            _dbContext.Deployments.Add(deploymentEntity);
            await _dbContext.SaveChangesAsync();

            await _logLogic.LogMessage(arena, deploymentEntity, bot, HistoryName.BotDeployed);

            return(deployment);
        }