Skip to content

Instantly share code, notes, and snippets.

@trbngr
Created March 13, 2013 21:16
Show Gist options
  • Select an option

  • Save trbngr/5156331 to your computer and use it in GitHub Desktop.

Select an option

Save trbngr/5156331 to your computer and use it in GitHub Desktop.
$maxCount
EventStoreConnection connection = get your connection;
string streamName = GetStreamName(aggregate);
//try to read the slice
var slice = connection.ReadStreamEventsForward(streamName, 0, int.MaxValue, false);
if (slice.Status == SliceReadStatus.StreamNotFound)
{
//create the stream if doesn't exist.
//NOTE: isJson MUST be true for this to work.
connection.CreateStream(streamName, Guid.NewGuid(), isJson: true, metadata: SnapshotMetadata.Bytes);
}
var events = slice.Events;
var @event = events.FirstOrDefault();
[DataContract]
public class SnapshotMetadata
{
[DataMember(Name = "$maxCount")] public int MaxCount = 1;
private SnapshotMetadata()
{
}
private static readonly SnapshotMetadata Instance = new SnapshotMetadata();
public static byte[] Bytes
{
get
{
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(Instance));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment