void ISubscriptionStorage.Subscribe(Address address, IEnumerable <MessageType> messageTypes) { using (var transaction = new TransactionScope(TransactionScopeOption.Suppress)) using (var session = subscriptionStorageSessionProvider.OpenSession()) using (var tx = session.BeginTransaction(System.Data.IsolationLevel.ReadCommitted)) { foreach (var messageType in messageTypes) { var type = messageType; if (session.QueryOver <Subscription>() .Where(s => s.TypeName == type.TypeName && s.SubscriberEndpoint == address.ToString()) .List() .Any(s => new MessageType(s.TypeName, s.Version) == messageType)) { continue; } session.Save(new Subscription { SubscriberEndpoint = address.ToString(), MessageType = messageType.TypeName + "," + messageType.Version, Version = messageType.Version.ToString(), TypeName = messageType.TypeName }); } tx.Commit(); transaction.Complete(); } }
/// <summary> /// Adds the given subscription to the DB. /// Method checks for existing subcriptions to prevent duplicates /// </summary> /// <param name="client"></param> /// <param name="messageTypes"></param> void ISubscriptionStorage.Subscribe(string client, IEnumerable <string> messageTypes) { using (var transaction = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) using (var session = subscriptionStorageSessionProvider.OpenSession()) { foreach (var messageType in messageTypes) { var subscription = new Subscription { SubscriberEndpoint = client, MessageType = messageType }; if (session.Get <Subscription>(subscription) == null) { session.Save(subscription); } } transaction.Complete(); } }
void ISubscriptionStorage.Subscribe(Address address, IEnumerable <MessageType> messageTypes) { using (var session = sessionSource.OpenSession()) using (var transaction = new TransactionScope()) { foreach (var messageType in messageTypes) { var subscription = new Subscription { SubscriberEndpoint = EncodeTo64(address.ToString()), MessageType = messageType.ToString() }; if (session.Get <Subscription>(subscription) == null) { session.Save(subscription); } } transaction.Complete(); session.Flush(); } }