private async void RunStatsRequestLoop() { var steamKey = Environment.GetEnvironmentVariable("STEAM_KEY"); SteamApi.Init(steamKey); var requestUri = BuildUri(); while (_running) { var apiResponse = await SteamApi.Request <SteamUserStatsForGameResponse>(requestUri, DefaultJsonOptions.Instance); var apiResponseContent = apiResponse.Content; var playerStats = apiResponseContent.PlayerStats; Logger.Info("Received stats of player {0} for {1}", playerStats.SteamId, playerStats.GameName); UpdateGameState(playerStats.Stats); var utcNow = DateTimeOffset.UtcNow; var offset = apiResponse.Expires.Subtract(utcNow); Logger.Trace("Next steam request in {0} (now: {1}, expires: {2})", offset, utcNow, apiResponse.Expires); await Task.Delay(offset); } SteamApi.Reset(); }
public static void Setup() { if (!Directory.Exists(AppEnvironment.DataPath)) { Directory.CreateDirectory(AppEnvironment.DataPath); } if (!Debugger.IsAttached) { ExceptionHandler.AddGlobalHandlers(); } Config.Load(); if (!Config.Instance.AppSettings.DisableSteamIntegration) { SteamApi.Init(); } }
static void Main() { if (!Debugger.IsAttached) { ExceptionHandler.AddGlobalHandlers(); } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (!AppEnvironment.SettingValue("DisableSteamIntegration", false)) { try { SteamLoaded = SteamApi.Init(); } catch (Exception ex) { Console.WriteLine(ex.GetType().ToString() + "\r\n" + ex.Message, "A fatal Steam error was detected"); } } // create the application data path, if necessary try { if (!Directory.Exists(AppEnvironment.DataPath)) { Directory.CreateDirectory(AppEnvironment.DataPath); } } catch { // ignored } Application.Run(new Forms.MainWindow()); }