/// <summary> /// /// </summary> /// <typeparam name="TEntity"></typeparam> /// <param name="storeClient"></param> /// <param name="items"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public static Task <int> BulkUpsertAsync <TEntity>( this ILeaderboardsStoreClient storeClient, IEnumerable <TEntity> items, CancellationToken cancellationToken) where TEntity : class { if (storeClient == null) { throw new ArgumentNullException(nameof(storeClient)); } return(storeClient.BulkUpsertAsync(items, null, cancellationToken)); }
public async Task StoreClientIsNull_ThrowsArgumentNullException() { // Arrange ILeaderboardsStoreClient storeClient = null; var items = new List <object>(); var cancellationToken = CancellationToken.None; // Act -> Assert await Assert.ThrowsAsync <ArgumentNullException>(() => { return(storeClient.BulkUpsertAsync(items, cancellationToken)); }); }
public async Task StoreDailyLeaderboardsAsync( IEnumerable <DailyLeaderboard> leaderboards, CancellationToken cancellationToken) { using (var operation = telemetryClient.StartOperation <RequestTelemetry>("Store daily leaderboards")) { try { using (var activity = new StoreActivity(Log, "daily leaderboards")) { var rowsAffected = await storeClient.BulkUpsertAsync(leaderboards, cancellationToken).ConfigureAwait(false); activity.Report(rowsAffected); } using (var activity = new StoreActivity(Log, "players")) { var players = leaderboards .SelectMany(l => l.Entries) .Select(e => e.SteamId) .Distinct() .Select(s => new Player { SteamId = s }); var options = new BulkUpsertOptions { UpdateWhenMatched = false }; var rowsAffected = await storeClient.BulkUpsertAsync(players, options, cancellationToken).ConfigureAwait(false); activity.Report(rowsAffected); } using (var activity = new StoreActivity(Log, "replays")) { var replays = leaderboards .SelectMany(l => l.Entries) .Where(e => e.ReplayId != null) .Select(e => e.ReplayId.Value) .Distinct() .Select(r => new Replay { ReplayId = r }); var options = new BulkUpsertOptions { UpdateWhenMatched = false }; var rowsAffected = await storeClient.BulkUpsertAsync(replays, options, cancellationToken).ConfigureAwait(false); activity.Report(rowsAffected); } using (var activity = new StoreActivity(Log, "daily entries")) { var entries = leaderboards.SelectMany(e => e.Entries); var rowsAffected = await storeClient.BulkUpsertAsync(entries, cancellationToken).ConfigureAwait(false); activity.Report(rowsAffected); } operation.Telemetry.Success = true; } catch (Exception) when(operation.Telemetry.MarkAsUnsuccessful()) { } } }