コード例 #1
0
        public static void Sample()
        {
            var iracing = new iRacingConnection();

            Trace.WriteLine("Moving to 4 minutes before end of replay");

            iracing.Replay.MoveToFrame(4 * 60 * 60, ReplayPositionMode.End);
            iracing.Replay.SetSpeed(2);
            Thread.Sleep(3000);

            int lastCount = 0;

            foreach (var data in iracing.GetDataFeed().AtSpeed(8)
                .WithFinishingStatus()
                .TakeUntil(5.Seconds()).After(data => data.Telemetry.RaceCars.All( c => c.HasSeenCheckeredFlag || c.HasRetired ))
                .TakeUntil(2.Seconds()).AfterReplayPaused()
                )
            {
                var count = data.Telemetry.RaceCars.Count(c => c.HasSeenCheckeredFlag || c.HasRetired);

                if (lastCount != count)
                {
                    foreach( var x in data.Telemetry.RaceCars)
                        Trace.WriteLine(string.Format("{0,20}\tHasSeenCheckedFlag: {1}\tHasRetired: {2}", x.Details.UserName, x.HasSeenCheckeredFlag, x.HasRetired));

                    Trace.WriteLine(string.Format("{0} finishers", count));
                }
                lastCount = count;
            }

            iracing.Replay.SetSpeed(0);
            Trace.WriteLine("Finished.");
        }
コード例 #2
0
        public static void Sample()
        {
            var iracing = new iRacingConnection();
            var ieventRacing = new iRacingEvents();

            ieventRacing.Connected += ieventRacing_Connected;
            ieventRacing.Disconnected += ieventRacing_Disconnected;
            ieventRacing.StartListening();

            iracing.Connected += iracing_Connected;
            iracing.Disconnected += iracing_Disconnected;

            try
            {
                var i = 0;

                foreach (var d in iracing.GetDataFeed())
                {
                    if (i++ % 600 == 0)
                        Trace.WriteLine(string.Format("Data Stream IsConnected = {0}", d.IsConnected));
                }
            }
            finally
            {
                ieventRacing.StopListening();
            }
        }
コード例 #3
0
        public static void Sample()
        {
            var iracing = new iRacingConnection();

            iracing.Replay.MoveToStartOfRace();
            iracing.Replay.SetSpeed(8);

            var time = new TimeSpan();
            iracing.Replay.SetSpeed(1);



            foreach (var data in iracing.GetDataFeed().WithFinishingStatus())
            {
                if( data.Telemetry.SessionTimeSpan > time)
                {
                    MyListener.Clear();

                    
   

                    foreach (var c in data.Telemetry.Cars.Where(c => !c.Details.IsPaceCar))
                        Trace.WriteLine(string.Format("{0,-20}\tCheckedFlag: {1}\tRetired: {2}\tData:{3}", c.Details.UserName, c.HasSeenCheckeredFlag, c.HasRetired, c.HasData));

                    Trace.WriteLine("");
                    Trace.WriteLine(string.Format("IsFinalLap: {0}, LeaderHasFinished: {1}", data.Telemetry.IsFinalLap, data.Telemetry.LeaderHasFinished));
                    Trace.WriteLine("");
                    Trace.WriteLine("");

                    time = data.Telemetry.SessionTimeSpan + (5*8).Seconds();
                }
            }
        }
コード例 #4
0
        void Listen()
        {
            var isConnected           = false;
            var isDisconnected        = true;
            var lastSessionInfoUpdate = -1;

            try
            {
                foreach (var d in instance.GetDataFeed(logging: false))
                {
                    if (requestCancel)
                    {
                        return;
                    }

                    if (!isConnected && d.IsConnected)
                    {
                        isConnected    = true;
                        isDisconnected = false;
                        connected.Invoke();
                    }

                    if (!isDisconnected && !d.IsConnected)
                    {
                        isConnected    = false;
                        isDisconnected = true;
                        disconnected.Invoke();
                    }

                    if (d.IsConnected)
                    {
                        newData.Invoke(d);
                    }

                    if (d.IsConnected && d.SessionData.InfoUpdate != lastSessionInfoUpdate)
                    {
                        lastSessionInfoUpdate = d.SessionData.InfoUpdate;
                        newSessionData.Invoke(d);
                    }
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.Message, "DEBUG");
                Trace.WriteLine(e.StackTrace, "DEBUG");
            }
            finally
            {
                backListener = null;
            }
        }
