예제 #1
0
        public void Fill(NonRaceSession session, DriverEntry te)
        {
            if (te.IsPaceCar)
            {
                return;
            }

            int carIdx = te.CarIdx;

            Driver d = session.Weekend.Season.Drivers.TryGetBestBy(te.CarNum, te.Name);

            if (d == null)
            {
                d = Driver.Create(te.CarNum, te.Name);
                session.Weekend.Season.Drivers.Add(d);
            }

            if (session.Weekend.Drivers.ContainsKey(carIdx))
            {
                Driver existing = session.Weekend.Drivers[carIdx];
                if (existing.Number != d.Number || existing.NameSurname != d.NameSurname)
                {
                    throw new Exception("The driver names with same number between sessions differs, which is not allowed in one race weekend.");
                }
            }
            else
            {
                session.Weekend.Drivers.Add(carIdx, d);
            }
        }
        private static bool AreDriverEntriesTheSame(DriverEntry existing, DriverEntry driverEntry)
        {
            if (existing.CarFile != driverEntry.CarFile)
            {
                return(false);
            }
            if (existing.CarIdx != driverEntry.CarIdx)
            {
                return(false);
            }
            if (existing.CarMake != driverEntry.CarMake)
            {
                return(false);
            }
            if (existing.CarNum != driverEntry.CarNum)
            {
                return(false);
            }
            if (existing.Flags != driverEntry.Flags)
            {
                return(false);
            }
            if (existing.Name != driverEntry.Name)
            {
                return(false);
            }

            return(true);
        }
예제 #3
0
        public void Update(DriverEntry e)
        {
#if IGNORE_PACE_CAR
            if (e.IsPaceCar)
            {
                return;
            }
#endif

            Driver d = null;
            d = w.Drivers.TryGetByIdx(e.CarIdx);
            if (d == null)
            {
                d = new Driver(e.CarIdx);
                w.AddDriver(d);
            }
            if (d.CarNumber != e.CarNum)
            {
                d.CarNumber = e.CarNum;
            }
            if (d.Name != e.Name)
            {
                d.Name = e.Name;
            }
        }
예제 #4
0
        public static Driver Convert(DriverEntry driverInfo)
        {
            Driver ret = new Driver(driverInfo.CarIdx);

            ret.CarNumber = driverInfo.CarNum;
            ret.Name      = driverInfo.Name;
            return(ret);
        }
예제 #5
0
        public static void Release(RemoteWebDriver driver)
        {
            DriverEntry entry = AllEntries.FirstOrDefault(x => x.Driver == driver);

            if (entry != null)
            {
                entry.IsAcquired = false;
            }
        }
예제 #6
0
        /// <summary>
        /// Acquires the driver for the specific <paramref name="driverFactory"/>.
        /// </summary>
        /// <param name="driverFactory">The driver factory.</param>
        /// <param name="poolScopeObject">
        /// The pool scope object.
        /// Is optional.
        /// Mostly can be a fixture class object.
        /// When is <see langword="null"/> then will use whole global common pool;
        /// otherwise will use separate pool for particular scope object.
        /// </param>
        /// <returns>A <see cref="RemoteWebDriver"/> created or gotten from pool.</returns>
        /// <exception cref="ArgumentNullException">driverFactory</exception>
        public static RemoteWebDriver Acquire(IDriverFactory driverFactory, object poolScopeObject = null)
        {
            if (driverFactory == null)
            {
                throw new ArgumentNullException(nameof(driverFactory));
            }

            ConcurrentBag <DriverEntry> entries = ResolveEntriesBag(poolScopeObject);

            Monitor.Enter(entries);

            try
            {
                DriverEntry entry = entries.FirstOrDefault(x => x.Alias == driverFactory.Alias && !x.IsAcquired);

                if (entry is null)
                {
                    Monitor.Exit(entries);

                    entry            = CreateDriverEntry(driverFactory);
                    entry.IsAcquired = true;

                    entries.Add(entry);
                }
                else
                {
                    entry.IsAcquired = true;
                }

                return(entry.Driver);
            }
            finally
            {
                if (Monitor.IsEntered(entries))
                {
                    Monitor.Exit(entries);
                }
            }
        }
        internal static SessionBlock[] AnalyseTelemetry(TelemetryEvent[] events)
        {
            List <SessionBlock> ret = new List <SessionBlock>();

            CurrentWeekend        currentWeekend       = null;
            SessionInfo           currentSession       = null;
            List <TelemetryEvent> currentSessionEvents = new List <TelemetryEvent>();
            List <DriverEntry>    globalDrivers        = new List <DriverEntry>();
            List <DriverEntry>    localDrivers         = new List <DriverEntry>();
            double lastSessionTime = 0;

            for (int f = 0; f < events.Length; f++)
            {
                TelemetryEvent te = events[f];

                if (te is DriverEntry)
                {
                    if (currentWeekend == null)
                    {
                        DriverEntry existing = globalDrivers.FirstOrDefault(i => (i.CarIdx == (te as DriverEntry).CarIdx));
                        if (existing != null)
                        {
                            if (AreDriverEntriesTheSame(existing, te as DriverEntry) == false)
                            {
                                throw new ApplicationException("Duplicit driver entry CarIdx.");
                            }
                        }
                        else
                        {
                            globalDrivers.Add(te as DriverEntry);
                        }
                    }
                    else
                    {
                        if (localDrivers.FirstOrDefault(i => (i.CarIdx == (te as DriverEntry).CarIdx)) != null)
                        {
                            throw new ApplicationException("Duplicit driver entry CarIdx.");
                        }
                        localDrivers.Add(te as DriverEntry);
                    }
                }
                else if (te is DriverWithdrawl)
                {
                }
                else if (te is CurrentWeekend)
                {
                    if (currentWeekend != null)
                    {
                        SessionBlock sb = BuildNewSessionBlock(
                            currentWeekend, currentSession, currentSessionEvents,
                            globalDrivers, localDrivers);
                        ret.Add(sb);

                        currentWeekend = null;
                        localDrivers   = new List <DriverEntry>();
                    }
                    CurrentWeekend x = te as CurrentWeekend;
                    if (x.AtTrack == false)
                    {
                        currentWeekend = null;
                    }
                    else
                    {
                        currentWeekend = x;
                    }
                }
                else if (te is SessionInfo)
                {
                    //if (currentWeekend == null && currentSession == null) continue;

                    SessionInfo x = te as SessionInfo;
                    //bool isNewSession = (currentSession == null
                    //  || IsNewSession(x));
                    bool isNewSession = (currentSession == null ||
                                         x.CurrentTime <= lastSessionTime);

                    if (isNewSession)
                    {
                        if (currentSession != null && currentWeekend != null)
                        {
                            SessionBlock sb = BuildNewSessionBlock(
                                currentWeekend, currentSession, currentSessionEvents,
                                globalDrivers, localDrivers);
                            ret.Add(sb);
                        }
                        currentSession       = x;
                        currentSessionEvents = new List <TelemetryEvent>();
                    }
                    else
                    {
                        currentSessionEvents.Add(te);
                    }

                    lastSessionTime = x.CurrentTime;
                }
                else
                {
                    if (currentSession != null)
                    {
                        currentSessionEvents.Add(te);
                    }
                }
            }

            return(ret.ToArray());
        }