Ejemplo n.º 1
0
        public IRacingSDK(MemoryMappedViewAccessor accessor)
        {
            // Register CP1252 encoding
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            _encoding = Encoding.GetEncoding(1252);

            FileMapView = accessor;

            Header = new IRacingSdkHeader(FileMapView);
            GetVarHeaders();
            IsStarted = true;
        }
Ejemplo n.º 2
0
        private void ConnectionLoop()
        {
            while (true)
            {
                if (_connectionLoopCancellationToken.IsCancellationRequested)
                {
                    break;
                }
                try
                {
                    if (!IsConnected() && !IsStarted && Header == null)
                    {
                        iRacingFile = MemoryMappedFile.OpenExisting(Constants.MemMapFileName);
                        FileMapView = iRacingFile.CreateViewAccessor();

                        _hEvent        = OpenEvent(Constants.DesiredAccess, false, Constants.DataValidEventName);
                        _gameLoopEvent = new AutoResetEvent(false)
                        {
                            SafeWaitHandle = new SafeWaitHandle(_hEvent, true)
                        };

                        IsStarted = true;
                        _logger?.LogDebug("Connected Starting");
                    }
                }
                catch (FileNotFoundException ex)
                {
                    IsStarted  = false;
                    Header     = null;
                    VarHeaders = null;
                    _logger?.LogDebug($"Not Connected {ex.Message}");
                }
                finally
                {
                    Thread.Sleep(1000);
                }
            }
        }
Ejemplo n.º 3
0
 private void WaitValidDataLoop()
 {
     while (true)
     {
         if (_waitValidDataLoopCancellationToken.IsCancellationRequested)
         {
             break;
         }
         if (IsStarted)
         {
             try
             {
                 _gameLoopEvent.WaitOne();
                 if (Header == null)
                 {
                     Header = new IRacingSdkHeader(FileMapView);
                 }
                 if (IsConnected() && VarHeaders == null)
                 {
                     GetVarHeaders();
                 }
                 if (!IsConnected() && VarHeaders != null)
                 {
                     VarHeaders = null;
                 }
             }
             catch
             {
             }
         }
         else
         {
             Thread.Sleep(1000);
         }
     }
 }