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.");
        }
Ejemplo n.º 2
0
        public static void Sample()
        {
            var iracing = new iRacingConnection();

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

            var time = new TimeSpan();

            foreach (var data in iracing.GetDataFeed().WithFinishingStatus().AtSpeed(16))
            {
                if (data.Telemetry.SessionTimeSpan > time)
                {
                    Trace.WriteLine("=============================================================");

                    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();
                }
            }
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
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.");
        }
Ejemplo n.º 5
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();
            }
        }
        public static void Sample()
        {
            var iracing = new iRacingConnection();

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

            foreach (var data in iracing.GetDataFeed()
                     .WithCorrectedPercentages()
                     .WithCorrectedDistances())
            {
                MyListener.Clear();

                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))
                {
                    Trace.WriteLine(string.Format("{0}, dist: {1}, pos: {2}", c.Details.UserName, c.TotalDistance, c.Position));
                }

                Thread.Sleep(2000);
            }
        }
Ejemplo n.º 7
0
        public static void Sample()
        {
            var iracing = new iRacingConnection();

            foreach (var data in iracing.GetDataFeed()
                     .WithCorrectedPercentages()
                     .WithCorrectedDistances()
                     .WithPitStopCounts())
            {
                Trace.WriteLine("CamGroupNumber selected: {0}".F(data.Telemetry.CamGroupNumber));
                Thread.Sleep(1000);
            }
        }
        public static void Sample()
        {
            var iracing = new iRacingConnection();

            foreach (var data in iracing.GetDataFeed()
                     .WithCorrectedPercentages()
                     .WithCorrectedDistances())
            {
                System.Diagnostics.Debugger.Break();

                var inspectData = data;
            }
        }
Ejemplo n.º 9
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");
        }
        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("");
                }
            }
        }
        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));
                    }
                }
            }
        }
Ejemplo n.º 12
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();
            }
        }
        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;
            }
        }
        void Process()
        {
            try
            {
                var averageFuelPerLap = AverageFuelUsage.Capture(avg => AverageFuelPerLap = avg);
                var onEachLap         = OnEachLap.Capture(averageFuelPerLap);

                var averageLapTime   = AverageTime.Capture(avg => AverageLapTimeSpan = avg);
                var onEachSessionLap = OnEachSessionLap.Capture(averageLapTime);
                var onEachSession    = OnEachSessionUpdate.Capture(onEachSessionLap);

                var data      = CaptureLatestData(EmitTo.All(onEachLap, onEachSession));
                var connected = ConnectedDataOnly(data);

                iracing.GetDataFeed().EmitTo(StopOnRequestCancel(connected));
            }
            catch (Exception e)
            {
                Trace.WriteLine("Non Recoverable error in DataCollector. {0}".F(e.Message), "INFO");
                Trace.WriteLine(e.StackTrace, "DEBUG");
            }
        }
