public async Task <bool> TryAddChannel(TwitchChannel channel) { var record = new TwitchChannelRecord { Id = channel.Id, DisplayName = channel.DisplayName, Followers = channel.Followers }; using (var op = _log.BeginOperation("Adding channel to repository. Channel name {channelName} id {channelId}", channel.DisplayName, channel.Id)) using (ITransaction tx = _stateManager.CreateTransaction()) { var channelDictionary = await GetChannelDictionary(tx); if (!await channelDictionary.TryAddAsync(tx, record.Id, record)) { return(false); } await tx.CommitAsync() .ContinueWith(task => RepositoryIndexes.Instance.AddRecord(record.Id, record.DisplayName), TaskContinuationOptions.OnlyOnRanToCompletion); op.Complete(); } return(true); }
public async Task DeleteChannelById(string channelId) { using (var op = _log.BeginOperation("Removing channel {channelId} from repository", channelId)) using (ITransaction tx = _stateManager.CreateTransaction()) { var channelDictionary = await GetChannelDictionary(tx); ConditionalValue <TwitchChannelRecord> removedRecord = await channelDictionary.TryRemoveAsync(tx, channelId); if (!removedRecord.HasValue) { return; } TwitchChannelRecord record = removedRecord.Value; await tx.CommitAsync() .ContinueWith(task => RepositoryIndexes.Instance.RemoveRecord(record.Id, record.DisplayName), TaskContinuationOptions.OnlyOnRanToCompletion); op.Complete(); } }