当前位置: 首页>>代码示例>>C#>>正文


C# IEventSource.GetUncommittedEvents方法代码示例

本文整理汇总了C#中IEventSource.GetUncommittedEvents方法的典型用法代码示例。如果您正苦于以下问题:C# IEventSource.GetUncommittedEvents方法的具体用法?C# IEventSource.GetUncommittedEvents怎么用?C# IEventSource.GetUncommittedEvents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IEventSource的用法示例。


在下文中一共展示了IEventSource.GetUncommittedEvents方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Save

 public void Save(IEventSource source)
 {
     try
     {
         using (var session = _documentStore.OpenSession())
         {
             session.UseOptimisticConcurrency = true;
             foreach (var sourcedEvent in source.GetUncommittedEvents())
             {
                 session.Store(new StoredEvent
                 {
                     Data = sourcedEvent,
                     EventSequence = sourcedEvent.EventSequence,
                     EventSourceId = sourcedEvent.EventSourceId,
                     Id = sourcedEvent.EventSourceId + "/" + sourcedEvent.EventSequence
                 });
             }
             session.SaveChanges();
         }
     }
     catch (Raven.Database.Exceptions.ConcurrencyException)
     {
         throw new ConcurrencyException(source.Id, source.Version);
     }
 }
开发者ID:Andrea,项目名称:ncqrs,代码行数:25,代码来源:RavenDBEventStore.cs

示例2: Save

        public void Save(IEventSource source)
        {
            Queue<ISourcedEvent> events;
            var eventsToCommit = source.GetUncommittedEvents();

            if (!_events.TryGetValue(source.Id, out events))
            {
                events = new Queue<ISourcedEvent>();
                _events.Add(source.Id, events);
            }

            foreach (var evnt in eventsToCommit)
            {
                events.Enqueue(evnt);
            }
        }
开发者ID:Andrea,项目名称:ncqrs,代码行数:16,代码来源:InMemoryEventStore.cs

示例3: Save

        public virtual void Save(IEventSource source)
        {
            IEnumerable<ISourcedEvent> eventsToSave = source.GetUncommittedEvents();

            IDBCollection sources = database.GetCollection("Events");

            if (IsNewEventSource(source))
            {
                InsertNewEventSource(source, eventsToSave, sources);
                VerifyInsertSuccessful(source);
            }
            else
            {
                PushOptimisticUpdate(source, eventsToSave, sources);
                VerifyUpdateSuccessful(source);
            }
        }
开发者ID:HAXEN,项目名称:ncqrs,代码行数:17,代码来源:MongoDBEventStore.cs

示例4: Save

 public void Save(IEventSource source)
 {
     FileInfo file = source.EventSourceId.GetEventStoreFileInfo(_path);
     if (!file.Exists && !file.Directory.Exists)
         file.Directory.Create();
     try
     {
         source.EventSourceId.GetWriteLock();
         if (file.Exists)
         {
             if (GetVersion(source.EventSourceId) > source.InitialVersion)
             {
                 throw new ConcurrencyException(source.EventSourceId, source.Version);
             }
         }
         using (var writer = file.OpenWrite())
         {
             writer.Seek(0, SeekOrigin.End);
             var indicies = new long[source.GetUncommittedEvents().Count()];
             var i = 0;
             var index = writer.Position;
             foreach (SourcedEvent sourcedEvent in source.GetUncommittedEvents())
             {
                 StoredEvent<JObject> storedEvent = _formatter.Serialize(sourcedEvent);
                 var bytes = storedEvent.GetBytes();
                 writer.Write(BitConverter.GetBytes(bytes.Length), 0, 4);
                 writer.Write(bytes, 0, bytes.Length);
                 indicies[i++] = index;
                 index += bytes.Length;
             }
             UpdateEventSourceIndexFile(source.EventSourceId, indicies);
             writer.Flush();
         }
     }
     finally
     {
         source.EventSourceId.ReleaseWriteLock();
     }
 }
开发者ID:HAXEN,项目名称:ncqrs,代码行数:39,代码来源:NoDBEventStore.cs