コード例 #5
0
        public static void Sample()
        {
            var iracing = new iRacingConnection();
            var i = 0;

            foreach (var data in iracing.GetDataFeed())
                if (i++ % 100 == 0)
                {
                    Trace.WriteLine("Processing Time: {0} micro seconds".F(iracing.ProcessingTime));
                    Trace.WriteLine("Waiting Time: {0} micro seconds".F(iracing.WaitingTime));
                    Trace.WriteLine("Yield Time: {0} micro seconds".F(iracing.YieldTime));
                    Trace.WriteLine("");
                }
        }
コード例 #6
0
        public static void Sample()
        {
            var iracing = new iRacingConnection();

            var data = iracing.GetDataFeed()
                .WithCorrectedPercentages()
                .AtSpeed(16)
                .RaceOnly()
                .First(d => d.Telemetry.SessionState == SessionState.Racing);

            var raceStartFrameNumber = data.Telemetry.ReplayFrameNum - (60 * 20);

            iRacing.Replay.MoveToFrame(raceStartFrameNumber);

            Trace.WriteLine("Sample Finished");
        }
コード例 #7
0
        public static void Sample()
        {
            FastLap lastFastestLap = null;
            var iracing = new iRacingConnection();

            Trace.WriteLine("Moving to start of race");
            iracing.Replay.MoveToStartOfRace();
            Trace.WriteLine("Watching for fastest laps");

            foreach (var data in iracing.GetDataFeed().AtSpeed(16).WithFastestLaps())
            {
                if (lastFastestLap != data.Telemetry.FastestLap)
                    Trace.WriteLine(string.Format("{0} - {1}", data.Telemetry.FastestLap.Driver.UserName, data.Telemetry.FastestLap.Time));

                lastFastestLap = data.Telemetry.FastestLap;
            }
        }
コード例 #8
0
        public static void Sample()
        {
            var iracing = new iRacingConnection();

            iracing.Replay.MoveToStartOfRace();
            iracing.Replay.SetSpeed(1);

            var i = 0;

            foreach (var data in iracing.GetDataFeed()
                .WithCorrectedPercentages()
                .WithCorrectedDistances()
                .WithFinishingStatus())
            {
                i++;
                if( i % 200 == 0)
                {
                    MyListener.Clear();

                    var car = data.Telemetry.Cars
                        .Where(c => c.TotalDistance > 0)
                        .Where(c => !c.HasSeenCheckeredFlag)
                        .Where(c => !c.Details.IsPaceCar)
                        .Where(c => c.HasData)
                        .Where(c => c.Details.Driver != null)
                        .Where(c => c.TrackSurface == TrackLocation.OnTrack)
                        .OrderByDescending(c => c.TotalDistance)
                        .ThenBy(c => c.OfficialPostion == 0 ? int.MaxValue : c.OfficialPostion)
                        .FirstOrDefault();

                    Trace.WriteLine("=============================================================");
                    Trace.WriteLine(string.Format("Next Finisher is {0}", car == null ? "null" : car.Details.UserName));

                    Trace.WriteLine("Driver Distances");
                    Trace.WriteLine("================");

                    Trace.WriteLine("RaceDistance: {0}".F(data.Telemetry.RaceDistance));
                    Trace.WriteLine("");

                    foreach (var c in data.Telemetry.Cars.OrderByDescending(d => d.TotalDistance).ThenBy(c => c.OfficialPostion == 0 ? int.MaxValue : c.OfficialPostion))
                        Trace.WriteLine(string.Format("{0}, dist: {1}, pos: {2}, official pos: {3}", c.Details.UserName, c.TotalDistance, c.Position, c.OfficialPostion));
                }
            }
        }
