internal Stream(Partition partition, string etag, int version, StreamProperties properties) { Partition = partition; ETag = etag; Version = version; Properties = properties; }
public EventIdEntity(Partition partition, RecordedEvent @event) { Event = @event; PartitionKey = partition.PartitionKey; RowKey = partition.EventIdRowKey(@event.Id); Version = @event.Version; }
internal DuplicateEventException(Partition partition, string id) : base("Found existing event with id '{3}' in partition '{1}' which resides in '{0}' table located at {2}", partition.Table, partition, partition.Table.StorageUri, id) { Partition = partition; Id = id; }
void UpdatingForExistingStream() { var partition = new Partition(Table, Id + ".c"); var properties = new Dictionary<string, EntityProperty> { {"Created", new EntityProperty(DateTimeOffset.Now)}, {"Active", new EntityProperty(true)} }; Stream.Provision(partition, StreamProperties.From(properties)); Console.WriteLine("Stream metadata specified for stream in partition '{0}'", partition); var stream = Stream.Open(partition); Print(stream.Properties); properties["Active"] = new EntityProperty(false); Stream.SetProperties(stream, StreamProperties.From(properties)); Console.WriteLine("Updated stream metadata in partition '{0}'", partition); stream = Stream.Open(partition); Print(stream.Properties); }
internal ConcurrencyConflictException(CloudTable table, Partition partition, string details) : base("Concurrent write detected for partition '{1}' which resides in table '{0}' located at {2}. See details below.\n{3}", table, partition, table.StorageUri, details) { Table = table; Partition = partition; }
void WriteMultipleStreamsInParallel() { const int streamsToWrite = 10; Enumerable.Range(1, streamsToWrite).AsParallel() .ForAll(streamIndex => { var partition = new Partition(Partition.Table, streamIndex.ToString()); var existent = Stream.TryOpen(partition); var stream = existent.Found ? existent.Stream : new Stream(partition); Console.WriteLine("Writing to new stream in partition '{0}'", partition); var stopwatch = Stopwatch.StartNew(); for (int i = 1; i <= 30; i++) { var events = Enumerable.Range(1, 10) .Select(_ => Event(new InventoryItemCheckedIn(partition.Key, i * 1000 + streamIndex))) .ToArray(); var result = Stream.Write(stream, events); stream = result.Stream; } stopwatch.Stop(); Console.WriteLine("Finished writing 300 events to new stream in partition '{0}' in {1}ms", stream.Partition, stopwatch.ElapsedMilliseconds); }); }
/// <summary> /// Constructs a new <see cref="Stream"/> instance with the given additional properties. /// </summary> /// <param name="partition"> /// The partition in which this stream will reside. /// </param> /// <param name="properties"> /// The additional properties for this stream. /// </param> /// <exception cref="ArgumentNullException"> /// If <paramref name="partition"/> is <c>null</c> /// </exception> /// <exception cref="ArgumentNullException"> /// If <paramref name="properties"/> is <c>null</c> /// </exception> public Stream(Partition partition, StreamProperties properties) { Requires.NotNull(partition, "partition"); Requires.NotNull(properties, "properties"); Partition = partition; Properties = properties; }
void SpecifyingForExistingStream() { var partition = new Partition(Table, Id + ".a"); var properties = new Dictionary<string, EntityProperty> { {"Created", new EntityProperty(DateTimeOffset.Now)}, {"Active", new EntityProperty(true)} }; Stream.Provision(partition, StreamProperties.From(properties)); Console.WriteLine("Stream metadata specified during provisioning in partition '{0}'", partition); var stream = Stream.Open(partition); Print(stream.Properties); }
void SpecifyingDuringWritingToNewStream() { var partition = new Partition(Table, Id + ".b"); var properties = new Dictionary<string, EntityProperty> { {"Created", new EntityProperty(DateTimeOffset.Now)}, {"Active", new EntityProperty(true)} }; var stream = new Stream(partition, StreamProperties.From(properties)); Stream.Write(stream, new EventData()); Console.WriteLine("Stream metadata specified during writing to new stream in partition '{0}'", partition); stream = Stream.Open(partition); Print(stream.Properties); }
internal static IncludedOperationConflictException Create(CloudTable table, Partition partition, EntityOperation include) { var dump = JsonConvert.SerializeObject(include.Entity, Formatting.Indented); var message = string.Format( "Included '{3}' operation had conflicts in partition '{1}' which resides in '{0}' table located at {2}\n" + "Dump of conflicting [{5}] contents follows: \n\t{4}", table, partition, table.StorageUri, include.GetType().Name, dump, include.Entity.GetType()); return new IncludedOperationConflictException(table, partition, include.Entity, message); }
public void Initialize(CloudTable table, string id) { Id = id; Table = table; Partition = new Partition(table, id); }
internal RecordedEvent Record(Partition partition, int version) { return new RecordedEvent(Id, Properties, Includes, partition, version); }
static IEnumerable<EntityOperation> Prepare(IEnumerable<Include> includes, Partition partition) { return includes.Select(include => include.Operation.Apply(partition)); }
IncludedOperationConflictException(CloudTable table, Partition partition, ITableEntity entity, string message) : base(message) { Table = table; Partition = partition; Entity = entity; }
internal static Exception EventVersionExists(CloudTable table, Partition partition, int version) { return new ConcurrencyConflictException(table, partition, string.Format("Event with version '{0}' is already exists", version)); }
static Stream From(Partition partition, StreamEntity entity) { return new Stream(partition, entity.ETag, entity.Version, entity.Properties); }
/// <summary> /// Constructs a new <see cref="Stream"/> instance which doesn't have any additional properties. /// </summary> /// <param name="partition"> /// The partition in which this stream will reside. /// </param> /// <exception cref="ArgumentNullException"> /// If <paramref name="partition"/> is <c>null</c> /// </exception> public Stream(Partition partition) : this(partition, StreamProperties.None) { }
public PartitionContents(Partition partition, Action<PartitionContents> continueWith) { this.table = partition.Table; this.partition = partition; captured = partition.RetrieveAll(); continueWith(this); }
IEnumerable<EntityOperation> Prepare(Partition partition) { yield return EventEntity(partition); if (Id != EventId.None) yield return IdEntity(partition); }
EntityOperation IdEntity(Partition partition) { var entity = new EventIdEntity(partition, this); return new EntityOperation.Insert(entity); }
internal StreamNotFoundException(CloudTable table, Partition partition) : base("Stream header was not found in partition '{1}' which resides in '{0}' table located at {2}", table, partition, table.StorageUri) { Table = table; Partition = partition; }
public EntityOperation Apply(Partition partition) { Entity.PartitionKey = partition.PartitionKey; return this; }
internal static Exception StreamChanged(Partition partition) { return new ConcurrencyConflictException(partition, "Stream header has been changed in a storage"); }
IncludedOperationConflictException(Partition partition, ITableEntity entity, string message) : base(message) { Partition = partition; Entity = entity; }
internal static Exception StreamChangedOrExists(CloudTable table, Partition partition) { return new ConcurrencyConflictException(table, partition, "Stream header has been changed or already exists in a storage"); }
internal RecordedEvent(EventId id, EventProperties properties, IEnumerable<Include> includes, Partition partition, int version) { Id = id; Version = version; Properties = properties; EventOperations = Prepare(partition).ToArray(); IncludedOperations = Prepare(includes, partition).ToArray(); }
public Stream Provision(Partition partition) { Record(partition); return Stream.Provision(partition); }
public OpenStreamOperation(Partition partition) { this.partition = partition; table = partition.Table; }
public EventStore(Partition directory) { this.directory = directory; this.directory.Table.CreateIfNotExists(); }
public Insert(Stream stream) { this.stream = stream.Entity(); partition = stream.Partition; }
void Record(Partition partition) { var header = new DynamicTableEntity(directory.PartitionKey, partition.ToString()); directory.Table.Execute(TableOperation.Insert(header)); }
public Replace(Stream stream, StreamProperties properties) { this.stream = stream.Entity(); this.stream.Properties = properties; partition = stream.Partition; }