Beispiel #1
0
        public override bool Equals(object outro)
        {
            Piloto outroPiloto = outro as Piloto;

            if (outroPiloto == null)
            {
                return(false);
            }

            return(this.numero == outroPiloto.numero);
        }
Beispiel #2
0
        public static Volta ConvertToVolta(string[] cols)
        {
            if (cols.Length != 5)
            {
                throw new NotSupportedException($"A quantidade das colunas no log não é suportada! {cols.Length} colunas (esperado: \"5\")");
            }

            #region horaRegistro

            TimeSpan horaRegistro;
            if (!TimeSpan.TryParse(cols[0], out horaRegistro))
            {
                throw new NotSupportedException($"O formato da hora de registro da volta não é suportado! {cols[0]}");
            }

            #endregion

            #region piloto

            var rawPiloto = cols[1].Split('–');
            if (rawPiloto.Length != 2)
            {
                throw new NotSupportedException($"O formato dos dados do piloto não é suportado! {cols[1]}");
            }

            var piloto = new Piloto();

            int numero;
            if (!int.TryParse(rawPiloto[0].Trim(), out numero))
            {
                throw new NotSupportedException($"O número do Piloto não é suportado! {rawPiloto[0]}");
            }

            piloto.numero = numero;
            piloto.nome   = rawPiloto[1].Trim();

            #endregion

            #region numeroVolta

            int numeroVolta;
            if (!int.TryParse(cols[2], out numeroVolta))
            {
                throw new NotSupportedException($"O formato do número da volta não é suportado! {cols[2]}");
            }

            #endregion

            #region tempoVolta

            TimeSpan tempoVolta;
            var      rawTempoVolta = cols[3].Split(':', '.');
            if (rawTempoVolta.Length != 3)
            {
                throw new NotSupportedException($"O formato dos tempo de volta não é suportado! {cols[3]}");
            }
            else
            {
                int minutoTempoVolta, segundoTempoVolta, milissegundoTempoVolta;
                if (!int.TryParse(rawTempoVolta[0], out minutoTempoVolta) ||
                    !int.TryParse(rawTempoVolta[1], out segundoTempoVolta) ||
                    !int.TryParse(rawTempoVolta[2], out milissegundoTempoVolta))
                {
                    throw new NotSupportedException($"O formato dos tempo de volta não é suportado! {cols[3]}");
                }
                tempoVolta = new TimeSpan(0, 0, minutoTempoVolta, segundoTempoVolta, milissegundoTempoVolta);
            }

            #endregion

            #region velocidadeMediaVolta

            TimeSpan velocidadeMediaVolta;
            var      rawVelocidadeMediaVolta = cols[4].Replace(" ", string.Empty).Split(',', '.');
            if (rawVelocidadeMediaVolta.Length != 2)
            {
                throw new NotSupportedException($"O formato da velocidade média da volta não é suportado! {cols[4]}");
            }
            else
            {
                int segundosVelocidadeMediaVolta, milissegundosVelocidadeMediaVolta;
                if (!int.TryParse(rawVelocidadeMediaVolta[0], out segundosVelocidadeMediaVolta) ||
                    !int.TryParse(rawVelocidadeMediaVolta[1], out milissegundosVelocidadeMediaVolta))
                {
                    throw new NotSupportedException($"O formato da velocidade média da volta não é suportado! {cols[4]}");
                }
                velocidadeMediaVolta = new TimeSpan(0, 0, 0, segundosVelocidadeMediaVolta, milissegundosVelocidadeMediaVolta);
            }

            #endregion

            #region new Volta()

            var volta = new Volta();

            volta.horaRegistro         = horaRegistro;
            volta.piloto               = piloto;
            volta.numeroVolta          = numeroVolta;
            volta.tempoVolta           = tempoVolta;
            volta.velocidadeMediaVolta = velocidadeMediaVolta;

            #endregion

            return(volta);
        }