Beispiel #1
0
 public static void ValidatePutBlockArguments(IBlobObject blob, byte[] blockIdentifier, long contentLength, byte[] contentMD5, IBlobObjectCondition condition, bool isLargeBlockBlobRequest)
 {
     if (blob.Snapshot != StorageStampHelpers.RootBlobSnapshotVersion)
     {
         throw new XStoreArgumentException("This operation is only supported on the root blob.");
     }
     if ((int)blockIdentifier.Length <= 0 || (int)blockIdentifier.Length > 64)
     {
         throw new XStoreArgumentOutOfRangeException("blockIdentifier");
     }
     if (contentLength <= (long)0)
     {
         throw new ArgumentOutOfRangeException("contentLength", "contentLength must be > 0");
     }
     if (!isLargeBlockBlobRequest && contentLength > (long)4194304)
     {
         throw new BlobContentTooLargeException(new long?((long)4194304), null, null);
     }
     StorageStampHelpers.ValidateMD5(contentMD5);
     if (condition != null)
     {
         if (condition.IfModifiedSinceTime.HasValue)
         {
             throw new XStoreArgumentException("PutBlock does not support IfModifiedSince as a condition. Only LeaseId is supported as part of the condition for PutBlock.");
         }
         if (condition.IfNotModifiedSinceTime.HasValue)
         {
             throw new XStoreArgumentException("PutBlock does not support IfNotModifiedSince as a condition. Only LeaseId is supported as part of the condition for PutBlock.");
         }
     }
 }
Beispiel #2
0
        private IEnumerator <IAsyncResult> ListBlobsImpl(string blobNamePrefix, BlobPropertyNames propertyNames, string separator, string blobNameStart, DateTime?snapshotStart, IBlobObjectCondition condition, int maxBlobNames, BlobServiceVersion version, AsyncIteratorContext <IBlobObjectCollection> context)
        {
            IAsyncResult asyncResult;

            try
            {
                asyncResult = this.InternalContainer.BeginListBlobs(blobNamePrefix, propertyNames, separator, blobNameStart, snapshotStart, Helpers.Convert(condition), maxBlobNames, version, context.GetResumeCallback(), context.GetResumeState("BlobContainer.ListBlobsImpl"));
            }
            catch (Exception exception)
            {
                StorageStamp.TranslateException(exception);
                throw;
            }
            yield return(asyncResult);

            try
            {
                IBlobObjectCollection blobObjectCollections = this.InternalContainer.EndListBlobs(asyncResult);
                context.ResultData = new BlobObjectCollection(blobObjectCollections);
            }
            catch (Exception exception1)
            {
                StorageStamp.TranslateException(exception1);
                throw;
            }
        }
Beispiel #3
0
        private IEnumerator <IAsyncResult> GetPageRangeListImpl(IBlobRegion blobRegion, BlobPropertyNames additionalPropertyNames, IBlobObjectCondition condition, int maxPageRanges, DateTime?prevSnapshotTimestamp, bool isRangeCompressed, bool skipClearPages, AsyncIteratorContext <IPageRangeCollection> context)
        {
            IAsyncResult asyncResult;

            try
            {
                asyncResult = ((IIndexBlobObject)this.blob).BeginGetPageRangeList(blobRegion, additionalPropertyNames, Helpers.Convert(condition), maxPageRanges, prevSnapshotTimestamp, isRangeCompressed, skipClearPages, context.GetResumeCallback(), context.GetResumeState("IndexBlobObject.GetPageRangeListImpl"));
            }
            catch (Exception exception)
            {
                StorageStamp.TranslateException(exception);
                throw;
            }
            yield return(asyncResult);

            try
            {
                context.ResultData = ((IIndexBlobObject)this.blob).EndGetPageRangeList(asyncResult);
            }
            catch (Exception exception1)
            {
                StorageStamp.TranslateException(exception1);
                throw;
            }
        }
Beispiel #4
0
        private IEnumerator <IAsyncResult> GetPropertiesImpl(BlobPropertyNames propertyNames, IBlobObjectCondition condition, AsyncIteratorContext <NoResults> context)
        {
            IAsyncResult asyncResult;

            try
            {
                asyncResult = this.blob.BeginGetProperties(propertyNames, Helpers.Convert(condition), context.GetResumeCallback(), context.GetResumeState("BaseBlobObject.GetPropertiesImpl"));
            }
            catch (Exception exception)
            {
                StorageStamp.TranslateException(exception);
                throw;
            }
            yield return(asyncResult);

            try
            {
                this.blob.EndGetProperties(asyncResult);
            }
            catch (Exception exception1)
            {
                StorageStamp.TranslateException(exception1);
                throw;
            }
        }
Beispiel #5
0
        private IEnumerator <IAsyncResult> RenewLeaseImpl(LeaseType leaseType, Guid leaseId, TimeSpan leaseDuration, IBlobObjectCondition condition, AsyncIteratorContext <NoResults> context)
        {
            IAsyncResult asyncResult;

            try
            {
                asyncResult = this.blob.BeginRenewLease(leaseType, leaseId, leaseDuration, Helpers.Convert(condition), context.GetResumeCallback(), context.GetResumeState("BaseBlobObject.RenewLeaseImpl"));
            }
            catch (Exception exception)
            {
                StorageStamp.TranslateException(exception);
                throw;
            }
            yield return(asyncResult);

            try
            {
                this.blob.EndRenewLease(asyncResult);
            }
            catch (Exception exception1)
            {
                StorageStamp.TranslateException(exception1);
                throw;
            }
        }
Beispiel #6
0
        public IAsyncResult BeginSetProperties(string contentType, long?maxBlobSize, NameValueCollection serviceMetadata, ServiceMetadataUpdatePolicy serviceMetadataPolicy, string[] serviceMetadataPolicyArguments, NameValueCollection applicationMetadata, ISequenceNumberUpdate sequenceNumberUpdate, IBlobObjectCondition condition, AsyncCallback callback, object state)
        {
            AsyncIteratorContext <NoResults> asyncIteratorContext = new AsyncIteratorContext <NoResults>("RealBlobObject.SetProperties", callback, state);

            asyncIteratorContext.Begin(this.SetPropertiesImpl(contentType, maxBlobSize, serviceMetadata, serviceMetadataPolicy, serviceMetadataPolicyArguments, applicationMetadata, sequenceNumberUpdate, condition, asyncIteratorContext));
            return(asyncIteratorContext);
        }
Beispiel #7
0
        private IEnumerator <IAsyncResult> ChangeLeaseImpl(Guid leaseId, Guid proposedLeaseId, IBlobObjectCondition condition, AsyncIteratorContext <NoResults> context)
        {
            IAsyncResult asyncResult;

            try
            {
                asyncResult = this.blob.BeginChangeLease(leaseId, proposedLeaseId, Helpers.Convert(condition), context.GetResumeCallback(), context.GetResumeState("BaseBlobObject.ChangeLeaseImpl"));
            }
            catch (Exception exception)
            {
                StorageStamp.TranslateException(exception);
                throw;
            }
            yield return(asyncResult);

            try
            {
                this.blob.EndChangeLease(asyncResult);
            }
            catch (Exception exception1)
            {
                StorageStamp.TranslateException(exception1);
                throw;
            }
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        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);
        }
Beispiel #10
0
        IAsyncResult Microsoft.Cis.Services.Nephos.Common.Storage.IListBlobObject.BeginPutBlock(byte[] blockIdentifier, long contentLength, Stream inputStream, CrcReaderStream crcReaderStream, byte[] contentMD5, bool isLargeBlockBlobRequest, IBlobObjectCondition condition, AsyncCallback callback, object state)
        {
            AsyncIteratorContext <NoResults> asyncIteratorContext = new AsyncIteratorContext <NoResults>("DbListBlobObject.PutBlock", callback, state);

            asyncIteratorContext.Begin(this.PutBlockImpl(blockIdentifier, contentLength, inputStream, contentMD5, isLargeBlockBlobRequest, condition, asyncIteratorContext));
            return(asyncIteratorContext);
        }
Beispiel #11
0
        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);
        }
Beispiel #12
0
        IAsyncResult Microsoft.Cis.Services.Nephos.Common.Storage.IListBlobObject.BeginGetBlockList(IBlobObjectCondition condition, BlockListTypes blockListTypes, BlobServiceVersion blobServiceVersion, AsyncCallback callback, object state)
        {
            AsyncIteratorContext <IBlockLists> asyncIteratorContext = new AsyncIteratorContext <IBlockLists>("DbListBlobObject.GetBlockList", callback, state);

            asyncIteratorContext.Begin(this.GetBlockListImpl(condition, blockListTypes, blobServiceVersion, asyncIteratorContext));
            return(asyncIteratorContext);
        }
