private void EnsureUsersAreSetup(GameSetupInfo setupInfo) { Console.WriteLine("getting existing users from elastic"); var elasticUsersCount = _client.Count <ElasticUser>(s => s.Query(q => q.MatchAll())).Count; Console.WriteLine($"{elasticUsersCount} users found"); if (elasticUsersCount < setupInfo.NumberOfPlayers) { var numberLeftToCreate = Convert.ToInt32(setupInfo.NumberOfPlayers - elasticUsersCount); Console.WriteLine($"need to create {numberLeftToCreate} more users"); var users = _converter.Convert(new PlayerGenerator().Setup(numberLeftToCreate, setupInfo).ToList()); _writer.BulkWriteData(users, _client); } var playerGenerator = new PlayerGenerator(); _users = new List <User>(); long userCount = 0; while (userCount < setupInfo.NumberOfPlayers) { Console.WriteLine("_"); System.Threading.Thread.Sleep(10000); var elasticUsers = _client.RockAndScroll <ElasticUser>(StringConstants.UserIndex).Result.ToList(); userCount = elasticUsers.Count; if (userCount < setupInfo.NumberOfPlayers) { continue; } //convert them back so the system can use them. foreach (var elasticUser in elasticUsers) { _users.Add(playerGenerator.Convert(elasticUser, setupInfo)); } } Console.WriteLine($"{_users.Count} users loaded"); if (_users.Count == 0) { System.Diagnostics.Debugger.Break(); } }
public void WriteAllData <T>(List <T> data) where T : class { Console.WriteLine(""); Console.WriteLine($"starting to write {data.Count} {typeof(T).Name} entries."); var converter = new ElasticClassConverter(); var client = ElasticClientManager.CreateClient(); var type = typeof(T); if (data is List <User> users) { BulkWriteData(converter.Convert(users), client); } if (data is List <ElasticUserStat> userStats) { BulkWriteData(userStats, client); } if (data is List <ElasticBettingStat> bettingStats) { BulkWriteData(bettingStats, client); } }