コード例 #9
0
        public static void Sample()
        {
            var iracing = new iRacingConnection();

            foreach (var data in iracing.GetDataFeed()
                .WithCorrectedPercentages()
                .WithCorrectedDistances()
                .WithPitStopCounts())
            {

                var tele = data.Telemetry;

                Trace.WriteLine(data.Telemetry.ToString());

                //Trace.WriteLine(data.SessionData.Raw);

                System.Diagnostics.Debugger.Break();

            }
        }
コード例 #10
0
        public static void Sample()
        {
            var instance1 = new iRacingEvents();
            instance1.NewData += instance1_NewData;
            instance1.StartListening();

            var iracingInstance = new iRacingConnection();

            var start = DateTime.Now;
            foreach (var data in iracingInstance.GetDataFeed())
            {
                if (DateTime.Now - start > TimeSpan.FromSeconds(1))
                    break;

                traceMessages.Enqueue(string.Format("Enumerable Data Tick {0}", data.Telemetry.TickCount));
            }

            instance1.StopListening();

            foreach (var m in traceMessages)
                Trace.WriteLine(m);
        }
コード例 #11
0
        public static void Sample()
        {
            var iracing = new iRacingConnection();

            Trace.WriteLine("Moving to start of race");
            iracing.Replay.MoveToStartOfRace();
            Trace.WriteLine("Watching first 2 laps + plus 5 seconds");

            int lastLap = -1;

            foreach (var data in iracing.GetDataFeed().AtSpeed(8)
                .TakeUntil(20.Seconds()).Of(data => data.Telemetry.RaceLaps == 2)
                .TakeUntil(20.Seconds()).AfterReplayPaused())
            {
                if (lastLap != data.Telemetry.RaceLaps)
                    Trace.WriteLine(string.Format("Lap: {0}", data.Telemetry.RaceLaps));
            
                lastLap = data.Telemetry.RaceLaps;
            }

            iracing.Replay.SetSpeed(0);
            Trace.WriteLine("Finished.");
        }
コード例 #12
0
 public static IEnumerable <DataSample> GetDataFeed()
 {
     return(instance.GetDataFeed());
 }
コード例 #13
0
        void Listen()
        {
            var isConnected           = false;
            var isDisconnected        = true;
            var lastSessionInfoUpdate = -1;

            var periodCount   = this.period;
            var lastTimeStamp = DateTime.Now;

            try
            {
                foreach (var d in instance.GetDataFeed(logging: false))
                {
                    if (requestCancel)
                    {
                        return;
                    }

                    if (!isConnected && d.IsConnected)
                    {
                        isConnected    = true;
                        isDisconnected = false;
                        connected.Invoke();
                    }

                    if (!isDisconnected && !d.IsConnected)
                    {
                        isConnected    = false;
                        isDisconnected = true;
                        disconnected.Invoke();
                    }

                    if (period >= (DateTime.Now - lastTimeStamp))
                    {
                        continue;
                    }

                    lastTimeStamp = DateTime.Now;

                    if (d.IsConnected)
                    {
                        newData.Invoke(d);
                    }

                    if (d.IsConnected && d.SessionData.InfoUpdate != lastSessionInfoUpdate)
                    {
                        lastSessionInfoUpdate = d.SessionData.InfoUpdate;
                        newSessionData.Invoke(d);
                    }
                }
            }
            catch (Exception e)
            {
                TraceError.WriteLine(e.Message);
                TraceError.WriteLine(e.StackTrace);
            }
            finally
            {
                backListener = null;
            }
        }