Beispiel #1
0
 internal Stream(Partition partition, string etag, int version, StreamProperties properties)
 {
     Partition = partition;
     ETag = etag;
     Version = version;
     Properties = properties;
 }
Beispiel #2
0
 public EventIdEntity(Partition partition, RecordedEvent @event)
 {
     Event = @event;
     PartitionKey = partition.PartitionKey;
     RowKey = partition.EventIdRowKey(@event.Id);
     Version = @event.Version;
 }
Beispiel #3
0
 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);
        }
Beispiel #5
0
 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);
                });
        }
Beispiel #7
0
        /// <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);
        }
Beispiel #10
0
        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);
        }
Beispiel #11
0
 public void Initialize(CloudTable table, string id)
 {
     Id = id;
     Table = table;
     Partition = new Partition(table, id);
 }
Beispiel #12
0
 internal RecordedEvent Record(Partition partition, int version)
 {
     return new RecordedEvent(Id, Properties, Includes, partition, version);
 }
Beispiel #13
0
 static IEnumerable<EntityOperation> Prepare(IEnumerable<Include> includes, Partition partition)
 {
     return includes.Select(include => include.Operation.Apply(partition));
 }
Beispiel #14
0
 IncludedOperationConflictException(CloudTable table, Partition partition, ITableEntity entity, string message)
     : base(message)
 {
     Table = table;
     Partition = partition;
     Entity = entity;
 }
Beispiel #15
0
 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));
 }
Beispiel #16
0
 static Stream From(Partition partition, StreamEntity entity)
 {
     return new Stream(partition, entity.ETag, entity.Version, entity.Properties);
 }
Beispiel #17
0
 /// <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)
 {
 }
Beispiel #18
0
            public PartitionContents(Partition partition, Action<PartitionContents> continueWith)
            {
                this.table = partition.Table;
                this.partition = partition;

                captured = partition.RetrieveAll();
                continueWith(this);
            }
Beispiel #19
0
        IEnumerable<EntityOperation> Prepare(Partition partition)
        {
            yield return EventEntity(partition);

            if (Id != EventId.None)
                yield return IdEntity(partition);
        }
Beispiel #20
0
 EntityOperation IdEntity(Partition partition)
 {
     var entity = new EventIdEntity(partition, this);
     return new EntityOperation.Insert(entity);
 }
Beispiel #21
0
 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;
 }
Beispiel #22
0
 public EntityOperation Apply(Partition partition)
 {
     Entity.PartitionKey = partition.PartitionKey;
     return this;
 }
Beispiel #23
0
 internal static Exception StreamChanged(Partition partition)
 {
     return new ConcurrencyConflictException(partition, "Stream header has been changed in a storage");
 }
Beispiel #24
0
 IncludedOperationConflictException(Partition partition, ITableEntity entity, string message)
     : base(message)
 {
     Partition = partition;
     Entity = entity;
 }
Beispiel #25
0
 internal static Exception StreamChangedOrExists(CloudTable table, Partition partition)
 {
     return new ConcurrencyConflictException(table, partition, "Stream header has been changed or already exists in a storage");
 }
Beispiel #26
0
 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);
 }
Beispiel #28
0
 public OpenStreamOperation(Partition partition)
 {
     this.partition = partition;
     table          = partition.Table;
 }
 public EventStore(Partition directory)
 {
     this.directory = directory;
     this.directory.Table.CreateIfNotExists();
 }
Beispiel #30
0
 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));
 }
Beispiel #32
0
 public Replace(Stream stream, StreamProperties properties)
 {
     this.stream            = stream.Entity();
     this.stream.Properties = properties;
     partition = stream.Partition;
 }