static private bool ExecuteCompetitionEvents(SoccerWorldDatabaseContext _context, IRealtimeCallback _callback, DateTime date) { //get all events for current date ICollection <CompetitionEvent> events = _context.CompetitionEvents.Where(o => o.Date == date) .Include(o => o.NextCompetitionEvent) .Include(o => o.Competition) .ThenInclude(o => o.Clubs) .ThenInclude(o => o.Country) .OrderByDescending(o => o.Id) .ToList(); if (events.Count == 0) { return(false); } //process each event sequential foreach (CompetitionEvent comp_event in events) { comp_event.Execute(); } _context.SaveChanges(); foreach (CompetitionEvent comp_event in events) { _callback.OnCompetitionEventProcessed(comp_event); } return(true); }
static private void ProcessGameTick(SoccerWorldDatabaseContext _context, IRealtimeCallback _callback, bool first_run = false) { //check if new CompetitionEvents are found, and activate them ExecuteCompetitionEvents(_context, _callback, GetWorldState().CurrentDateTime); //check if new matches found on current time, to add to matches-pool UpdateMatchPool(_context, _callback, GetWorldState().CurrentDateTime); //if matches-pool is empty if (_MATCHES.Count == 0) { // end Process return; } //else process all matches ProcessMatchPool(); GetWorldState().CurrentDateTime = GetWorldState().CurrentDateTime.AddMinutes(1); GetDatabaseContext().SaveChanges(); if (_MATCHES.Count > 0) { _callback.OnMatchesChanged(_MATCHES); } _callback.OnWorldStateChanged(GetWorldState()); Thread.Sleep(2000); ProcessGameTick(_context, _callback); }
static public SoccerWorldDatabaseContext GetDatabaseContext() { if (_context == null) { _context = SoccerWorldDatabaseContext.GetService(); } return(_context); //return SoccerWorldDatabaseContext.GetService(); }
static public IEnumerable <CompetitionLeagueTable> GetStandings(CompetitionEvent comp_event, int season) { var list = SoccerWorldDatabaseContext.GetService().CompetitionLeagueTable .Where(o => o.Season == season && o.CompetitionEventId == comp_event.Id) .Include(o => o.Club) .ToList(); list.Sort(new StandingOrderComparer(backwards: false)); return(list); }
static public IEnumerable <CompetitionLeagueTable> GetStandingsBackwards(Competition comp, int season) { var first_tableitem = SoccerWorldDatabaseContext.GetService().CompetitionLeagueTable .Where(o => o.Season == season && o.CompetitionId == comp.Id) .Include(o => o.CompetitionEvent) .First(); CompetitionEvent first_event = first_tableitem.CompetitionEvent; return (GetStandingsBackwards(first_event, season)); }
////////////////////////////// public async void CompetitionsDataRequest(int?id) { if (id == null) { await Clients.Caller.SendAsync("OnCompetitionsDataRequest", "{}"); return; } using (var context = SoccerWorldDatabaseContext.GetService()) { var comps = context.Competitions .Where(c => c.CountryId == id) .ToList(); await Clients.Caller.SendAsync("OnCompetitionsDataRequest", JsonConvert.SerializeObject(SerializeCompetitions(comps))); } }
static private void UpdateMatchPool(SoccerWorldDatabaseContext _context, IRealtimeCallback _callback, DateTime date) { //select ended matches and send callback _callback.OnMatchesEnd(_MATCHES.Where(o => o.HasEnded)); //check if matches ended, to remove from matches-pool _MATCHES = _MATCHES.Where(o => o.HasEnded == false).ToList(); //check if matches started, to add them to matches-pool List <Match> new_matches = _context.Matches.Where(o => o.Date == date) .Include(o => o.HomeClub) .Include(o => o.AwayClub) .Include(o => o.CompetitionEvent) .ThenInclude(e => e.Competition) .ThenInclude(c => c.Country) .ToList(); _MATCHES.AddRange(new_matches); }
static private DateTime GetEarliestEvent(SoccerWorldDatabaseContext _context) { var world_state = GetWorldState(); var next_event = _context.CompetitionEvents .OrderBy(o => o.Date) .FirstOrDefault(o => //o.Date != null && o.Date > world_state.CurrentDateTime); var next_match = _context.Matches .OrderBy(o => o.Date) .FirstOrDefault(o => //o.Date != null && o.Date > world_state.CurrentDateTime); if (next_match == null && next_event == null) { throw new ArgumentNullException(); } if (next_match == null) { return((DateTime)next_event.Date); } if (next_event == null) { return(next_match.Date); } if (next_event.Date < next_match.Date) { return((DateTime)next_event.Date); } else { return(next_match.Date); } }
static private void ProcessWorld(SoccerWorldDatabaseContext _context, IRealtimeCallback _callback, DateTime target_date) { //if another Process is taking care of it, return if (IsProcessingMatches()) { return; } //as long we did not reach target date while (GetWorldState().CurrentDateTime < target_date) { DateTime eventdate = GetEarliestEvent(_context); //update world date with the first next date (target or event) GetWorldState().CurrentDateTime = (eventdate < target_date ? eventdate : target_date); GetWorldState().AsyncProcessesCount++; _context.SaveChanges(); _callback.OnWorldStateChanged(GetWorldState()); ProcessGameTick(_context, _callback, true); GetWorldState().AsyncProcessesCount--; _context.SaveChanges(); } }
public SeedAbstract(SoccerWorldDatabaseContext db_context) { Context = db_context; }
public Engeland(SoccerWorldDatabaseContext context) : base(context) { }
public async void CompetitionDataRequest(int id, int?season, int?round) { using (var context = SoccerWorldDatabaseContext.GetService()) { var comp = context.Competitions .Where(c => c.Id == id) .Include(c => c.Country).First(); if (comp.Country.Season == null) { await Clients.Caller.SendAsync("OnCompetitionDataRequest", JsonConvert.SerializeObject( new { Competition = new CompetitionViewModel(comp), CompetitionSeasons = new Array[0], LeagueTable = new Array[0], Matches = new Array[0] } )); return;//nullable-int syndrome solution #1 } if (season == null) { season = comp.Country.Season; } var country_seasons = context.CompetitionLeagueTable.Where(o => o.Competition == comp) .Select(o => o.Season) .Distinct().ToList(); //TODO.OrderBy(); // var standings = CompetitionLeagueTable.GetStandings(comp, (int)season); if (round == null) { var chosen_match = context.Matches .Where(m => m.Season == season && m.CompetitionEvent.CompetitionId == comp.Id && m.HasEnded == false) .OrderBy(m => m.RoundNumber).FirstOrDefault(); if (chosen_match == null) { chosen_match = context.Matches .Where(m => m.Season == season && m.CompetitionEvent.CompetitionId == comp.Id && m.HasEnded == true) .OrderByDescending(m => m.RoundNumber).FirstOrDefault(); } round = chosen_match?.RoundNumber; } var matches = context.Matches .Where(m => m.Season == season && m.CompetitionEvent.CompetitionId == comp.Id && m.RoundNumber == round) .Include(m => m.HomeClub) .Include(m => m.AwayClub) .ToList(); await Clients.Caller.SendAsync("OnCompetitionDataRequest", JsonConvert.SerializeObject( new { Competition = new CompetitionViewModel(comp), CompetitionSeasons = country_seasons, LeagueTable = SerializeStandings(standings), Matches = SerializeMatches(matches) } )); } }
public Nederland(SoccerWorldDatabaseContext context) : base(context) { }
static public IEnumerable <CompetitionLeagueTable> GetStandings(int competition_id) { var comp = SoccerWorldDatabaseContext.GetService().Competitions.Where(c => c.Id == competition_id).First(); return(GetStandings(comp, (int)comp.Country.Season)); }
public HomeController(ILogger <HomeController> logger, SoccerWorldDatabaseContext context) { _logger = logger; _context = context; }
public Spanje(SoccerWorldDatabaseContext context) : base(context) { }