public static string MakeBlobDataCopy(BlockBlobMetaInfo blobInfo) { string str; DevStoreBlockBlobFileParameters devStoreBlockBlobFileParameter = BlockBlobDataManager.AddInfoIfNotExists(blobInfo); try { try { devStoreBlockBlobFileParameter.AccessReadWriteLock.EnterWriteLock(); string str1 = BlockBlobDataManager.CreateUniqueDirectoryLoadBalanced(); string[] files = Directory.GetFiles(devStoreBlockBlobFileParameter.DirectoryName); string str2 = null; IStringDataEventStream infoDebug = Logger <INormalAndDebugLogger> .Instance.InfoDebug; object[] directoryName = new object[] { devStoreBlockBlobFileParameter.DirectoryName, str1 }; infoDebug.Log("BlockBlob: MakeBlobDataCopy SrcDir {0} -> DestDir {1}", directoryName); if (files != null && (int)files.Length > 0) { string[] strArrays = files; for (int i = 0; i < (int)strArrays.Length; i++) { string str3 = strArrays[i]; string str4 = Path.Combine(str1, Path.GetFileName(str3)); if (string.Compare(str3, devStoreBlockBlobFileParameter.ReadWriteFile, StringComparison.OrdinalIgnoreCase) == 0) { str2 = str4; } else { Logger <INormalAndDebugLogger> .Instance.InfoDebug.Log("BlockBlob: MakeBlobDataCopy SrcFile {0} -> DestFile {1}", new object[] { str3, str4 }); File.Copy(str3, str4); } } IStringDataEventStream stringDataEventStream = Logger <INormalAndDebugLogger> .Instance.InfoDebug; object[] readWriteFile = new object[] { devStoreBlockBlobFileParameter.ReadWriteFile, str2 }; stringDataEventStream.Log("BlockBlob: MakeBlobDataCopy RW FILE SrcFile {0} -> DestFile {1}", readWriteFile); File.Copy(devStoreBlockBlobFileParameter.ReadWriteFile, str2); } str = str1; } catch (Exception exception1) { Exception exception = exception1; Logger <INormalAndDebugLogger> .Instance.Error.Log("BlockBlob: MakeBlobDataCopy failed. Exception:{0}", new object[] { exception.StackTrace }); throw; } } finally { devStoreBlockBlobFileParameter.AccessReadWriteLock.ExitWriteLock(); } return(str); }
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); }
private IEnumerator <IAsyncResult> PutBlobImpl(string contentType, long contentLength, byte[] serviceMetadata, byte[] applicationMetadata, byte[][] blockList, BlockSource[] blockSourceList, byte[] contentMD5, OverwriteOption overwriteOption, IBlobObjectCondition condition, AsyncIteratorContext <NoResults> context) { IStringDataEventStream verboseDebug = Logger <INormalAndDebugLogger> .Instance.VerboseDebug; object[] objArray = new object[] { contentType, this.ContentLength, serviceMetadata, applicationMetadata, blockList, overwriteOption, condition, base.Timeout }; verboseDebug.Log("PutBlobImpl.PutBlobImpl({0};{1};{2};{3};{4};{5};{6};{7})", objArray); IAsyncResult asyncResult = this._storageManager.AsyncProcessor.BeginExecute((TimeSpan param0) => { using (TransactionScope transactionScope = new TransactionScope()) { using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext()) { base.LoadContainer(dbContext); string str = null; BlockBlob blockBlob = base.TryLoadBlockBlob(dbContext, out str); DateTime utcNow = DateTime.UtcNow; bool flag = false; if (blockBlob != null) { DbBlobObject.CheckCopyState(blockBlob); flag = DbBlobObject.CheckConditionsAndReturnResetRequired(blockBlob, new BlobLeaseInfo(blockBlob, utcNow), condition, null, true); if (blockBlob.IsCommitted.Value) { if (overwriteOption == OverwriteOption.CreateNewOnly) { throw new BlobAlreadyExistsException(); } } else if (overwriteOption == OverwriteOption.UpdateExistingOnly && condition != null && !condition.IsIncludingUncommittedBlobs) { throw new ConditionNotMetException(); } } else { if (overwriteOption == OverwriteOption.UpdateExistingOnly) { if (condition == null || !condition.LeaseId.HasValue) { throw new ConditionNotMetException(); } throw new LeaseNotPresentException(); } StorageStampHelpers.CheckBlobName(this._blob.BlobName, this._blob.ContainerName); if (string.IsNullOrEmpty(str)) { str = BlockBlobDataManager.CreateUniqueDirectoryLoadBalanced(); } blockBlob = new BlockBlob() { AccountName = this._blob.AccountName, ContainerName = this._blob.ContainerName, BlobName = this._blob.BlobName, VersionTimestamp = DateTime.SpecifyKind(DateTime.MaxValue, DateTimeKind.Utc), IsCommitted = new bool?(false), DirectoryPath = str }; dbContext.Blobs.InsertOnSubmit(blockBlob); } StorageStampHelpers.ValidatePutBlockListArguments(this, contentLength, applicationMetadata, blockList, blockSourceList, contentMD5, condition, this._blobServiceVersion); blockBlob.ContentType = contentType ?? "application/octet-stream"; blockBlob.ContentMD5 = contentMD5; blockBlob.ServiceMetadata = serviceMetadata; blockBlob.Metadata = applicationMetadata; blockBlob.HasBlock = new bool?(true); blockBlob.GenerationId = Guid.NewGuid().ToString(); blockBlob.SnapshotCount = 0; base.ResetBlobLeaseToAvailable(blockBlob, flag); dbContext.SubmitChanges(); DateTime?nullable = null; StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < (int)blockList.Length; i++) { DbListBlobObject.SerializeCommitBlockListEntry(stringBuilder, blockList[i], (blockSourceList != null ? blockSourceList[i] : BlockSource.Uncommitted)); } dbContext.CommitBlockList(this._blob.AccountName, this._blob.ContainerName, this._blob.BlobName, stringBuilder.ToString(), ref nullable); transactionScope.Complete(); blockBlob.LastModificationTime = nullable; this._blob = blockBlob; this.LeaseInfo = new BlobLeaseInfo(blockBlob, utcNow); } } }, base.Timeout, context.GetResumeCallback(), context.GetResumeState("DbListBlobObject.PutBlob")); yield return(asyncResult); this._storageManager.AsyncProcessor.EndExecute(asyncResult); }
private IEnumerator <IAsyncResult> PutBlobImpl(string contentType, long contentLength, byte[] serviceMetadata, byte[] applicationMetadata, Stream inputStream, byte[] contentMD5, bool invokeGeneratePutBlobServiceMetadata, GeneratePutBlobServiceMetadata generatePutBlobServiceMetadata, bool isLargeBlockBlobRequest, ISequenceNumberUpdate sequenceNumberUpdate, OverwriteOption overwriteOption, IBlobObjectCondition condition, AsyncIteratorContext <NoResults> context) { IAsyncResult asyncResult = this._storageManager.AsyncProcessor.BeginExecute((TimeSpan param0) => { long num; long num1; using (TransactionScope transactionScope = new TransactionScope()) { using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext()) { base.LoadContainer(dbContext); string str = null; BlockBlob blockBlob = base.TryLoadBlockBlob(dbContext, out str); DateTime utcNow = DateTime.UtcNow; bool flag = false; if (blockBlob != null) { if (blockBlob.IsCommitted.Value && overwriteOption == OverwriteOption.CreateNewOnly) { throw new BlobAlreadyExistsException(); } DbBlobObject.CheckCopyState(blockBlob); flag = DbBlobObject.CheckConditionsAndReturnResetRequired(blockBlob, new BlobLeaseInfo(blockBlob, utcNow), condition, null, true); dbContext.ClearUncommittedBlocks(this._blob.AccountName, this._blob.ContainerName, this._blob.BlobName); dbContext.Refresh(RefreshMode.KeepChanges, blockBlob); } else { if (overwriteOption == OverwriteOption.UpdateExistingOnly) { if (condition == null || !condition.LeaseId.HasValue) { throw new ConditionNotMetException(); } throw new LeaseNotPresentException(); } StorageStampHelpers.CheckBlobName(this._blob.BlobName, this._blob.ContainerName); if (string.IsNullOrEmpty(str)) { str = BlockBlobDataManager.CreateUniqueDirectoryLoadBalanced(); } blockBlob = new BlockBlob() { AccountName = this._blob.AccountName, ContainerName = this._blob.ContainerName, BlobName = this._blob.BlobName, VersionTimestamp = DateTime.SpecifyKind(DateTime.MaxValue, DateTimeKind.Utc), DirectoryPath = str }; dbContext.Blobs.InsertOnSubmit(blockBlob); } StorageStampHelpers.ValidatePutBlobArguments(this, contentLength, null, applicationMetadata, contentMD5, sequenceNumberUpdate, overwriteOption, condition, true, false); byte[] byteArrayFromStream = DbStorageHelper.GetByteArrayFromStream(inputStream, out num, false, isLargeBlockBlobRequest); string file = BlockBlobDataManager.WriteBytesToFile(new BlockBlobMetaInfo(this._blob.AccountName, this._blob.ContainerName, this._blob.BlobName, str), byteArrayFromStream, out num1); Guid guid = Guid.NewGuid(); BlockData blockDatum = new BlockData() { AccountName = this._blob.AccountName, ContainerName = this._blob.ContainerName, BlobName = this._blob.BlobName, VersionTimestamp = this._blob.VersionTimestamp, IsCommitted = false, BlockId = DbListBlobObject.ToHexString(guid.ToByteArray()), FilePath = file, StartOffset = new long?(num1) }; dbContext.BlocksData.InsertOnSubmit(blockDatum); if (invokeGeneratePutBlobServiceMetadata && generatePutBlobServiceMetadata != null) { serviceMetadata = generatePutBlobServiceMetadata(); } blockBlob.ContentType = contentType ?? "application/octet-stream"; blockBlob.ContentMD5 = contentMD5; blockBlob.ServiceMetadata = serviceMetadata; blockBlob.Metadata = applicationMetadata; blockBlob.IsCommitted = new bool?(false); blockBlob.HasBlock = new bool?(false); blockBlob.UncommittedBlockIdLength = null; blockBlob.GenerationId = Guid.NewGuid().ToString(); blockBlob.SnapshotCount = 0; blockDatum.Length = new long?(num); blockBlob.ContentLength = num; base.ResetBlobLeaseToAvailable(blockBlob, flag); dbContext.SubmitChanges(); StringBuilder stringBuilder = new StringBuilder(); DbListBlobObject.SerializeCommitBlockListEntry(stringBuilder, guid.ToByteArray(), BlockSource.Uncommitted); DateTime?nullable = null; dbContext.CommitBlockList(this._blob.AccountName, this._blob.ContainerName, this._blob.BlobName, stringBuilder.ToString(), ref nullable); transactionScope.Complete(); blockBlob.LastModificationTime = nullable; this._blob = blockBlob; this.LeaseInfo = new BlobLeaseInfo(blockBlob, utcNow); } } }, base.Timeout, context.GetResumeCallback(), context.GetResumeState("DbListBlobObject.PutBlobImpl")); yield return(asyncResult); this._storageManager.AsyncProcessor.EndExecute(asyncResult); }