示例5: Save

        /// <summary>
        /// Saves all events from an event provider.
        /// </summary>
        /// <param name="provider">The eventsource.</param>
        public void Save(IEventSource eventSource)
        {
            // Get all events.
            IEnumerable<ISourcedEvent> events = eventSource.GetUncommittedEvents();

            // Create new connection.
            using (var connection = new SqlConnection(_connectionString))
            {
                // Open connection and begin a transaction so we can
                // commit or rollback all the changes that has been made.
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
                {
                    try
                    {
                        // Get the current version of the event provider.
                        int? currentVersion = GetVersion(eventSource.Id, transaction);

                        // Create new event provider when it is not found.
                        if (currentVersion == null)
                        {
                            AddEventSource(eventSource, transaction);
                        }
                        else if (currentVersion.Value != eventSource.InitialVersion)
                        {
                            throw new ConcurrencyException(eventSource.Id, eventSource.Version);
                        }

                        // Save all events to the store.
                        SaveEvents(events, eventSource.Id, transaction);

                        // Update the version of the provider.
                        UpdateEventSourceVersion(eventSource, transaction);

                        // Everything is handled, commint transaction.
                        transaction.Commit();
                    }
                    catch
                    {
                        // Something went wrong, rollback transaction.
                        transaction.Rollback();
                        throw;
                    }
                }
            }
        }
开发者ID:Andrea,项目名称:ncqrs,代码行数:50,代码来源:SimpleSqlEventStore.cs

示例6: Save

        /// <summary>
        /// Save all events from a specific event provider.
        /// </summary>
        /// <exception cref="T:Ncqrs.Eventing.Storage.ConcurrencyException">Occurs when there is already a newer version of the event provider stored in the event store.</exception><param name="source">The source that should be saved.</param><requires description="source cannot be null." exception="T:System.ArgumentNullException">source != null</requires><exception cref="T:System.ArgumentNullException">source == null</exception><ensures description="Return should never be null.">Contract.Result&lt;IEnumerable&lt;IEvent&gt;&gt;() != null</ensures>
        public void Save(IEventSource source)
        {
            var context = _tableClient.GetDataServiceContext();
            var sourceInStore = GetSourceFromStore(context, source.EventSourceId);
            var uncommitedEvents = source.GetUncommittedEvents();

            if (sourceInStore == null)
            {
                sourceInStore = InsertNewEventSource(context, source);
            }
            else
            {
                if (source.Version != sourceInStore.Version)
                    throw new ConcurrencyException(source.EventSourceId, source.Version);
            }

            // Update version.
            sourceInStore.Version = source.Version + uncommitedEvents.Count(); // TODO: We can do this better.
            context.UpdateObject(sourceInStore);
            context.SaveChanges(SaveChangesOptions.Batch); // TODO: Validate response.

            PushEventToStore(context, source.EventSourceId, uncommitedEvents);

            // TODO: Validate response.
            var response = context.SaveChanges(SaveChangesOptions.Batch);
        }
开发者ID:SzymonPobiega,项目名称:ncqrs,代码行数:30,代码来源:AzureEventStore.cs

示例7: Save

        public void Save(IEventSource source)
        {
            var events = source.GetUncommittedEvents();
            using (var conn = new SQLiteConnection(_connectionString))
            {
                conn.Open();
                using (var transaction = conn.BeginTransaction())
                    try
                    {
                        var currentVersion = GetVersion(source.EventSourceId, transaction);

                        if (currentVersion == null)
                            AddEventSource(source, transaction);
                        else if (currentVersion.Value != source.InitialVersion)
                            throw new ConcurrencyException(source.EventSourceId, source.Version);

                        SaveEvents(events, source.EventSourceId, transaction);
                        UpdateEventSourceVersion(source, transaction);
                        transaction.Commit();
                    }
                    catch
                    {
                        transaction.Rollback();
                        throw;
                    }
            }
        }
开发者ID:SzymonPobiega,项目名称:ncqrs,代码行数:27,代码来源:SQLiteEventStore.cs

示例8: Save

        public void Save(IEventSource source)
        {
            var events = source.GetUncommittedEvents();

            _context.WithConnection(connection =>
            _context.WithTransaction(connection, transaction =>
            {
                var currentVersion = GetVersion(source.EventSourceId, transaction);

                if (currentVersion == null)
                    AddEventSource(source, transaction);
                else if (currentVersion.Value != source.InitialVersion)
                    throw new ConcurrencyException(source.EventSourceId, source.Version);

                SaveEvents(events, source.EventSourceId, transaction);
                UpdateEventSourceVersion(source, transaction);
            }));
        }
开发者ID:kajaljatakia,项目名称:ncqrs,代码行数:18,代码来源:SQLiteEventStore.cs


注:本文中的IEventSource.GetUncommittedEvents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。