private async Task SyncMapPeriodically(Guid mapId, bool isLocalGame, MapRepository mapRepo, CancellationToken token = default(CancellationToken)) { while (!token.IsCancellationRequested) { var map = isLocalGame ? this._localGames.Single(x => x.Map.Id.Equals(mapId)).Map : this.GameHosts.Values.Single(x => x.Map.Id.Equals(mapId)).Map; // Make sure it stays locked map.IsLocked = true; map.LastUpdated = DateTime.Now; mapRepo.UpdateMap(map); try { await Task.Delay(TimeSpan.FromSeconds(this.SyncMapSecInterval), token); } catch (TaskCanceledException) { break; } } }
// POST api/<controller> public HttpResponseMessage Post(MapViewModel mapVm) { Map map = ModelConverter.ToDbMapModel(mapVm); // If the ID is not zero, then edit the map if (map.Id > 0) { mapRepository.UpdateMap(map); } else // If the map has a zero id, then create a new map { map = mapRepository.CreateMap(map); } if (mapVm.SessionId > 0) { mapRepository.AddMapToSession(map.Id, mapVm.SessionId); } mapVm = ModelConverter.ToMapViewModel(mapRepository.GetMap(map.Id)); return(Request.CreateResponse(HttpStatusCode.OK, mapVm)); }