All the code
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using Gameboard.Shogi.Api.ServiceModels.Messages;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Websockets.Repositories;
|
||||
|
||||
namespace AspShogiSockets.Repositories.RepositoryManagers
|
||||
{
|
||||
public interface IGameboardRepositoryManager
|
||||
{
|
||||
Task<string> CreateGuestUser();
|
||||
}
|
||||
|
||||
public class GameboardRepositoryManager : IGameboardRepositoryManager
|
||||
{
|
||||
private readonly IGameboardRepository repository;
|
||||
private const int MaxTries = 3;
|
||||
|
||||
public GameboardRepositoryManager(IGameboardRepository repository)
|
||||
{
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
public async Task<string> CreateGuestUser()
|
||||
{
|
||||
var count = 0;
|
||||
while (count < MaxTries)
|
||||
{
|
||||
count++;
|
||||
var clientId = $"Guest-{Guid.NewGuid()}";
|
||||
var request = new PostPlayer
|
||||
{
|
||||
PlayerName = clientId
|
||||
};
|
||||
var response = await repository.PostPlayer(request);
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return clientId;
|
||||
}
|
||||
}
|
||||
throw new OperationCanceledException($"Failed to create guest user after {MaxTries} tries.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user