Example #1
0
        /// <summary>
        /// Creates a commit from the provided definition
        /// </summary>
        /// <param name="streamId"></param>
        /// <param name="commitDefinition"></param>
        /// <returns></returns>
        private ICommit CreateCommitFromDefinition(WrappedPageBlob blob, PageBlobCommitDefinition commitDefinition)
        {
            var startIndex     = commitDefinition.StartPage * BlobPageSize;
            var endIndex       = startIndex + commitDefinition.DataSizeBytes;
            var downloadedData = blob.DownloadBytes(startIndex, endIndex, true);

            using (var ms = new MemoryStream(downloadedData, false))
            {
                AzureBlobCommit azureBlobCommit;
                try
                {
                    azureBlobCommit = _serializer.Deserialize <AzureBlobCommit>(ms);
                }
                catch (Exception ex)
                {
                    var message = $"Blob with uri [{((CloudPageBlob) blob).Uri}] is corrupt.";
                    Logger.Fatal(message);
                    throw new InvalidDataException(message, ex);
                }

                return(CreateCommitFromAzureBlobCommit(azureBlobCommit));
            }
        }
 /// <summary>
 /// Adds a PageBlobCommitDefinition to the end of the list.
 /// </summary>
 /// <param name="definition">The definition to be added</param>
 public void AppendPageBlobCommitDefinition(PageBlobCommitDefinition definition)
 {
     _pageBlobCommitDefinitions.Add(definition);
 }