Пример #1
0
 /// <summary>
 /// Creates a Commit object from an AzureBlobEntry.
 /// </summary>
 /// <param name="blobEntry">The source AzureBlobEntry.</param>
 /// <returns>The populated Commit.</returns>
 private ICommit CreateCommitFromAzureBlobCommit(AzureBlobCommit blobEntry)
 {
     return(new Commit(blobEntry.BucketId,
                       blobEntry.StreamId,
                       blobEntry.StreamRevision,
                       blobEntry.CommitId,
                       blobEntry.CommitSequence,
                       blobEntry.CommitStampUtc,
                       blobEntry.Checkpoint.ToString(),
                       blobEntry.Headers,
                       blobEntry.Events));
 }
Пример #2
0
        /// <summary>
        /// Adds a commit to a stream.
        /// </summary>
        /// <param name="attempt">The commit attempt to be added.</param>
        /// <returns>An Commit if successful.</returns>
        public ICommit Commit(CommitAttempt attempt)
        {
            var pageBlob = WrappedPageBlob.CreateNewIfNotExists(_primaryContainer, attempt.BucketId + "/" + attempt.StreamId, _options.BlobNumPages);
            HeaderDefinitionMetadata headerDefinitionMetadata = null;
            var header = GetHeaderWithRetry(pageBlob, out headerDefinitionMetadata);

            // we must commit at a page offset, we will just track how many pages in we must start writing at
            var startPage = 0;

            foreach (var commit in header.PageBlobCommitDefinitions)
            {
                if (commit.CommitId == attempt.CommitId)
                {
                    throw new DuplicateCommitException("Duplicate Commit Attempt");
                }

                startPage += commit.TotalPagesUsed;
            }

            if (attempt.CommitSequence <= header.LastCommitSequence)
            {
                throw new ConcurrencyException("Concurrency exception in Commit");
            }

            var blobCommit = new AzureBlobCommit();

            blobCommit.BucketId       = attempt.BucketId;
            blobCommit.CommitId       = attempt.CommitId;
            blobCommit.CommitSequence = attempt.CommitSequence;
            blobCommit.CommitStampUtc = attempt.CommitStamp;
            blobCommit.Events         = attempt.Events.ToList();
            blobCommit.Headers        = attempt.Headers;
            blobCommit.StreamId       = attempt.StreamId;
            blobCommit.StreamRevision = attempt.StreamRevision;
            blobCommit.Checkpoint     = GetNextCheckpoint();
            var serializedBlobCommit = _serializer.Serialize(blobCommit);

            header.AppendPageBlobCommitDefinition(new PageBlobCommitDefinition(serializedBlobCommit.Length, attempt.CommitId, attempt.StreamRevision,
                                                                               attempt.CommitStamp, header.PageBlobCommitDefinitions.Count, startPage, blobCommit.Checkpoint));
            ++header.UndispatchedCommitCount;
            header.LastCommitSequence = attempt.CommitSequence;

            CommitNewMessage(pageBlob, serializedBlobCommit, header, headerDefinitionMetadata, startPage * _blobPageSize);
            return(CreateCommitFromAzureBlobCommit(blobCommit));
        }