예제 #1
0
                internal void Handle(StorageException exception)
                {
                    if (exception.RequestInformation.HttpStatusCode == (int)HttpStatusCode.Conflict)
                    {
                        throw ConcurrencyConflictException.StreamChangedOrExists(partition);
                    }

                    ExceptionDispatchInfo.Capture(exception).Throw();
                }
예제 #2
0
                internal void Handle(CloudTable table, StorageException exception)
                {
                    if (exception.RequestInformation.HttpStatusCode == (int)HttpStatusCode.Conflict)
                    {
                        throw ConcurrencyConflictException.StreamChangedOrExists(partition);
                    }

                    throw exception.PreserveStackTrace();
                }
예제 #3
0
        /// <summary>
        /// Initiates an asynchronous operation that writes the given array of events to a partition using specified expected version.
        /// </summary>
        /// <remarks>For new stream specify expected version as 0</remarks>
        /// <param name="partition">The partition.</param>
        /// <param name="options">The stream write options.</param>
        /// <param name="expectedVersion">The expected version of the stream.</param>
        /// <param name="events">The events to write.</param>
        /// <returns>
        ///     The result of the stream write operation containing updated stream header
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="partition"/> is <c>null</c>
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="events"/> is <c>null</c>
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        ///    If <paramref name="expectedVersion"/> is less than 0
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        ///    If <paramref name="events"/> array is empty
        /// </exception>
        /// <exception cref="DuplicateEventException">
        ///     If event with the given id already exists in a storage
        /// </exception>
        /// <exception cref="IncludedOperationConflictException">
        ///     If included entity operation has conflicts
        /// </exception>
        /// <exception cref="ConcurrencyConflictException">
        ///     If write operation has conflicts
        /// </exception>
        public static async Task <StreamWriteResult> WriteAsync(Partition partition, StreamWriteOptions options, int expectedVersion, params EventData[] events)
        {
            Requires.NotNull(partition, nameof(partition));
            Requires.GreaterThanOrEqualToZero(expectedVersion, nameof(expectedVersion));

            var stream = expectedVersion == 0
                ? new Stream(partition)
                : await OpenAsync(partition);

            if (stream.Version != expectedVersion)
            {
                throw ConcurrencyConflictException.StreamChangedOrExists(partition);
            }

            return(await WriteAsync(stream, options, events));
        }
예제 #4
0
        /// <summary>
        /// Writes the given array of events to a partition using specified expected version.
        /// </summary>
        /// <remarks>For new stream specify expected version as 0</remarks>
        /// <param name="partition">The partition.</param>
        /// <param name="expectedVersion">The expected version of the stream.</param>
        /// <param name="events">The events to write.</param>
        /// <returns>
        ///     The result of the stream write operation containing updated stream header
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="partition"/> is <c>null</c>
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="events"/> is <c>null</c>
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        ///    If <paramref name="expectedVersion"/> is less than 0
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        ///    If <paramref name="events"/> array is empty
        /// </exception>
        /// <exception cref="DuplicateEventException">
        ///     If event with the given id already exists in a storage
        /// </exception>
        /// <exception cref="IncludedOperationConflictException">
        ///     If included entity operation has conflicts
        /// </exception>
        /// <exception cref="ConcurrencyConflictException">
        ///     If write operation has conflicts
        /// </exception>
        public static StreamWriteResult Write(Partition partition, int expectedVersion, params EventData[] events)
        {
            Requires.NotNull(partition, nameof(partition));
            Requires.GreaterThanOrEqualToZero(expectedVersion, nameof(expectedVersion));

            var stream = expectedVersion == 0
                ? new Stream(partition)
                : Open(partition);

            if (stream.Version != expectedVersion)
            {
                throw ConcurrencyConflictException.StreamChangedOrExists(partition);
            }

            return(Write(stream, events));
        }
예제 #5
0
                internal void Handle(StorageException exception)
                {
                    if (exception.RequestInformation.HttpStatusCode == (int)HttpStatusCode.PreconditionFailed)
                    {
                        throw ConcurrencyConflictException.StreamChangedOrExists(partition);
                    }

                    if (exception.RequestInformation.HttpStatusCode != (int)HttpStatusCode.Conflict)
                    {
                        ExceptionDispatchInfo.Capture(exception).Throw();
                    }

                    var error = exception.RequestInformation.ExtendedErrorInformation;

                    if (error.ErrorCode != "EntityAlreadyExists")
                    {
                        throw UnexpectedStorageResponseException.ErrorCodeShouldBeEntityAlreadyExists(error);
                    }

                    var position = ParseConflictingEntityPosition(error);

                    Debug.Assert(position >= 0 && position < operations.Count);
                    var conflicting = operations[position].Entity;

                    if (conflicting == stream)
                    {
                        throw ConcurrencyConflictException.StreamChangedOrExists(partition);
                    }

                    var id = conflicting as EventIdEntity;

                    if (id != null)
                    {
                        throw new DuplicateEventException(partition, id.Event.Id);
                    }

                    var @event = conflicting as EventEntity;

                    if (@event != null)
                    {
                        throw ConcurrencyConflictException.EventVersionExists(partition, @event.Version);
                    }

                    var include = operations.Single(x => x.Entity == conflicting);

                    throw IncludedOperationConflictException.Create(partition, include);
                }