Beispiel #13
0
        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);
        }
Beispiel #14
0
        public static void ValidatePutBlockListArguments(IBlobObject blob, long contentLength, byte[] applicationMetadata, byte[][] blockIdList, BlockSource[] blockSourceList, byte[] md5, IBlobObjectCondition condition, BlobServiceVersion blobServiceVersion)
        {
            if (blob.Snapshot != StorageStampHelpers.RootBlobSnapshotVersion)
            {
                throw new XStoreArgumentException("This operation is only supported on the root blob.");
            }
            if (contentLength < (long)-1)
            {
                throw new ArgumentOutOfRangeException("contentLength", "contentLength must be >= -1");
            }
            if (contentLength > 5242880000000L)
            {
                throw new BlobContentTooLargeException(new long?(5242880000000L), null, null);
            }
            StorageStampHelpers.ValidateApplicationMetadata(applicationMetadata);
            if (blockSourceList != null && blobServiceVersion < BlobServiceVersion.July09)
            {
                throw new XStoreArgumentException("blockSourceList is only allowed for verisons STG18 and up.");
            }
            int num  = (blockIdList != null ? (int)blockIdList.Length : 0);
            int num1 = (blockSourceList != null ? (int)blockSourceList.Length : 0);

            if (blockIdList != null && blockSourceList != null && num != num1)
            {
                string str = string.Format("blockIdList (length {0}) and blockSourceList (length {1}) must be of the same length.", num, num1);
                throw new XStoreArgumentException(str);
            }
            if ((long)num > (long)50000)
            {
                throw new BlockListTooLongException();
            }
            StorageStampHelpers.ValidateMD5(md5);
        }
Beispiel #15
0
        public IAsyncResult BeginPutBlob(string contentType, long contentLength, long?maxBlobSize, byte[] serviceMetadata, byte[] applicationMetadata, Stream inputStream, CrcReaderStream crcReaderStream, byte[] contentMD5, bool invokeGeneratePutBlobServiceMetadata, GeneratePutBlobServiceMetadata generatePutBlobServiceMetadata, bool isLargeBlockBlobRequest, bool is8TBPageBlobAllowed, ISequenceNumberUpdate sequenceNumberUpdate, OverwriteOption overwriteOption, IBlobObjectCondition condition, AsyncCallback callback, object state)
        {
            AsyncIteratorContext <NoResults> asyncIteratorContext = new AsyncIteratorContext <NoResults>("RealBlobObject.PutBlob", callback, state);

            asyncIteratorContext.Begin(this.PutBlobImpl(contentType, contentLength, maxBlobSize, serviceMetadata, applicationMetadata, inputStream, crcReaderStream, contentMD5, invokeGeneratePutBlobServiceMetadata, generatePutBlobServiceMetadata, isLargeBlockBlobRequest, is8TBPageBlobAllowed, sequenceNumberUpdate, overwriteOption, condition, asyncIteratorContext));
            return(asyncIteratorContext);
        }
Beispiel #16
0
 public IAsyncResult BeginAppendBlock(long contentLength, Stream inputStream, CrcReaderStream crcReaderStream, IBlobObjectCondition condition, long?conditionalMaxBlobSize, long?conditionalAppendBlockPosition, AsyncCallback callback, object state)
 {
     throw new NotImplementedException();
 }
Beispiel #17
0
        public IAsyncResult BeginRenewLease(LeaseType leaseType, Guid leaseId, TimeSpan leaseDuration, IBlobObjectCondition condition, AsyncCallback callback, object state)
        {
            AsyncIteratorContext <NoResults> asyncIteratorContext = new AsyncIteratorContext <NoResults>("RealBlobObject.RenewLease", callback, state);

            asyncIteratorContext.Begin(this.RenewLeaseImpl(leaseType, leaseId, leaseDuration, condition, asyncIteratorContext));
            return(asyncIteratorContext);
        }
