public override async Task CompleteRestoreAsync(Guid appId, BackupReader reader) { await appsByNameIndex.AddAppAsync(appId, appName); foreach (var user in contributors) { await grainFactory.GetGrain <IAppsByUserIndex>(user).AddAppAsync(appId); } }
public override async Task CompleteRestoreAsync(Guid appId, BackupReader reader) { await RebuildAsync <AppState, AppGrain>(appId, (e, s) => s.Apply(e)); await appsByNameIndex.AddAppAsync(appId, appName); foreach (var user in activeUsers) { await grainFactory.GetGrain <IAppsByUserIndex>(user).AddAppAsync(appId); } }
public async Task Should_add_app_to_index_on_create() { var context = new CommandContext(new CreateApp { AppId = appId, Name = "my-app" }, commandBus) .Complete(); await sut.HandleAsync(context); A.CallTo(() => index.AddAppAsync(appId, "my-app")) .MustHaveHappened(); }
public async Task HandleAsync(CommandContext context, Func <Task> next) { var createApp = context.Command as CreateApp; var isReserved = false; try { if (createApp != null) { isReserved = await index.ReserveAppAsync(createApp.AppId, createApp.Name); if (!isReserved) { var error = new ValidationError("An app with the same name already exists.", nameof(createApp.Name)); throw new ValidationException("Cannot create app.", error); } } await next(); if (context.IsCompleted) { if (createApp != null) { await index.AddAppAsync(createApp.AppId, createApp.Name); } else if (context.Command is ArchiveApp archiveApp) { await index.RemoveAppAsync(archiveApp.AppId); } } } finally { if (isReserved) { await index.RemoveReservationAsync(createApp.AppId, createApp.Name); } } }
public async Task HandleAsync(CommandContext context, Func <Task> next) { if (context.IsCompleted) { switch (context.Command) { case CreateApp createApp: await index.AddAppAsync(createApp.AppId, createApp.Name); break; case ArchiveApp archiveApp: await index.RemoveAppAsync(archiveApp.AppId); break; } } await next(); }