Created
March 13, 2013 21:16
-
-
Save trbngr/5156331 to your computer and use it in GitHub Desktop.
$maxCount
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [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