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); } }
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(); } }
private void Run() { _iRacingConnection = new iRacingConnection(); _iRacingConnection.Connected += _iracing_Connected; if (_isAutoSend) { _iRacingEvents = new iRacingEvents(); _iRacingEvents.Connected += _iracingEvents_Connected; _iRacingEvents.Disconnected += _iracingEvents_Disconnected; _iRacingEvents.NewData += _iracingEvents_NewData; _iRacingEvents.NewSessionData += _iracingEvents_NewSessionData; _iRacingEvents.StartListening(); } }
public static void Sample() { var ieventRacing = new iRacingEvents(1.Seconds()); ieventRacing.Connected += ieventRacing_Connected; ieventRacing.Disconnected += ieventRacing_Disconnected; ieventRacing.NewData += ieventRacing_NewData; Trace.WriteLine("This sample show how to access game data through an event paradigm."); //The following statement would be best in your form_load handler ieventRacing.StartListening(); //Simulate a form opened for 10 seconds. Thread.Sleep(10000); //Stop listening when your app shuts down (say inside your form_unload handler). ieventRacing.StopListening(); Trace.WriteLine("Sample finished."); }
public Main() { iracingEvents = new iRacingEvents(); InitializeComponent(); }
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!"; }