private static void DecodeMessage(string decodedMessage) { string plainMessage = new string(decodedMessage.Where(char.IsDigit).ToArray()); Console.WriteLine(plainMessage); string cartNo = plainMessage.Substring(0, 2); if (cartNo != "00") { Laps record = LapCollection.LapList.Where(x => x.KartID == cartNo).Last(); record.Lap = (Convert.ToInt32(record.Lap) + 1).ToString(); record.AbsoluteTime = $"{int.Parse(plainMessage.Substring(2, 6)).ToString()}.{plainMessage.Substring(8, 3)}"; string bestTime = Laps.GetBestTime(record); string time = Laps.GetTime(record); Database.Update("Laps", "Time,Laps,BestTime,AbsoluteTime", $"'{time}','{record.Lap}','{bestTime}','{record.Time}'", $"Course_Id LIKE '{record.CourseID}'"); LapCollection.RefreshList(record.CourseID); Database.Insert("UserLaps", "Course_Id, Kart_Id, Time, Lap", $"'{record.CourseID}','{record.KartID}','{time}','{record.Lap}'"); UserLapsList.RefreshList(); } Timing = ""; }
/// <summary> /// Get direction of the received data. /// </summary> /// <param name="message"></param> private static void GetDirection(string message) { if (message == "Ping") { TcpPingTimer.Stop(); TcpPingTimer.Interval = new TimeSpan(0, 0, 10); TcpPingTimer.Start(); Send("Ping"); } else { string[] text = message.Split('+'); switch (text[0]) { case "K": Kart.SendKarts(); break; case "C": if (Database.Insert("Course", "Course_Name, Course_Id, User_Id, Kart_Id, Date", $"'{text[1]}','{text[2]}','{text[3]}','{text[4]}','{text[5]}'")) { if (Database.Insert("Laps", "Course_Id, Kart_Id, Time, BestTime ,AbsoluteTime", $"'{text[2]}','{text[4]}','0:00.000','0:00.000','0:00.000'")) { CourseRowList.RefreshList(); CourseList.RefreshList(); if (LapCollection.LapList.Count(x => x.CourseID == text[2]) > 0) { LapCollection.RefreshList(text[2]); } } } break; case "P": if (Database.Insert("CoursePlaces", "user,cart,course_id", $"'{text[1]}','{text[2]}','{text[3]}'")) { log.Debug($"[{Settings.GetLine(new StackTrace(true))}]:New user joined Course: {text[1]} - {text[2]} - {text[3]}"); } break; case "U": if (Database.Insert("UserStatistics", "User_id,Course_id,Time", $"'{text[1]}','{text[2]}','{text[3]}'")) { log.Debug($"[{Settings.GetLine(new StackTrace(true))}]:New User Statistic: {text[1]} - {text[2]} - {text[3]}"); } break; case "R": UserCollection.RefreshList(); foreach (User user in UserCollection.UserList) { Send($"R+{user.Email}+{user.Password}+{user.Name}+{user.Surname}+{user.Photo}"); log.Debug($"[{Settings.GetLine(new StackTrace(true))}]:Sent user {user.Email} - {user.Name} - {user.Surname}"); } break; case "Q": if (Database.Insert("Users", "Email,Name,Surname,Password,Image", $"'{text[1]}','{text[2]}','{text[3]}','{text[4]}','{text[5]}'")) { log.Debug($"[{Settings.GetLine(new StackTrace(true))}]:New User Created: {text[1]} - {text[2]} - {text[3]}"); } break; default: log.Error($"[{Settings.GetLine(new StackTrace(true))}]:Unknown message: {message}"); break; } } }