public JsonResult SaveGamesUrl(int teamId, string url, string teamName, int clubId) { try { var service = new ScrapperService(); var result = service.SchedulerScraper(url); service.Quit(); var isTeamExist = teamRepo.GetById(teamId) != null; if (!isTeamExist && result.Any(t => t.HomeTeam != teamName || t.GuestTeam != teamName)) { return(Json(new { Success = false, Error = "Such team doesn't exist" })); } var scheduleId = gamesRepo.SaveTeamGameUrl(teamId, url, clubId, teamName); gamesRepo.UpdateGamesSchedulesFromDto(result, clubId, scheduleId, url); ProcessHelper.ClosePhantomJSProcess(); return(Json(new { Success = true, Data = result })); } catch (Exception e) { ProcessHelper.ClosePhantomJSProcess(); return(Json(new { Success = false, Error = e.Message })); } }
public JsonResult SaveTeamStandingGameUrl(int teamId, int clubId, string url, string teamName) { try { var service = new ScrapperService(); var isTeamExist = teamRepo.GetById(teamId) != null; var result = service.StandingScraper(url); if (!isTeamExist && result.Any(t => t.Team != teamName)) { ProcessHelper.ClosePhantomJSProcess(); return(Json(new { Success = false, Error = "Such team not exist." })); } int standingGameId = teamRepo.SaveTeamStandingUrl(teamId, clubId, url, teamName); bool isSuccess = standingGameId > 0; if (isSuccess) { gamesRepo.UpdateTeamStandingsFromModel(result, standingGameId, url); service.Quit(); } ProcessHelper.ClosePhantomJSProcess(); return(Json(new { Success = isSuccess, Data = result })); } catch (Exception e) { return(Json(new { Sucess = false, Error = e.Message })); } }
public void Execute() { lock (_lock) { if (_shuttingDown) { return; } //TODO service call var teamSchedulesUrl = _clubsRepo.GetClubTeamGamesUrl(); _gamesRepo.UpdateGamesSchedulersFromScrapper(teamSchedulesUrl); var teamStandingsUrl = _teamsRepo.GetTeamStandingsUrl(); _gamesRepo.UpdateTeamStandingsFromScrapper(teamStandingsUrl); } //close all phantomjs process after the end of the timer //TODO ProcessHelper.ClosePhantomJSProcess(); }