public LiveViewModel getLiveViewModel(LiveResponse liveResponse) { return(new LiveViewModel { GameId = liveResponse.GameId, RoundId = liveResponse.RoundId, RoundNumber = liveResponse.RoundNumber, Phase = liveResponse.Phase, SecretLength = liveResponse.SecretLength, JoiningDuration = liveResponse.JoiningDuration, RunningDuration = liveResponse.RunningDuration, FinishedDuration = liveResponse.FinishedDuration, PhaseStartTime = liveResponse.PhaseStartTime, Participants_CurrentScore = liveResponse.Participants_Current.OrderByDescending(o => o.Score).ToList(), Participants_TotalScore = liveResponse.Participants_Total.OrderByDescending(o => o.Score).ToList() }); }
private async Task <LiveResponse> GetNews(string newsSource) { LiveResponse liveResponse = new LiveResponse(); try { var client = new HttpClient(); var response = await client.GetAsync(string.Format("https://newsapi.org/v1/articles?source={0}&apiKey=94f312c927104585a9e98ebcfce44403", newsSource)); var content = await response.Content.ReadAsStringAsync(); liveResponse = JsonConvert.DeserializeObject <LiveResponse>(content); return(liveResponse); } catch (Exception) { return(liveResponse); } }
// string newsSource = await result; // var newsArticles = await GetNews(newsSource.ToString()); // if (newsArticles.Status == "ok") // { // List<Attachment> list = new List<Attachment>(); // foreach (Article articleResponse in newsArticles.Articles) // { // var articleCard = new HeroCard() // { // Title = articleResponse.Title; // Subtitle = articleResponse.Author; // Text = articleResponse.Description; // }; // } //} //List<Article> articles = liveResult.Result.Articles; //foreach (var article in articles) //{ // HeroCard heroCard = new HeroCard { Title = article.Title, Subtitle} //} //throw new NotImplementedException(); //} private async Task <LiveResponse> GetNews(string newsSource) { LiveResponse liveResponse = new LiveResponse(); try { var client = new HttpClient(); var response = await client.GetAsync(string.Format("https://newsapi.org/v1/articles?source={0}&apiKey=7f29daf2862c4e3ba2956c754689df07", newsSource)); var content = await response.Content.ReadAsStringAsync(); liveResponse = JsonConvert.DeserializeObject <LiveResponse>(content); return(liveResponse); } catch (Exception) { return(liveResponse); } }
static void Main(string[] args) { string live_request_headers_text = System.IO.File.ReadAllText(@".\Resources\live_request_headers.txt"); object live_request_headers = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(live_request_headers_text); string live_request_body_text = System.IO.File.ReadAllText(@".\Resources\live_request_body.txt"); object live_request_body = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(live_request_body_text); string live_response_headers_text = System.IO.File.ReadAllText(@".\Resources\live_response_headers.txt"); object live_response_headers = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(live_response_headers_text); string live_response_body_text = System.IO.File.ReadAllText(@".\Resources\live_response_body.txt"); object live_response_body = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(live_response_body_text); LiveRequest liveRequest = new LiveRequest( "PUT", "/subscriptions/4d368445-cbb1-42a7-97a6-6850ab99f48e/resourceGroups/pslibtest9279/providers/Microsoft.Compute/virtualMachines/vm1827?api-version=2017-12-01", live_request_body, live_request_headers ); LiveResponse liveResponse = new LiveResponse( "403", live_response_headers, live_response_body ); LiveValidationParameter liveValidationParameter = new LiveValidationParameter( liveRequest, liveResponse ); var apiInstance = new LiveValidationApi(); try { LiveValidationResponse liveValidationResponse = apiInstance.ToolsLiveValidationValidate(liveValidationParameter); Console.WriteLine(liveValidationResponse); } catch (Exception e) { Debug.Print("Exception when calling LiveValidationApi.ToolsLiveValidationProdValidate: " + e.Message); } }
public LiveResponse DeleteLive(Live live) { liveResponse = new LiveResponse(); if (live.id == 0) { return(liveResponseFactory.CreateLiveResponse(liveResponse, "live.id is null", HttpStatusCode.BadRequest)); } try { liveDao.DeleteLive(live); } catch (Exception ex) { return(liveResponseFactory.CreateLiveResponse(liveResponse, ex.Message, HttpStatusCode.BadRequest)); } return(liveResponseFactory.CreateLiveResponse(liveResponse, "", HttpStatusCode.OK)); }
public LiveResponse GetLiveById(int id) { liveResponse = new LiveResponse(); if (id == 0) { return(liveResponseFactory.CreateLiveResponse(liveResponse, "live.id is null", HttpStatusCode.BadRequest)); } try { liveResponse.live = liveDao.GetLiveById(id); } catch (Exception ex) { return(liveResponseFactory.CreateLiveResponse(liveResponse, ex.Message, HttpStatusCode.BadRequest)); } return(liveResponseFactory.CreateLiveResponse(liveResponse, "", HttpStatusCode.OK)); }
public LiveResponse CreateLiveFileType(LiveFileType liveFileType) { liveResponse = new LiveResponse(); if (liveFileType.id != 0) { return(liveResponseFactory.CreateLiveResponse(liveResponse, "liveFileType.id is not null", HttpStatusCode.BadRequest)); } try { liveResponse.liveFileType = liveFileTypeDao.CreateLiveFileType(liveFileType); } catch (Exception ex) { return(liveResponseFactory.CreateLiveResponse(liveResponse, ex.Message, HttpStatusCode.BadRequest)); } return(liveResponseFactory.CreateLiveResponse(liveResponse, "", HttpStatusCode.OK)); }
public async Task <IActionResult> LoadData() { LiveResponse liveResponse = await _liveService.GetLiveStatus(); return(Json(getLiveViewModel(liveResponse))); }
public virtual async Task <LiveResponse> GetLiveStatus() { try { LiveResponse response = new LiveResponse(); var currentPhase = await _context.Phases.Include(p => p.Round).OrderByDescending(p => p.TimeStamp).FirstOrDefaultAsync(); if (currentPhase == null) { _logger.LogError("Error : Game not running"); } else { var roundConfig = await _context.RoundConfigs.Where(rc => rc.Id == currentPhase.Round.RoundNumber).SingleOrDefaultAsync(); var participants_round = await _context.Participants.Include(p => p.Team).Where(p => p.RoundId.CompareTo(currentPhase.RoundId) == 0).ToDictionaryAsync(p => p.TeamId); var participants_total = await _context.Participants.Include(p => p.Team).Where(p => p.GameId.CompareTo(currentPhase.GameId) == 0) .Select(p => new { p.TeamId, p.Team }) .Distinct() .ToDictionaryAsync(p => p.TeamId) ; var tScore = await _context.Scores.Where(s => s.GameId.CompareTo(currentPhase.GameId) == 0) .GroupBy(s => s.TeamId) .Select(s => new { TeamId = s.Key, TotalScore = s.Sum(p => p.PointsScored) }) .ToDictionaryAsync(kg => kg.TeamId); var cScore = await _context.Scores.Where(s => s.RoundId.CompareTo(currentPhase.RoundId) == 0) .GroupBy(s => s.TeamId) .Select(s => new { TeamId = s.Key, CurrentScore = s.Sum(p => p.PointsScored) }) .ToDictionaryAsync(kg => kg.TeamId); var killNumber = await(from k in _context.Kills.Where(k => k.RoundId.CompareTo(currentPhase.RoundId) == 0) group k by k.VictimId into killGroup select new { TeamId = killGroup.Key, TotalKills = killGroup.Count() }).ToDictionaryAsync(kg => kg.TeamId); var participantsList_CurrentScore = new List <LiveParticipantDetails>(); var participantsList_TotalScore = new List <LiveParticipantDetails>(); foreach (var key in participants_total.Keys) { bool inScore = tScore.ContainsKey(key); participantsList_TotalScore.Add(new LiveParticipantDetails { TeamId = key, Score = inScore ? tScore[key].TotalScore : 0, IsRobot = participants_total[key].Team.IsRobot, Location = participants_total[key].Team.Location, RoundId = currentPhase.Round.RoundId, GameId = currentPhase.Round.GameId, RoundNumber = currentPhase.Round.RoundNumber, Phase = currentPhase.PhaseType.ToString() }); } foreach (var key in participants_round.Keys) { bool inScore = cScore.ContainsKey(key); int LifelinesRemaining = roundConfig.LifeLines - (killNumber.ContainsKey(key) ? killNumber[key].TotalKills : 0); bool zeroLifelines = LifelinesRemaining <= 0 ? true : false; participantsList_CurrentScore.Add(new LiveParticipantDetails { TeamId = key, Score = inScore ? cScore[key].CurrentScore : 0, IsAlive = participants_round[key].IsAlive, IsRobot = participants_round[key].Team.IsRobot, Location = participants_round[key].Team.Location, Lifelines = zeroLifelines ? 0 : LifelinesRemaining, RoundId = currentPhase.Round.RoundId, GameId = currentPhase.Round.GameId, RoundNumber = currentPhase.Round.RoundNumber, Phase = currentPhase.PhaseType.ToString() }); } response.RoundId = currentPhase.Round.RoundId; response.GameId = currentPhase.Round.GameId; response.RoundNumber = currentPhase.Round.RoundNumber; response.SecretLength = roundConfig?.SecretLength; response.Participants_Current = participantsList_CurrentScore; response.Participants_Total = participantsList_TotalScore; response.Phase = currentPhase.PhaseType.ToString(); response.JoiningDuration = roundConfig.JoiningDuration; response.RunningDuration = roundConfig.RunningDuration; response.FinishedDuration = roundConfig.FinishedDuration; response.PhaseStartTime = currentPhase.TimeStamp; } return(response); } catch (Exception ex) { _logger.LogError($"Fetching current gamestatus failed, {ex}"); throw new ServerSideException("Failed in GetCurrentStatus()", ex); } }