Beispiel #18
0
        public IAsyncResult BeginPutBlob(string contentType, long contentLength, byte[] serviceMetadata, byte[] applicationMetadata, byte[][] blockList, BlockSource[] blockSourceList, byte[] contentMD5, OverwriteOption overwriteOption, IBlobObjectCondition condition, AsyncCallback callback, object state)
        {
            AsyncIteratorContext <NoResults> asyncIteratorContext = new AsyncIteratorContext <NoResults>("DbListBlobObject.PutBlob", callback, state);

            asyncIteratorContext.Begin(this.PutBlobImpl(contentType, contentLength, serviceMetadata, applicationMetadata, blockList, blockSourceList, contentMD5, overwriteOption, condition, asyncIteratorContext));
            return(asyncIteratorContext);
        }
Beispiel #19
0
        public IAsyncResult BeginSynchronousCopyBlob(string sourceAccount, IBlobObject sourceBlob, DateTime?expiryTime, byte[] applicationMetadata, OverwriteOption overwriteOption, IBlobObjectCondition sourceCondition, IBlobObjectCondition destinationCondition, UriString copySource, AsyncCallback callback, object state)
        {
            AsyncIteratorContext <CopyBlobOperationInfo> asyncIteratorContext = new AsyncIteratorContext <CopyBlobOperationInfo>("RealBlobObject.SynchronousCopyBlob", callback, state);

            asyncIteratorContext.Begin(this.SynchronousCopyBlobImpl(sourceAccount, sourceBlob, expiryTime, applicationMetadata, overwriteOption, sourceCondition, destinationCondition, copySource, asyncIteratorContext));
            return(asyncIteratorContext);
        }
Beispiel #20
0
        private IEnumerator <IAsyncResult> SetPropertiesImpl(string contentType, long?maxBlobSize, NameValueCollection serviceMetadata, ServiceMetadataUpdatePolicy serviceMetadataPolicy, string[] serviceMetadataPolicyArguments, NameValueCollection applicationMetadata, ISequenceNumberUpdate sequenceNumberUpdate, IBlobObjectCondition condition, AsyncIteratorContext <NoResults> context)
        {
            IAsyncResult asyncResult;

            try
            {
                asyncResult = this.blob.BeginSetProperties(contentType, maxBlobSize, serviceMetadata, serviceMetadataPolicy, serviceMetadataPolicyArguments, applicationMetadata, sequenceNumberUpdate, Helpers.Convert(condition), context.GetResumeCallback(), context.GetResumeState("BaseBlobObject.SetPropertiesImpl"));
            }
            catch (Exception exception)
            {
                StorageStamp.TranslateException(exception);
                throw;
            }
            yield return(asyncResult);

            try
            {
                this.blob.EndSetProperties(asyncResult);
            }
            catch (Exception exception1)
            {
                StorageStamp.TranslateException(exception1);
                throw;
            }
        }
Beispiel #21
0
        private IEnumerator <IAsyncResult> GetBlobImpl(IBlobRegion blobRegion, BlobPropertyNames propertyNames, IBlobObjectCondition condition, AsyncIteratorContext <CrcStream> context)
        {
            IAsyncResult asyncResult;

            try
            {
                asyncResult = this.blob.BeginGetBlob(blobRegion, propertyNames, Helpers.Convert(condition), context.GetResumeCallback(), context.GetResumeState("RealBlobObject.GetBlobImpl"));
            }
            catch (Exception exception)
            {
                StorageStamp.TranslateException(exception);
                throw;
            }
            yield return(asyncResult);

            try
            {
                context.ResultData = this.blob.EndGetBlob(asyncResult);
            }
            catch (Exception exception1)
            {
                StorageStamp.TranslateException(exception1);
                throw;
            }
        }
