コード例 #1
0
ファイル: Stream.Header.cs プロジェクト: kowalot/Streamstone
 internal Stream(Partition partition, string etag, int version, StreamProperties properties)
 {
     Partition = partition;
     ETag = etag;
     Version = version;
     Properties = properties;
 }
コード例 #2
0
 public EventIdEntity(Partition partition, RecordedEvent @event)
 {
     Event = @event;
     PartitionKey = partition.PartitionKey;
     RowKey = partition.EventIdRowKey(@event.Id);
     Version = @event.Version;
 }
コード例 #3
0
ファイル: Exceptions.cs プロジェクト: kowalot/Streamstone
 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;
 }
コード例 #4
0
        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);
        }
コード例 #5
0
ファイル: Exceptions.cs プロジェクト: gabikliot/Streamstone
 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;
 }
コード例 #6
0
        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);
                });
        }
コード例 #7
0
ファイル: Stream.Header.cs プロジェクト: kowalot/Streamstone
        /// <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;
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
ファイル: Exceptions.cs プロジェクト: gabikliot/Streamstone
        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);
        }
コード例 #11
0
ファイル: Scenario.cs プロジェクト: aprooks/Streamstone
 public void Initialize(CloudTable table, string id)
 {
     Id = id;
     Table = table;
     Partition = new Partition(table, id);
 }
コード例 #12
0
ファイル: Event.cs プロジェクト: gabikliot/Streamstone
 internal RecordedEvent Record(Partition partition, int version)
 {
     return new RecordedEvent(Id, Properties, Includes, partition, version);
 }
コード例 #13
0
ファイル: Event.cs プロジェクト: gabikliot/Streamstone
 static IEnumerable<EntityOperation> Prepare(IEnumerable<Include> includes, Partition partition)
 {
     return includes.Select(include => include.Operation.Apply(partition));
 }
コード例 #14
0
ファイル: Exceptions.cs プロジェクト: gabikliot/Streamstone
 IncludedOperationConflictException(CloudTable table, Partition partition, ITableEntity entity, string message)
     : base(message)
 {
     Table = table;
     Partition = partition;
     Entity = entity;
 }
コード例 #15
0
ファイル: Exceptions.cs プロジェクト: gabikliot/Streamstone
 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));
 }
コード例 #16
0
ファイル: Stream.Header.cs プロジェクト: kowalot/Streamstone
 static Stream From(Partition partition, StreamEntity entity)
 {
     return new Stream(partition, entity.ETag, entity.Version, entity.Properties);
 }
コード例 #17
0
ファイル: Stream.Header.cs プロジェクト: kowalot/Streamstone
 /// <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)
 {
 }
コード例 #18
0
ファイル: Storage.cs プロジェクト: kowalot/Streamstone
            public PartitionContents(Partition partition, Action<PartitionContents> continueWith)
            {
                this.table = partition.Table;
                this.partition = partition;

                captured = partition.RetrieveAll();
                continueWith(this);
            }
コード例 #19
0
ファイル: Event.cs プロジェクト: gabikliot/Streamstone
        IEnumerable<EntityOperation> Prepare(Partition partition)
        {
            yield return EventEntity(partition);

            if (Id != EventId.None)
                yield return IdEntity(partition);
        }
コード例 #20
0
ファイル: Event.cs プロジェクト: gabikliot/Streamstone
 EntityOperation IdEntity(Partition partition)
 {
     var entity = new EventIdEntity(partition, this);
     return new EntityOperation.Insert(entity);
 }
コード例 #21
0
ファイル: Exceptions.cs プロジェクト: gabikliot/Streamstone
 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;
 }
コード例 #22
0
 public EntityOperation Apply(Partition partition)
 {
     Entity.PartitionKey = partition.PartitionKey;
     return this;
 }
コード例 #23
0
ファイル: Exceptions.cs プロジェクト: kowalot/Streamstone
 internal static Exception StreamChanged(Partition partition)
 {
     return new ConcurrencyConflictException(partition, "Stream header has been changed in a storage");
 }
コード例 #24
0
ファイル: Exceptions.cs プロジェクト: kowalot/Streamstone
 IncludedOperationConflictException(Partition partition, ITableEntity entity, string message)
     : base(message)
 {
     Partition = partition;
     Entity = entity;
 }
コード例 #25
0
ファイル: Exceptions.cs プロジェクト: gabikliot/Streamstone
 internal static Exception StreamChangedOrExists(CloudTable table, Partition partition)
 {
     return new ConcurrencyConflictException(table, partition, "Stream header has been changed or already exists in a storage");
 }
コード例 #26
0
ファイル: Event.cs プロジェクト: gabikliot/Streamstone
 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();
 }
コード例 #27
0
 public Stream Provision(Partition partition)
 {
     Record(partition);
     return Stream.Provision(partition);
 }
コード例 #28
0
 public OpenStreamOperation(Partition partition)
 {
     this.partition = partition;
     table          = partition.Table;
 }
コード例 #29
0
 public EventStore(Partition directory)
 {
     this.directory = directory;
     this.directory.Table.CreateIfNotExists();
 }
コード例 #30
0
 public Insert(Stream stream)
 {
     this.stream = stream.Entity();
     partition   = stream.Partition;
 }
コード例 #31
0
 void Record(Partition partition)
 {
     var header = new DynamicTableEntity(directory.PartitionKey, partition.ToString());
     directory.Table.Execute(TableOperation.Insert(header));
 }
コード例 #32
0
 public Replace(Stream stream, StreamProperties properties)
 {
     this.stream            = stream.Entity();
     this.stream.Properties = properties;
     partition = stream.Partition;
 }