void Delete(IDbConnection connection, DeleteAnnouncement request) { var subscriber = connection.GetById <Subscriber>(request.SubscriberId); var announcement = connection.First(NextAnnouncement.make(connection, subscriber)); if (announcement.Id != request.AnnouncementId) { throw new ArgumentException("Invalid announcement"); } connection.UpdateOnly(new Subscriber { LastAnnouncementId = announcement.Id }, subscription => new { subscription.LastAnnouncementId }, subscription => subscription.Id == subscriber.Id); Propagators.ScheduleTopicOperation(request.TopicName, () => Propagate(request)); }
Announcement ReadFromDb(IDbConnection connection, Subscriber subscriber, ReadAnnouncement request) { var topicLock = Locks.TakeTopicLock(request.TopicName); lock (topicLock) { var query = NextAnnouncement.make(connection, subscriber); var announcement = connection.FirstOrDefault(query); while (announcement == null) { Monitor.Wait(topicLock); announcement = connection.FirstOrDefault(query); } return(announcement); } }