private IEnumerator <IAsyncResult> SnapshotBlobImpl(byte[] metadata, IBlobObjectCondition condition, AsyncIteratorContext <DateTime> context) { IAsyncResult asyncResult = this._storageManager.AsyncProcessor.BeginExecute <DateTime>((TimeSpan param0) => { DateTime value; StorageStampHelpers.ValidateApplicationMetadata(metadata); using (TransactionScope transactionScope = new TransactionScope()) { using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext()) { base.LoadContainer(dbContext); BlockBlob blockBlob = base.LoadBlockBlob(dbContext); BlobLeaseInfo blobLeaseInfo = new BlobLeaseInfo(blockBlob, DateTime.UtcNow); DbBlobObject.CheckConditionsAndReturnResetRequired(blockBlob, blobLeaseInfo, condition, null, false); DateTime?nullable = null; DateTime?nullable1 = null; dbContext.SnapshotBlockBlob(blockBlob.AccountName, blockBlob.ContainerName, blockBlob.BlobName, metadata, ref nullable, ref nullable1); transactionScope.Complete(); nullable = new DateTime?(DateTime.SpecifyKind(nullable.Value, DateTimeKind.Utc)); this._blob = blockBlob; this.LeaseInfo = blobLeaseInfo; if (nullable1.HasValue) { this._blob.LastModificationTime = new DateTime?(nullable1.Value); } value = nullable.Value; } } return(value); }, base.Timeout, context.GetResumeCallback(), context.GetResumeState("BlobObject.SnapshotBlobImpl")); yield return(asyncResult); context.ResultData = this._storageManager.AsyncProcessor.EndExecute <DateTime>(asyncResult); }
private IEnumerator <IAsyncResult> GetBlockListImpl(IBlobObjectCondition condition, BlockListTypes blockListTypes, BlobServiceVersion blobServiceVersion, AsyncIteratorContext <IBlockLists> context) { IAsyncResult asyncResult = this._storageManager.AsyncProcessor.BeginExecute <BlockLists>((TimeSpan param0) => { BlockLists blockList; using (TransactionScope transactionScope = new TransactionScope()) { using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext()) { base.LoadContainer(dbContext); BlockBlob blockBlob = base.LoadBlockBlob(dbContext, true); BlobLeaseInfo blobLeaseInfo = new BlobLeaseInfo(blockBlob, DateTime.UtcNow); DbBlobObject.CheckConditionsAndReturnResetRequired(blockBlob, blobLeaseInfo, condition, null, false); BlockLists dbBlockCollections = new BlockLists() { BlobLastModificationTime = blockBlob.LastModificationTime.Value, BlobSize = blockBlob.ContentLength }; if ((blockListTypes & BlockListTypes.Committed) != BlockListTypes.None) { List <IBlock> blocks = new List <IBlock>(); if (blockBlob.HasBlock.Value) { foreach (CommittedBlock committedBlock in from blck in dbContext.CommittedBlocks where (blck.AccountName == this._blob.AccountName) && (blck.ContainerName == this._blob.ContainerName) && (blck.BlobName == this._blob.BlobName) && (blck.VersionTimestamp == this._blob.VersionTimestamp) select blck) { blocks.Add(new Block(DbListBlobObject.FromHexString(committedBlock.BlockId), committedBlock.Length.Value)); } } dbBlockCollections.CommittedBlockList = new DbListBlobObject.DbBlockCollection(blocks); } if ((blockListTypes & BlockListTypes.Uncommitted) != BlockListTypes.None) { List <IBlock> blocks1 = new List <IBlock>(); foreach (BlockData blockDatum in from blck in dbContext.BlocksData where (blck.AccountName == this._blob.AccountName) && (blck.ContainerName == this._blob.ContainerName) && (blck.BlobName == this._blob.BlobName) && (blck.VersionTimestamp == this._blob.VersionTimestamp) && !blck.IsCommitted select blck) { blocks1.Add(new Block(DbListBlobObject.FromHexString(blockDatum.BlockId), blockDatum.Length.Value)); } dbBlockCollections.UncommittedBlockList = new DbListBlobObject.DbBlockCollection(blocks1); } transactionScope.Complete(); this._blob = blockBlob; this.LeaseInfo = blobLeaseInfo; blockList = dbBlockCollections; } } return(blockList); }, base.Timeout, context.GetResumeCallback(), context.GetResumeState("DbListBlobObject.GetBlockList")); yield return(asyncResult); context.ResultData = this._storageManager.AsyncProcessor.EndExecute <BlockLists>(asyncResult); }
private IEnumerator <IAsyncResult> GetBlobImpl(IBlobRegion blobRegion, BlobPropertyNames propertyNames, IBlobObjectCondition condition, AsyncIteratorContext <CrcStream> context) { IAsyncResult asyncResult = this._storageManager.AsyncProcessor.BeginExecute <CrcStream>((TimeSpan param0) => { CrcStream streamFromByteArray; using (TransactionScope transactionScope = new TransactionScope()) { using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext()) { base.LoadContainer(dbContext); BlockBlob blockBlob = base.LoadBlockBlob(dbContext); if (blobRegion == null) { blobRegion = new BlobRegion((long)0, blockBlob.ContentLength); } else if (blobRegion.Offset > blockBlob.ContentLength || blobRegion.Offset == blockBlob.ContentLength && blockBlob.ContentLength > (long)0) { throw new InvalidBlobRegionException(new long?(blobRegion.Offset), "Offset value is greater than the contentlength"); } BlobLeaseInfo blobLeaseInfo = new BlobLeaseInfo(blockBlob, DateTime.UtcNow); DbBlobObject.CheckConditionsAndReturnResetRequired(blockBlob, blobLeaseInfo, condition, null, false); long offset = blobRegion.Offset; long num = Math.Min(offset + blobRegion.Length, blockBlob.ContentLength); IOrderedQueryable <CommittedBlock> committedBlocks = from b in dbContext.CommittedBlocks where (b.AccountName == this._blob.AccountName) && (b.ContainerName == this._blob.ContainerName) && (b.BlobName == this._blob.BlobName) && (b.VersionTimestamp == this._blob.VersionTimestamp) && (long?)b.Offset + b.Length >= (long?)offset && b.Offset < num orderby b.Offset select b; byte[] bytesFromCommittedBlocks = this.GetBytesFromCommittedBlocks(dbContext, offset, num, committedBlocks); transactionScope.Complete(); this._blob = blockBlob; this.LeaseInfo = blobLeaseInfo; streamFromByteArray = DbStorageHelper.GetStreamFromByteArray(bytesFromCommittedBlocks); } } return(streamFromByteArray); }, base.Timeout, context.GetResumeCallback(), context.GetResumeState("DbListBlobObject.GetBlob")); yield return(asyncResult); context.ResultData = this._storageManager.AsyncProcessor.EndExecute <CrcStream>(asyncResult); }
private IEnumerator <IAsyncResult> PutBlockImpl(byte[] blockIdentifier, long contentLength, Stream inputStream, byte[] contentMD5, bool isLargeBlockBlobRequest, IBlobObjectCondition condition, AsyncIteratorContext <NoResults> context) { Microsoft.WindowsAzure.DevelopmentStorage.Store.BlobContainer blobContainer = null; BlockBlob blockBlob = null; IAsyncResult asyncResult = this._storageManager.AsyncProcessor.BeginExecute((TimeSpan param0) => { long num; long num1; StorageStampHelpers.ValidatePutBlockArguments(this, blockIdentifier, contentLength, contentMD5, condition, true); string str = null; using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext()) { blobContainer = base.LoadContainer(dbContext); blockBlob = base.TryLoadBlockBlob(dbContext, out str); if (blockBlob == null) { lock (DbListBlobObject.SynchronizePutBlock) { blockBlob = base.TryLoadBlockBlob(dbContext, out str); if (blockBlob == null) { if (string.IsNullOrEmpty(str)) { str = BlockBlobDataManager.CreateUniqueDirectoryLoadBalanced(); } using (DevelopmentStorageDbDataContext developmentStorageDbDataContext = DevelopmentStorageDbDataContext.GetDbContext()) { Logger <INormalAndDebugLogger> .Instance.VerboseDebug.Log("PutBlockImpl: Creating record for ({0};{1};{2})", new object[] { this._blob.AccountName, this._blob.ContainerName, this._blob.BlobName }); StorageStampHelpers.CheckBlobName(this._blob.BlobName, this._blob.ContainerName); blockBlob = new BlockBlob() { AccountName = this._blob.AccountName, ContainerName = this._blob.ContainerName, BlobName = this._blob.BlobName, VersionTimestamp = DateTime.SpecifyKind(DateTime.MaxValue, DateTimeKind.Utc), ContentLength = (long)0, IsCommitted = new bool?(false), HasBlock = new bool?(true), DirectoryPath = str, GenerationId = Guid.NewGuid().ToString(), SnapshotCount = 0 }; developmentStorageDbDataContext.Blobs.InsertOnSubmit(blockBlob); developmentStorageDbDataContext.SubmitChanges(); } } } } bool flag = false; BlobLeaseInfo blobLeaseInfo = new BlobLeaseInfo(blockBlob, DateTime.UtcNow); DbBlobObject.CheckCopyState(blockBlob); flag = DbBlobObject.CheckConditionsAndReturnResetRequired(blockBlob, blobLeaseInfo, condition, null, true); byte[] byteArrayFromStream = DbStorageHelper.GetByteArrayFromStream(inputStream, out num, true, isLargeBlockBlobRequest); string file = BlockBlobDataManager.WriteBytesToFile(new BlockBlobMetaInfo(this._blob.AccountName, this._blob.ContainerName, this._blob.BlobName, str), byteArrayFromStream, out num1); string hexString = DbListBlobObject.ToHexString(blockIdentifier); BlockData blockDatum = this.TryLoadUncommittedBlock(dbContext, hexString); if (blockDatum == null) { blockDatum = new BlockData() { AccountName = this._blob.AccountName, ContainerName = this._blob.ContainerName, BlobName = this._blob.BlobName, VersionTimestamp = this._blob.VersionTimestamp, IsCommitted = false, BlockId = hexString }; dbContext.BlocksData.InsertOnSubmit(blockDatum); } blockDatum.Length = new long?(num); blockDatum.FilePath = file; blockDatum.StartOffset = new long?(num1); base.ResetBlobLeaseToAvailable(blockBlob, flag); dbContext.SubmitChanges(); blobLeaseInfo.SetBlob(blockBlob, blobLeaseInfo.LeaseInfoValidAt); this.LeaseInfo = blobLeaseInfo; } }, base.Timeout, context.GetResumeCallback(), context.GetResumeState("DbListBlobObject.PutBlock")); yield return(asyncResult); this._storageManager.AsyncProcessor.EndExecute(asyncResult); }