private static void TestConsumer(GameApi api, PlayersApi players, Configuration config) { GameRules rules = new GameRules(true, 2, "Test", 1, password: null); PrintHeader("Create Game"); int game = api.CreateGame(rules); Print("Game ID: " + game); Print("Stats : " + api.GetGameState(game)); PrintHeader("Join Game"); players.Join(game); ConsumerApi consumerApi = new ConsumerApi(config); JoinResponse response = consumerApi.RegisterConsumer(game, new ConsumerRegistration("Test", "Ein consumer")); Print($"id : {response.Id}"); Print($"pat : {response.Pat}"); players.Configuration.ApiKey["pat"] = response.Pat; api.Configuration.ApiKey["pat"] = response.Pat; config.ApiKey["pat"] = response.Pat; JoinResponse somePlayer = players.Join(game); Print(players.GetPlayer(game, somePlayer.Id).ToJson()); PrintHeader("Start Game"); api.CommitAction(game, ActionType.STARTGAME); PrintHeader("Fetch Events"); EventHandlingApi eventApi = new EventHandlingApi(config); for (int i = 0; i < 8; i++) { Print(eventApi.FetchNextEvent(game).Type.ToString()); } }
private static PlayersApi PlayersApiFactory(IServiceProvider arg) { IHttpClientFactory factory = arg.GetRequiredService <IHttpClientFactory>(); HttpClient httpClient = factory.CreateClient("cocApi"); TokenProvider tokenProvider = arg.GetRequiredService <TokenProvider>(); PlayersApi playersApi = new PlayersApi(httpClient, tokenProvider); return(playersApi); }
public IndiebackendAPI(string appId) { _http = new HttpUtils(Constants.API_GATEWAY, appId); // HTTP Services initialization Players = new PlayersApi(_http); Profiles = new ProfilesApi(_http); Groups = new GroupsApi(_http); Stats = new StatsApi(_http); }
internal override async void OnSettingsChanged(object?sender, UserSettingsEventArgs e) { if (e.ChangedKey != nameof(UserSettings.AllMaps)) { return; } Players = Enumerable.Empty <PlayerStatisticDto>(); StateHasChanged(); Players = (await PlayersApi.GetAllStatisticsAsync()).Where(p => p.BestGameSum is not null).ToList(); StateHasChanged(); }
static void Main(string[] args) { Configuration c = new Configuration { BasePath = "http://localhost:5050/v1" }; GameApi api = new GameApi(c); PlayersApi players = new PlayersApi(c); PrintHeader("{Test Game Lifecycle}"); TestStartGame(api, players, c); return; PrintHeader("\n{Test Consumers}"); TestConsumer(api, players, c); }
public ClansClient( Cache.ClientConfiguration cacheConfiguration, ClansApi clansApi, PlayersClient playersCache, LocationsApi locationsApi, PlayersApi playersApi) : base(cacheConfiguration, clansApi, playersCache) { _playersCache = playersCache; _locationsApi = locationsApi; _playersApi = playersApi; ClanUpdated += OnClanUpdated; ClanWarAdded += OnClanWarAdded; ClanWarLogUpdated += OnClanWarLogUpdated; ClanWarUpdated += OnClanWarUpdated; Log += OnLog; }
private static void TestStartGame(GameApi api, PlayersApi players, Configuration config) { GameRules rules = new GameRules(true, 2, "Test", 1, password: null); PrintHeader("Create Game"); int game = api.CreateGame(rules); Print("Game ID: " + game); Print("Stats : " + api.GetGameState(game)); PrintHeader("Join Game"); JoinResponse response = players.Join(game); Print($"id : {response.Id}"); Print($"pat : {response.Pat}"); players.Configuration.ApiKey["pat"] = response.Pat; api.Configuration.ApiKey["pat"] = response.Pat; config.ApiKey["pat"] = response.Pat; players.Join(game); Print(players.GetPlayer(game, response.Id).ToJson()); PrintHeader("Start Game"); api.CommitAction(game, ActionType.STARTGAME); PrintHeader("Fetch Events"); EventHandlingApi eventApi = new EventHandlingApi(config); bool run = true; int c = 1; try { while (run) { EventType type = eventApi.TraceEvent(game, wait: true, batch: false)[0]; run = type != EventType.Gameendevent; GenericEvent ev = eventApi.FetchNextEvent(game); Print(c++ + ". Event: " + type); Print(ev.ToJson() + "\n"); } } catch (Exception) { Console.Out.WriteLine("TraceEvent(" + game + ")"); throw; } }
public PlayerMonitor(ClientConfiguration cacheConfiguration, PlayersApi playersApi, PlayersClientBase playersClientBase) : base(cacheConfiguration) { _playersApi = playersApi; _playersClientBase = playersClientBase; }
protected override async Task OnInitializedAsync() { Players = (await PlayersApi.GetAllStatisticsAsync()).Where(p => p.BestGameSum is not null).ToList(); }
public PlayersClientBase(ClientConfiguration clientConfiguration, PlayersApi playersApi) : base(clientConfiguration) { _playersApi = playersApi; PlayerMontitor = new PlayerMonitor(clientConfiguration, _playersApi, this); }
public PlayersApiTests() { instance = new PlayersApi(); }
public PlayersClient(Cache.ClientConfiguration cacheConfiguration, PlayersApi playersApi) : base(cacheConfiguration, playersApi) { Log += OnLog; PlayerUpdated += OnPlayerUpdated; }
internal static async Task <CachedPlayer> FromPlayerResponseAsync(string tag, PlayersClientBase playersCacheBase, PlayersApi playersApi, CancellationToken?cancellationToken = default) { try { ApiResponse <Player> apiResponse = await playersApi.FetchPlayerResponseAsync(tag, cancellationToken).ConfigureAwait(false); return(new CachedPlayer(tag, apiResponse, await playersCacheBase.TimeToLiveAsync(apiResponse).ConfigureAwait(false))); } catch (Exception e) { return(new CachedPlayer(tag, await playersCacheBase.TimeToLiveAsync(e).ConfigureAwait(false))); } }