Beispiel #22
0
        private IEnumerator <IAsyncResult> SynchronousCopyBlobImpl(string sourceAccount, IBlobObject sourceBlob, DateTime?expiryTime, byte[] applicationMetadata, OverwriteOption overwriteOption, IBlobObjectCondition sourceCondition, IBlobObjectCondition destinationCondition, UriString copySource, AsyncIteratorContext <CopyBlobOperationInfo> context)
        {
            IAsyncResult asyncResult;

            try
            {
                asyncResult = this.blob.BeginSynchronousCopyBlob(sourceAccount, ((BaseBlobObject)sourceBlob).blob, StorageStampHelpers.AdjustNullableDatetimeRange(expiryTime), applicationMetadata, overwriteOption, Helpers.Convert(sourceCondition), Helpers.Convert(destinationCondition), copySource, context.GetResumeCallback(), context.GetResumeState("IBlobObject.BeginSynchronousCopyBlob"));
            }
            catch (Exception exception)
            {
                StorageStamp.TranslateException(exception);
                throw;
            }
            yield return(asyncResult);

            CopyBlobOperationInfo copyBlobOperationInfo = null;

            try
            {
                copyBlobOperationInfo = this.blob.EndSynchronousCopyBlob(asyncResult);
            }
            catch (Exception exception1)
            {
                StorageStamp.TranslateException(exception1);
                throw;
            }
            context.ResultData = copyBlobOperationInfo;
        }
Beispiel #23
0
        private IEnumerator <IAsyncResult> PutBlobImpl(string contentType, long contentLength, long?maxBlobSize, byte[] serviceMetadata, byte[] applicationMetadata, Stream inputStream, CrcReaderStream crcReaderStream, byte[] contentMD5, bool invokeGeneratePutBlobServiceMetadata, GeneratePutBlobServiceMetadata generatePutBlobServiceMetadata, bool isLargeBlockBlobRequest, bool is8TBPageBlobAllowed, ISequenceNumberUpdate sequenceNumberUpdate, OverwriteOption overwriteOption, IBlobObjectCondition condition, AsyncIteratorContext <NoResults> context)
        {
            IAsyncResult asyncResult;

            if (contentLength < (long)0)
            {
                throw new ArgumentOutOfRangeException("contentLength", "contentLength must be >= 0");
            }
            try
            {
                asyncResult = this.blob.BeginPutBlob(contentType, contentLength, maxBlobSize, serviceMetadata, applicationMetadata, inputStream, crcReaderStream, contentMD5, invokeGeneratePutBlobServiceMetadata, generatePutBlobServiceMetadata, isLargeBlockBlobRequest, is8TBPageBlobAllowed, sequenceNumberUpdate, overwriteOption, Helpers.Convert(condition), context.GetResumeCallback(), context.GetResumeState("RealBlobObject.PutBlobImpl"));
            }
            catch (Exception exception)
            {
                StorageStamp.TranslateException(exception);
                throw;
            }
            yield return(asyncResult);

            try
            {
                this.blob.EndPutBlob(asyncResult);
            }
            catch (Exception exception1)
            {
                StorageStamp.TranslateException(exception1);
                throw;
            }
        }
Beispiel #24
0
        private IEnumerator <IAsyncResult> AsynchronousCopyBlobImpl(UriString copySource, bool isSourceAzureBlob, FECopyType copyType, long contentLength, string contentType, NameValueCollection serviceMetadataCollection, byte[] applicationMetadata, ISequenceNumberUpdate sequenceNumberUpdate, OverwriteOption overwriteOption, string sourceETag, IBlobObjectCondition destinationCondition, AsyncIteratorContext <CopyBlobOperationInfo> context)
        {
            IAsyncResult asyncResult;

            try
            {
                asyncResult = this.blob.BeginAsynchronousCopyBlob(copySource, isSourceAzureBlob, copyType, contentLength, contentType, serviceMetadataCollection, applicationMetadata, sequenceNumberUpdate, overwriteOption, sourceETag, Helpers.Convert(destinationCondition), context.GetResumeCallback(), context.GetResumeState("IBlobObject.BeginAsynchronousCopyBlob"));
            }
            catch (Exception exception)
            {
                StorageStamp.TranslateException(exception);
                throw;
            }
            yield return(asyncResult);

            CopyBlobOperationInfo copyBlobOperationInfo = null;

            try
            {
                copyBlobOperationInfo = this.blob.EndAsynchronousCopyBlob(asyncResult);
            }
            catch (Exception exception1)
            {
                StorageStamp.TranslateException(exception1);
                throw;
            }
            context.ResultData = copyBlobOperationInfo;
        }
