public void Add(EventSubscription subscription)
 {
     var holder = ConvertToEventSubscriptionHolder(subscription);
     holder.Id = Guid.NewGuid();
     _entityContext.Insert(holder);
     _entityContext.Commit();
 }
Пример #2
0
        public void Save(EventSubscription subscription)
        {
            var key = subscription.GetHashCode();
            subscription.Id = key;
            var keyAsString = key.ToString();
            using (var session = _documentStore.OpenSession())
            {
                using (new TransactionScope(TransactionScopeOption.Suppress))
                {
                    var saving = true;

                    while (saving)
                    {
                        try
                        {
                            session.Store(subscription);
                            session.SaveChanges();
                            saving = false;
                        }
                        catch (ConcurrencyException)
                        {
                            var existing = session.Load<EventSubscription>(keyAsString);
                            if (existing.LastEventId > subscription.LastEventId)
                                saving = false;
                        }
                    }
                }
            }
        }
 public void Update(EventSubscription subscription)
 {
     var holder = GetHolderFromSubscription(subscription);
     if (holder == null)
         Add(subscription);
     else
     {
         CopyToEventSubscriptionHolder(subscription, holder);
         _entityContext.Update(holder);
         _entityContext.Commit();
     }
 }
Пример #4
0
        public void Save(EventSubscription subscription)
        {
            var document = _client
                .CreateDocumentQuery(_collection.SelfLink).Where(d => d.Id == subscription.Id.ToString()).ToArray()
                .SingleOrDefault(d => d.Id == subscription.Id.ToString());

            using (var stream = _serializer.ToJsonStream(subscription, SerializationExtensions.SerializationOptions))
            {
                if (document != null)
                {
                    _client.ReplaceDocumentAsync(document.SelfLink, Resource.LoadFrom<Document>(stream)).Wait();
                }
                else
                {
                    _client.CreateDocumentAsync(_collection.DocumentsLink, Resource.LoadFrom<Document>(stream)).Wait();
                }
            }
        }
 void CopyToEventSubscriptionHolder(EventSubscription subscription, EventSubscriptionHolder holder)
 {
     holder.Owner = subscription.Owner.AssemblyQualifiedName;
     holder.Method = subscription.Method.Name;
     holder.EventType = subscription.EventType.AssemblyQualifiedName;
     holder.EventName = subscription.EventName;
     holder.EventSourceVersions = _serializer.ToJson(subscription.Versions);
 }
 EventSubscriptionHolder ConvertToEventSubscriptionHolder(EventSubscription subscription)
 {
     var holder = new EventSubscriptionHolder();
     CopyToEventSubscriptionHolder(subscription, holder);
     return holder;
 }
 EventSubscriptionHolder GetHolderFromSubscription(EventSubscription subscription)
 {
     var specificHolder = ConvertToEventSubscriptionHolder(subscription);
     var holder = _entityContext.Entities.Where(e =>
         e.Owner == specificHolder.Owner &&
         e.Method == specificHolder.Method &&
         e.EventType == specificHolder.EventType).SingleOrDefault();
     return holder;
 }
Пример #8
0
 public void Process(EventSubscription subscription, IEvent @event)
 {
     var subscriber = _container.Get(subscription.Owner) as IProcessEvents;
     Process(subscription, subscriber, @event);
 }
Пример #9
0
 void UpdateExistingSubscriptionFrom(EventSubscription subscription, long eventId)
 {
     var subscriptionToUpdate = _allSubscriptions.Where(e=>e.Equals(subscription)).Single();
     subscriptionToUpdate.LastEventId = eventId;
     _subscriptions.Save(subscriptionToUpdate);
 }
Пример #10
0
 void Process(EventSubscription subscription, IProcessEvents subscriber, IEvent @event)
 {
     using (_localizer.BeginScope())
     {
         subscription.Method.Invoke(subscriber, new[] { @event });
         UpdateExistingSubscriptionFrom(subscription, @event.Id);
     }
 }
Пример #11
0
        public void Process(EventSubscription subscription, IEvent @event)
        {
            var subscriber = _container.Get(subscription.Owner) as IProcessEvents;

            Process(subscription, subscriber, @event);
        }
Пример #12
0
 public void Save(EventSubscription subscription)
 {
 }
Пример #13
0
 public void Save(EventSubscription subscription)
 {
     subscription.Id = subscription.GetHashCode();
     _collection.Save(subscription);
 }
Пример #14
0
 /// <summary>
 /// Merge versions from another <see cref="EventSubscription"/>
 /// </summary>
 /// <param name="subscription"><see cref="EventSubscription"/> to merge from</param>
 public void MergeVersionsFrom(EventSubscription subscription)
 {
     foreach( var key in subscription.Versions.Keys )
         SetEventSourceVersion(key, subscription.Versions[key]);
 }
Пример #15
0
 public void Process(EventSubscription subscription, IEnumerable<IEvent> events)
 {
     foreach (var @event in events)
         Process(subscription, @event);
 }
Пример #16
0
        public void Save(EventSubscription subscription)
        {

        }
Пример #17
0
 public void Save(EventSubscription subscription)
 {
     _collection.Save(subscription);
 }