/// <summary> /// Sends the updates for a <see cref="Region"/> /// </summary> /// <param name="player">The player.</param> /// <param name="position">The position.</param> /// <param name="differences">The differences.</param> /// <param name="full">The HashSet of <see cref="RegionCoordinates"/> of regions that require a full update.</param> /// <param name="encodes">The HashSet of <see cref="RegionCoordinates"/> of regions that changed.</param> /// <param name="updates">The HashSet of <see cref="RegionCoordinates"/> of regions that require a update.</param> private async Task SendUpdates(Player player, Position position, HashSet <RegionCoordinates> differences, HashSet <RegionCoordinates> full, Dictionary <RegionCoordinates, HashSet <RegionUpdateMessage> > encodes, Dictionary <RegionCoordinates, HashSet <RegionUpdateMessage> > updates) { IRegionRepository repository = _regionRepository; int height = position.Height; foreach (RegionCoordinates coordinates in differences) { var updatesMsgs = repository.Get(coordinates).GetUpdates(height); var messages = updates.TryAdd(coordinates, updatesMsgs); if (messages) { await player.SendAsync(new GroupedRegionUpdateMessage(position, coordinates, updatesMsgs)); } } foreach (RegionCoordinates coordinates in full) { var addMessages = repository.Get(coordinates).Encode(height); var added = encodes.TryAdd(coordinates, addMessages); if (added) { await _protoMessageSender.SendAsync(player, new ClearRegionMessage { LocalX = position.LocalX, LocalY = position.LocalX }); await player.SendAsync(new GroupedRegionUpdateMessage(position, coordinates, addMessages)); } } }
public async Task ComUmaDiferenca() { var first = regionRepository.Get(1); regionRepository.Delete(first); regionRepository.Create(new Region(1, "V", "Vorte")); var result = await regionDiffServices.Get(); Assert.NotEmpty(result.Diffs); }
public IActionResult GetRegion(long id) { var region = _repository.Get(id); var regionDto = RegionDetailsDto.MapFromEntity(region); return(Ok(regionDto)); }
// GET: Municipio/Edit/5 public ActionResult Edit(int id) { try { var listMunicipio = repoMunicipio.List(); var m = repository.Get(id); IEnumerable <Municipio> list = (from lm in listMunicipio join rm in m.RegionMunicipio on lm.Id equals rm.MunicipioId into a from x in a.DefaultIfEmpty() select new Municipio { Id = lm.Id, Name = lm.Name, StatusId = x != null ? 2 : lm.StatusId }).ToList().Where(x => x.StatusId == 1); RegionViewModel model = new RegionViewModel { Region = m, ListMunicipio = list }; return(View(model)); } catch (Exception ex) { TempData["message"] = $"Error: {ex.Message}"; return(View("List")); } }
/// <summary> /// The GetRegion /// </summary> /// <param name="id">The id<see cref="int"/></param> /// <returns>The <see cref="ServiceResult"/></returns> public ServiceResult GetRegion(int id) { return(new ServiceResult(true) { Data = _repository.Get(x => x.Identifier == id) }); }
public RegionHandlerTests() { var context = new FakeContext(); _repository = new RegionRepository(context); context.RemoveRange(_repository.Get()); handlerValid = new RegionHandler(_repository); handlerValid.Handle(secondValidCommand); }
public BaseResult <List <RegionModel.Region> > Get() { try { var regions = _regionRepository.Get(); return(BaseResult <List <RegionModel.Region> > .OK(regions)); } catch (Exception e) { return(BaseResult <List <RegionModel.Region> > .NotOK(e.Message)); } }
public async Task <RegionDiffServices> Get() { var local = _repository.Get(); var request = await _ibgeRepository.Get(IbgeEndPoints.RegionUrl); var ibge = AutoMapperConfiguration.Mapper.Map <List <Region> >(request); regionDiff = new RegionDiff(local, ibge); this.Diffs = regionDiff.GetDiffs(); this.IbgeNonexistent = regionDiff.GetNonexistentsInIbge(); this.LocalNonexistent = regionDiff.GetNonexistentInLocal(); return(this); }
public RegionDiffServicesTests() { httpClient = new HttpClient(); regionIbgeRepository = new RegionIbgeRepository(httpClient); context = new FakeContext(); regionRepository = new RegionRepository(context); context.Region.RemoveRange(regionRepository.Get()); local = new List <Region>() { new Region(1, "N", "Norte"), new Region(2, "NE", "Nordeste"), new Region(3, "SE", "Sudeste"), new Region(4, "S", "Sul"), new Region(5, "CO", "Centro-Oeste") }; local.ForEach(x => regionRepository.Create(x)); regionDiffServices = new RegionDiffServices(regionIbgeRepository, regionRepository); }
public IActionResult Index(int Id = 0) { var region = new Region_VM(); if (Id > 0) { region = _regionRepository.Get(Id); if (region == null) { return(RedirectToAction("List", "Region")); } else { ViewData["Title"] = "Edit"; return(View(region)); } } else { ViewData["Title"] = "Add"; return(View(region)); } }
public async Task UpdateAsync(Player player) { Position lastKnownRegion = player.LastKnownRegion; var regionChanged = player.RegionChanged; int[] appearanceTickets = player.AppearanceTickets; SynchronizationBlockSet blockSet = player.BlockSet; Position position = player.Position; SynchronizationSegment segment = (player.IsTeleporting || player.RegionChanged) ? new TeleportSegment(blockSet, position) : new MovementSegment(blockSet, player.GetDirections()); List <Player> localPlayers = player.LocalPlayerList; int oldCount = localPlayers.Count; List <SynchronizationSegment> segments = new(); int distance = player.ViewingDistance; foreach (var other in localPlayers.ToList()) { if (Removeable(position, distance, other)) { localPlayers.Remove(other); segments.Add(new RemoveMobSegment()); } else { segments.Add(new MovementSegment(other.BlockSet, other.GetDirections())); } } int added = 0, count = localPlayers.Count; IRegion current = _regionRepository.FromPosition(position); HashSet <RegionCoordinates> regions = current.GetSurrounding(); regions.Add(current.Coordinates); IEnumerable <Player> players = regions.Select(t => _regionRepository.Get(t)) .SelectMany(region => region.GetEntities <Player>(EntityType.Player)); foreach (var other in players) { if (count >= MaximumLocalPlayers) { player.ExcessivePlayers = true; break; } else if (added >= NewPlayersPerCycle) { break; } Position local = other.Position; if (other != player && local.IsWithinDistance(position, distance) && !localPlayers.Contains(other)) { localPlayers.Add(other); count++; added++; blockSet = other.BlockSet; int index = other.Index; if (!blockSet.Contains <AppearanceBlock>() && !HasCachedAppearance(appearanceTickets, index - 1, other.AppearanceTicket)) { blockSet = (SynchronizationBlockSet)blockSet.Clone(); blockSet.Add(SynchronizationBlock.CreateAppearanceBlock(other)); } segments.Add(new AddPlayerSegment(blockSet, index, local)); } } PlayerSynchronizationMessage message = new PlayerSynchronizationMessage(lastKnownRegion, position, regionChanged, segment, oldCount, segments); await player.SendAsync(message); }
public Region GetRegion(Guid id) { return(_regionRepository.Get(id)); }
public async Task <IActionResult> RegionUpdate([FromBody] CmsPostWebHookApiModel model) { if (model == null) { return(BadRequest("delete model empty or null.")); } var postId = model.post_id; if (postId <= 0) { return(BadRequest($"post id null. model.post_id: {postId}")); } if (model.post.post_status == "trash") { var removeSuccessful = await _regionRepository.Delete(postId); if (!removeSuccessful) { _logger.LogError("Failed to delete region with id: {PostId} in elasticsearch.", postId); return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to delete region.")); } return(NoContent()); } var cmsRegion = await _cmsApiProxy.GetRegion(postId); var elasticRegion = await MapToElasticModel(cmsRegion); bool successful; var region = await _regionRepository.Get(postId); if (region == null) { successful = await _regionRepository.Insert(new List <RegionElasticModel> { elasticRegion }); if (!successful) { _logger.LogError("Failed to insert region with id:{PostId} in elasticsearch.", postId); return(BadRequest("Failed to insert region.")); } _logger.LogInformation("Inserted region with id {PostId} to elasticsearch successfully.", postId); return(Created(elasticRegion.Id.ToString(), elasticRegion)); } successful = await _regionRepository.Update(elasticRegion); if (!successful) { _logger.LogError("Failed to update region with id:{PostId} in elasticsearch.", postId); return(BadRequest("Failed to update region.")); } _logger.LogInformation("Updated region with id {PostId} to elasticsearch successfully.", postId); // TODO: FIX THIS!!!!!! // Update business cache! await SyncBusiness(); // Update pages cache! var apiPath = model.post.post_type; _cmsApiProxy.RemovePagesCache(apiPath); await _cmsApiProxy.GetPages(regionPageApiPath : apiPath); return(Ok()); }
public Region GetById( [FromServices] IRegionRepository repository, int id) { return(repository.Get(id)); }
public IEnumerable <Region> Get( [FromServices] IRegionRepository repository) { return(repository.Get()); }
public async Task <List <Region> > GetRegions(short countryId) { List <RegionEntity> regions = await _regionRepository.Get(r => r.Country.Id == countryId).ToListAsync(); return(regions.Select(Mapper.Map <RegionEntity, Region>).ToList()); }