Beispiel #25
0
        private IEnumerator <IAsyncResult> SetApplicationMetadataImpl(byte[] metadata, IBlobObjectCondition condition, AsyncIteratorContext <NoResults> context)
        {
            IAsyncResult asyncResult;

            try
            {
                asyncResult = this.blob.BeginSetApplicationMetadata(metadata, Helpers.Convert(condition), context.GetResumeCallback(), context.GetResumeState("BaseBlobObject.SetApplicationMetadataImpl"));
            }
            catch (Exception exception)
            {
                StorageStamp.TranslateException(exception);
                throw;
            }
            yield return(asyncResult);

            try
            {
                this.blob.EndSetApplicationMetadata(asyncResult);
            }
            catch (Exception exception1)
            {
                StorageStamp.TranslateException(exception1);
                throw;
            }
        }
Beispiel #26
0
        public IAsyncResult BeginAsynchronousCopyBlob(UriString copySource, bool isSourceAzureBlob, FECopyType copyType, long contentLength, string contentType, NameValueCollection serviceMetadataCollection, byte[] applicationMetadata, ISequenceNumberUpdate sequenceNumberUpdate, OverwriteOption overwriteOption, string sourceETag, IBlobObjectCondition destinationCondition, AsyncCallback callback, object state)
        {
            AsyncIteratorContext <CopyBlobOperationInfo> asyncIteratorContext = new AsyncIteratorContext <CopyBlobOperationInfo>("RealBlobObject.AsynchronousCopyBlob", callback, state);

            asyncIteratorContext.Begin(this.AsynchronousCopyBlobImpl(copySource, isSourceAzureBlob, copyType, contentLength, contentType, serviceMetadataCollection, applicationMetadata, sequenceNumberUpdate, overwriteOption, sourceETag, destinationCondition, asyncIteratorContext));
            return(asyncIteratorContext);
        }
Beispiel #27
0
        IAsyncResult Microsoft.Cis.Services.Nephos.Common.Storage.IBlobContainer.BeginListBlobs(string blobNamePrefix, BlobPropertyNames propertyNames, string separator, string blobNameStart, DateTime?snapshotStart, IBlobObjectCondition condition, int maxBlobNames, BlobServiceVersion version, AsyncCallback callback, object state)
        {
            AsyncIteratorContext <IBlobObjectCollection> asyncIteratorContext = new AsyncIteratorContext <IBlobObjectCollection>("RealBlobContainer.ListBlobs", callback, state);

            asyncIteratorContext.Begin(this.ListBlobsImpl(blobNamePrefix, propertyNames, separator, blobNameStart, snapshotStart, condition, maxBlobNames, version, asyncIteratorContext));
            return(asyncIteratorContext);
        }
Beispiel #28
0
        public IAsyncResult BeginGetBlob(IBlobRegion blobRegion, BlobPropertyNames propertyNames, IBlobObjectCondition condition, AsyncCallback callback, object state)
        {
            AsyncIteratorContext <CrcStream> asyncIteratorContext = new AsyncIteratorContext <CrcStream>("RealBlobObject.GetBlob", callback, state);

            asyncIteratorContext.Begin(this.GetBlobImpl(blobRegion, propertyNames, condition, asyncIteratorContext));
            return(asyncIteratorContext);
        }
Beispiel #29
0
        private IEnumerator <IAsyncResult> PutPageImpl(IBlobRegion blobRegion, Stream inputStream, CrcReaderStream crcReaderStream, IBlobObjectCondition condition, AsyncIteratorContext <NoResults> context)
        {
            IAsyncResult asyncResult;

            try
            {
                asyncResult = ((IIndexBlobObject)this.blob).BeginPutPage(blobRegion, inputStream, crcReaderStream, Helpers.Convert(condition), context.GetResumeCallback(), context.GetResumeState("IndexBlobObject.PutPageImpl"));
            }
            catch (Exception exception)
            {
                StorageStamp.TranslateException(exception);
                throw;
            }
            yield return(asyncResult);

            try
            {
                ((IIndexBlobObject)this.blob).EndPutPage(asyncResult);
            }
            catch (Exception exception1)
            {
                StorageStamp.TranslateException(exception1);
                throw;
            }
        }
Beispiel #30
0
 public static void ValidatePutBlockArguments(IBlobObject blob, byte[] blockIdentifier, long contentLength, byte[] contentMD5, IBlobObjectCondition condition)
 {
     StorageStampHelpers.ValidatePutBlockArguments(blob, blockIdentifier, contentLength, contentMD5, condition, false);
 }