Ejemplo n.º 1
0
        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 = "";
        }
Ejemplo n.º 2
0
        public static string GetTime(Laps laps)
        {
            string last = LapCollection.LapList.Where(y => y.CourseID == laps.CourseID && y.KartID == laps.KartID).Select(x => x.Time).Last();

            if (string.IsNullOrEmpty(last))
            {
                return(laps.Time);
            }

            TimeSpan lastSpan, timeSpan;

            if (!TimeSpan.TryParse(last, out lastSpan))
            {
                return(laps.Time);
            }
            return(TimeSpan.TryParse(laps.Time, out timeSpan) ? (timeSpan - lastSpan).ToString() : laps.Time);
        }
Ejemplo n.º 3
0
        public static string GetBestTime(Laps laps)
        {
            IEnumerable <string>            timesString = LapCollection.LapList.Where(y => y.CourseID == laps.CourseID && y.KartID == laps.KartID).Select(x => x.Time);
            ObservableCollection <TimeSpan> times       = new ObservableCollection <TimeSpan>();

            foreach (string time in timesString)
            {
                TimeSpan timeSpan;
                if (TimeSpan.TryParse(time, out timeSpan))
                {
                    times.Add(timeSpan);
                }
            }

            if (times.Any())
            {
                return(times.Min().ToString());
            }
            return("");
        }