本文整理汇总了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);
}
}
示例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);
}
}
示例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);
}
}
示例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();
}
}
示例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;
}
}
}
}
示例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<IEnumerable<IEvent>>() != 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);
}
示例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;
}
}
}
示例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);
}));
}