public static void BroadcastScore(Score score, int roundIndex, int diverIndex, SimhoppMessage.ClientAction action = SimhoppMessage.ClientAction.Ping) { if (_server == null) return; _serverThread = new Thread(() => SendScoreToConnectedClients(score, roundIndex, diverIndex, action)) { IsBackground = true }; _serverThread.Start(); }
public void CommitScore(int judgeIndex, Score score) { SimhoppMessage.SimhoppStatus status = new SimhoppMessage.SimhoppStatus(Presenter.CurrentRoundIndex, Presenter.CurrentDiverIndex, null); SimhoppMessage msg = new SimhoppMessage(judgeIndex, SimhoppMessage.ClientAction.SubmitScore, "", score.Points, status); Messages.Enqueue(msg); }
public void ScoreDive(int diveNum, Score score) { Dives[diveNum].AddScore(score); }
public void SetUp() { _judges = new List<Judge>(); _divers = new List<Diver>(); _contest = new Contest(0, "Nunit Test Contest", "2015-02-02", "Badhuset", 1, 1, 1, 5); _judges.Add(new Judge(0, "Mr. Test")); _judges.Add(new Judge(1, "Mrs. Fest")); _judges.Add(new Judge(2, "Konstapel Kuk")); _judges.Add(new Judge(3, "Domherre")); _judges.Add(new Judge(4, "McFlash")); _divers.Add(new Diver(0, "Kalle")); _divers.Add(new Diver(1, "Greger")); _divers.Add(new Diver(2, "Skitunge")); _contest.AddDivers(_divers); _contest.AddJudges(_judges); for (int i = 0; i < 3; i++) { for (int j = 0; j < 5; j++) { Dive dive = new Dive(0, null, j + 1, _contest); _contest.Divers[i].AddDive(dive); for (int k = 0; k < 5; k++) { Score s = new Score(0, null, _judges[k], (k + j)%11); dive.AddScore(s); } } } }
public void PopulateScoreInput(Score score, int judgeIndex, int diverIndex = -1, int roundIndex = -1) { if (diverIndex == -1) diverIndex = CurrentDiverIndex; if (roundIndex == -1) roundIndex = CurrentRoundIndex; Panel divePanel = _divePanels[roundIndex][diverIndex]; if (divePanel.InvokeRequired) { PopulateScoreInputDelegate d = new PopulateScoreInputDelegate(PopulateScoreInput); this.Invoke(d, new object[] {score, judgeIndex, diverIndex, roundIndex}); return; } TextBox scoreInput = (TextBox)divePanel.Controls.Find("Score", true)[judgeIndex]; scoreInput.Text = score.Points.ToString(); scoreInput.Tag = score; }
public void AddScore(Score score) { if (score.dive == null) score.dive = this; foreach (Score iScore in Scores) { if (iScore.judge == score.judge) { return; Exception ex = new Exception("Domare har redan poängsatt hoppet"); ExceptionHandler.Handle(ex); } } Scores.Add(score); }
private static void SendScoreToConnectedClients(Score score, int roundIndex, int diverIndex, SimhoppMessage.ClientAction action = SimhoppMessage.ClientAction.Ping) { if (_judgeClients == null) return; IPEndPoint toDelete = null; bool delete = false; //Skicka poäng (eller status / request) till anslutna domarklienter foreach (IPEndPoint ipep in _judgeClients.Keys) { try { //Skapa statusmeddelande med runda/hopp SimhoppMessage.SimhoppStatus status = new SimhoppMessage.SimhoppStatus( roundIndex, diverIndex, null); SimhoppMessage msg; if (score == null) msg = new SimhoppMessage(-2, action, "", 0, status); else msg = new SimhoppMessage(score.judge.Index((_presenter.Judges)), SimhoppMessage.ClientAction.SubmitScore, "", score.Points, status); LogToServer("Send: " + msg.Serialize()); var sendData = Encoding.ASCII.GetBytes(msg.Serialize()); _server.Send(sendData, sendData.Length, ipep); } catch (Exception ex) { delete = true; ExceptionHandler.Handle(ex); } } if (delete && toDelete != null) { try { int judgeIndex = _judgeClients[toDelete]; _judgeClients.Remove(toDelete); _judges.Remove(judgeIndex); _presenter.LogoutClient(judgeIndex); } catch (Exception ex) { /* Ignore */ } } }
public static void GetScoresToDives(Contest contest) { MySqlConnection conn = Database.ConnectToDatabase(); MySqlCommand comm = new MySqlCommand(); string sql = ""; comm = conn.CreateCommand(); if(conn != null) { foreach (Diver diver in contest.Divers) { //hämtar alla Scores som finns på hopparen sql = "SELECT * FROM score WHERE diveId IN (SELECT id FROM dive WHERE diverId=" + diver.Id + " AND eventId=" + contest.Id + ") ORDER BY id"; comm.CommandText = sql; MySqlDataReader dr = comm.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(dr); int count = 0; int diveCount = 1; Score currentScore = new Score(); Dive currentDive = new Dive(); Judge currentJudge = new Judge(); //Alla scores som finns på alla hoppen foreach(DataRow row in dt.Rows) { if (count < diver.Dives.Count) { foreach (Judge judge in contest.Judges) { if (judge.Id.ToString().CompareTo(row["judgeId"].ToString()) == 0) currentJudge = judge; } try { currentDive = diver.Dives[count]; } catch (IndexOutOfRangeException) { } currentScore = new Score(Int32.Parse(row["id"].ToString()), currentDive, currentJudge, Double.Parse(row["point"].ToString())); diver.Dives[count].AddScore(currentScore); if(diveCount == contest.Judges.Count) { count++; diveCount = 1; } else { diveCount++; } } } } } }