private async Task FetchServerStats(ServiceDbContext context, Server server) { var stats = new ServerStats { Server = server, TrackedAt = DateTime.Now }; var infoUrl = new Url(server.GameEndpoint).AppendPathSegment("GetServerInformation"); try { var serverInformation = JsonConvert.DeserializeObject <ServerInformation>( await infoUrl.WithHeader("User-Agent", "SBRW-ServerMonitor") .WithHeader("Accept", "application/json").GetStringAsync()); stats.Status = ServerStatus.Online; stats.PlayersOnline = serverInformation.NumOnline; stats.PlayersRegistered = serverInformation.NumRegistered; } catch (Exception e) { stats.Status = ServerStatus.Offline; _logger.LogError(e, "Failed to fetch stats for {Name} @ {Endpoint}", server.Name, infoUrl); } context.Add(stats); }
public TryAsync <CalendarEvent> CreateAsync(CalendarEvent entity) => async() => { entity.CalendarEventMembers = await GetMembersAsync(entity); var created = _context.Add(entity); await _context.SaveChangesAsync(); return(created.Entity); };
public Task <int> InsertAsync(TraefikRouteValue entity) { serviceDbContext.Add(entity); return(serviceDbContext.SaveChangesAsync()); }