Ejemplo n.º 15
0
        private void RunButton_Click(object sender, EventArgs e)
        {
            try
            {
                lblMessage.Text = "Running...";
                Random random = new Random();

                string        filepath = PaintFileTextBox.Text + @"\" + CarDropDown.SelectedValue;
                DirectoryInfo d        = new DirectoryInfo(filepath);

                string saveLocation = SaveFileTextBox.Text + @"\" + CarDropDown.SelectedItem + @"\" + random.Next(1, 1000) + @"\";

                //iRacing SDK connects to game
                var iracing = new iRacingConnection();
                var data    = iracing.GetDataFeed().First();

                var ieventRacing = new iRacingEvents();
                ieventRacing.StartListening();

                List <UserDriverObject> userDriverObjects = new List <UserDriverObject>();

                foreach (SessionData._DriverInfo._Drivers car in data.SessionData.DriverInfo.CompetingDrivers)
                {
                    UserDriverObject userDriverObject = new UserDriverObject();
                    //dont include pace car
                    if (car.UserID == -1)
                    {
                        continue;
                    }

                    userDriverObject.ID     = car.UserID.ToString();
                    userDriverObject.Name   = car.UserName;
                    userDriverObject.Number = car.CarNumber;
                    userDriverObject.File   = "car_" + car.UserID.ToString() + ".tga";

                    //set rim color if specified
                    if (car.CarDesignStr.Split(";").Count() > 1)
                    {
                        userDriverObject.RimColor = car.CarDesignStr.Split(";")[1];
                    }
                    else
                    {
                        userDriverObject.RimColor = "000000";
                    }
                    userDriverObject.NumberColor1 = car.CarNumberDesignStr.Split(",")[2] + "," + car.CarNumberDesignStr.Split(",")[3] + "," + car.CarNumberDesignStr.Split(",")[4];
                    userDriverObject.NumberColor2 = car.CarNumberDesignStr.Split(",")[0];

                    userDriverObjects.Add(userDriverObject);
                }

                //Order By Car Number
                userDriverObjects = userDriverObjects.OrderBy(x => x.Number).ToList();

                //get paint files from local directory
                foreach (FileInfo file in d.GetFiles("*.tga"))
                {
                    string imageUrl = "";
                    string savename = "";
                    if (userDriverObjects.Where(x => x.File == file.Name.Replace("num_", "")).ToList().Count > 0)
                    {
                        //check for custom number paint
                        //use iRacing provided thumbnails
                        if (file.Name.Contains("num"))
                        {
                            imageUrl = @"http://*****:*****@"\") + "&carRimCol=" + userDriverObjects.Where(x => x.File == file.Name.Replace("num_", "")).FirstOrDefault().RimColor + "&carCustPaint=" + PaintFileTextBox.Text + @"\" + CarDropDown.SelectedValue + @"\" + file.Name;
                            savename = userDriverObjects.Where(x => x.File == file.Name.Replace("num_", "")).FirstOrDefault().Number + "_" + userDriverObjects.Where(x => x.File == file.Name.Replace("num_", "")).FirstOrDefault().Name;
                        }
                        else
                        {
                            imageUrl = @"http://*****:*****@"\") + "&number=" + userDriverObjects.Where(x => x.File == file.Name).FirstOrDefault().Number + "&carRimCol=" + userDriverObjects.Where(x => x.File == file.Name).FirstOrDefault().RimColor + "&numCol=" + userDriverObjects.Where(x => x.File == file.Name).FirstOrDefault().NumberColor1 + "&numPat=" + userDriverObjects.Where(x => x.File == file.Name).FirstOrDefault().NumberColor2 + "&carCustPaint=" + PaintFileTextBox.Text + @"\" + CarDropDown.SelectedValue + @"\" + file.Name;
                            savename = userDriverObjects.Where(x => x.File == file.Name).FirstOrDefault().Number + "_" + userDriverObjects.Where(x => x.File == file.Name).FirstOrDefault().Name;
                        }
                    }
                    else
                    {
                        imageUrl = @"http://*****:*****@"\") + "&number=1&numCol=FFFFFF,000000,000000&carCustPaint=" + PaintFileTextBox.Text + @"\" + CarDropDown.SelectedValue + @"\" + file.Name;
                        savename = file.Name.Replace(file.Extension, "");
                    }

                    //write image
                    byte[]         imageBytes;
                    HttpWebRequest imageRequest  = (HttpWebRequest)WebRequest.Create(imageUrl);
                    WebResponse    imageResponse = imageRequest.GetResponse();

                    Stream responseStream = imageResponse.GetResponseStream();

                    using (BinaryReader br = new BinaryReader(responseStream))
                    {
                        imageBytes = br.ReadBytes(500000);
                        br.Close();
                    }
                    responseStream.Close();
                    imageResponse.Close();


                    System.IO.Directory.CreateDirectory(saveLocation);


                    FileStream   fs = new FileStream(saveLocation + savename + ".png", FileMode.Create);
                    BinaryWriter bw = new BinaryWriter(fs);
                    try
                    {
                        bw.Write(imageBytes);
                    }
                    finally
                    {
                        fs.Close();
                        bw.Close();
                    }
                }


                //merge files into 1 spotter guide
                if (chkMerge.Checked)
                {
                    // Get the picture files in the source directory.
                    List <FileInfo> files = new List <FileInfo>();
                    foreach (string filename in Directory.GetFiles(saveLocation))
                    {
                        int    pos       = filename.LastIndexOf('.');
                        string extension = filename.Substring(pos).ToLower();
                        if ((extension == ".bmp") ||
                            (extension == ".jpg") ||
                            (extension == ".jpeg") ||
                            (extension == ".png") ||
                            (extension == ".tif") ||
                            (extension == ".tiff") ||
                            (extension == ".gif"))
                        {
                            files.Add(new FileInfo(filename));
                        }
                    }
                    files = files.Select(s => new { Str = s, Split = s.Name.Split('_') })
                            .OrderBy(x => int.Parse(x.Split[0]))
                            .ThenBy(x => x.Split[1])
                            .Select(x => x.Str)
                            .ToList();
                    int num_images = files.Count;

                    // Load the images.
                    Bitmap[] images    = new Bitmap[files.Count];
                    String[] imageName = new String[files.Count];
                    for (int i = 0; i < num_images; i++)
                    {
                        images[i]    = new Bitmap(files[i].FullName);
                        imageName[i] = new String(files[i].Name);
                    }

                    // Find the largest width and height.
                    int max_wid = 0;
                    int max_hgt = 0;
                    for (int i = 0; i < num_images; i++)
                    {
                        if (max_wid < images[i].Width)
                        {
                            max_wid = images[i].Width;
                        }
                        if (max_hgt < images[i].Height)
                        {
                            max_hgt = images[i].Height;
                        }
                    }

                    // Make the result bitmap.
                    int marginX  = 100;
                    int marginY  = 100;
                    int num_cols = int.Parse(txtColumns.Text);
                    int num_rows = (int)Math.Ceiling(num_images / (float)num_cols);
                    //increment rows for extra space
                    num_rows++;
                    int    wid = max_wid * num_cols + marginX * (num_cols - 1);
                    int    hgt = max_hgt * num_rows + marginY * (num_rows - 1);
                    Bitmap bm  = new Bitmap(wid, hgt);

                    // Place the images on it.
                    using (Graphics gr = Graphics.FromImage(bm))
                    {
                        gr.Clear(Color.Transparent);

                        //pic is 508x272

                        int x = 0;
                        int y = marginY;
                        for (int i = 0; i < num_images; i++)
                        {
                            gr.DrawImage(images[i], x, y);
                            using (Font arialFont = new Font("RussellSquare", 30))
                            {
                                string value = "#" + imageName[i].Split("_")[0] + " " + imageName[i].Split("_")[1].Replace(".png", "");
                                gr.DrawString(value, arialFont, Brushes.White, new Point((int)(x + (max_wid - gr.MeasureString(value, arialFont).Width) / 2f), y + max_hgt));
                            }
                            x += max_wid + marginX;
                            if (x >= wid)
                            {
                                y += max_hgt + marginY;
                                x  = 0;
                            }
                        }
                    }

                    // Save the result.
                    bm.Save(saveLocation + "MergedImage.png", System.Drawing.Imaging.ImageFormat.Png);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            lblMessage.Text = "Done!";
        }