Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        protected override IEnumerator <IAsyncResult> GetQueuePropertiesImpl(IAccountIdentifier identity, string account, string queue, bool getMessageCount, SASAuthorizationParameters sasParams, TimeSpan?timeout, RequestContext requestContext, AsyncIteratorContext <QueueProperties> context)
        {
            RemainingTime remainingTime = new RemainingTime(timeout);
            IAsyncResult  asyncResult   = this.BeginGetQueue(identity, account, queue, PermissionLevel.Read, sasParams, ContainerPropertyNames.ApplicationMetadata, remainingTime, requestContext, context.GetResumeCallback(), context.GetResumeState("QueueManager.GetQueuePropertiesImpl"));

            yield return(asyncResult);

            IQueueContainer operationStatus = this.EndGetQueue(asyncResult);

            if (requestContext != null)
            {
                operationStatus.OperationStatus = requestContext.OperationStatus;
            }
            NameValueCollection nameValueCollection = QueueHelpers.DeserializeMetadata(operationStatus.ApplicationMetadata);
            long?nullable = null;

            if (getMessageCount)
            {
                operationStatus.Timeout = remainingTime;
                asyncResult             = operationStatus.BeginGetQueueStatistics(true, true, context.GetResumeCallback(), context.GetResumeState("QueueManager.GetQueuePropertiesImpl"));
                yield return(asyncResult);

                nullable = new long?(operationStatus.EndGetQueueStatistics(asyncResult).TotalMessages);
            }
            context.ResultData = new QueueProperties(account, queue, nullable, nameValueCollection);
        }
Exemplo n.º 3
0
        protected override IEnumerator <IAsyncResult> ListMessagesImpl(IAccountIdentifier identity, string account, string queue, string messageMarker, bool includeInvisibleMessages, bool incldueMessageTextProperty, int maxMessages, TimeSpan?timeout, RequestContext requestContext, AsyncIteratorContext <ListMessagesResult> context)
        {
            string   nextQueueStart;
            DateTime?nextVisibilityStart;
            Guid     guid;
            int?     subQueueId;
            object   obj;

            this.ValidateNumMessages(maxMessages, this.config.MaxMessagesToReturnForListMessages);
            RemainingTime remainingTime = new RemainingTime(timeout);
            SASAuthorizationParameters sASAuthorizationParameter = new SASAuthorizationParameters()
            {
                SupportedSasTypes  = SasType.ResourceSas | SasType.AccountSas,
                SignedResourceType = SasResourceType.Object,
                SignedPermission   = SASPermission.Read
            };
            SASAuthorizationParameters sASAuthorizationParameter1 = sASAuthorizationParameter;
            IAsyncResult asyncResult = this.BeginGetQueue(identity, account, queue, PermissionLevel.Read, sASAuthorizationParameter1, remainingTime, requestContext, context.GetResumeCallback(), context.GetResumeState("QueueManager.PeekMessagesImpl"));

            yield return(asyncResult);

            IQueueContainer operationStatus = this.EndGetQueue(asyncResult);

            if (requestContext != null)
            {
                operationStatus.OperationStatus = requestContext.OperationStatus;
            }
            operationStatus.Timeout = remainingTime;
            ListMessagesMarker listMessagesMarker = SummaryResult.DecodeMarker <ListMessagesMarker>(messageMarker);

            if (listMessagesMarker == null)
            {
                Logger <IRestProtocolHeadLogger> .Instance.VerboseDebug.Log("ListMessageImpl marker is null");
            }
            else
            {
                IStringDataEventStream verboseDebug = Logger <IRestProtocolHeadLogger> .Instance.VerboseDebug;
                verboseDebug.Log("ListMessageImpl marker.NextQueueStart: {0}", new object[] { listMessagesMarker.NextQueueStart });
                IStringDataEventStream stringDataEventStream = Logger <IRestProtocolHeadLogger> .Instance.VerboseDebug;
                object[] objArray = new object[] { listMessagesMarker.SubQueueId };
                stringDataEventStream.Log("ListMessageImpl marker.SubQueueId: {0}", objArray);
                IStringDataEventStream verboseDebug1 = Logger <IRestProtocolHeadLogger> .Instance.VerboseDebug;
                object[] nextMessageIdStart          = new object[] { listMessagesMarker.NextMessageIdStart };
                verboseDebug1.Log("ListMessageImpl marker.NextMessageIdStart: {0}", nextMessageIdStart);
                IStringDataEventStream stringDataEventStream1 = Logger <IRestProtocolHeadLogger> .Instance.VerboseDebug;
                object[] objArray1 = new object[1];
                object[] objArray2 = objArray1;
                obj          = (listMessagesMarker.NextVisibilityStart.HasValue ? listMessagesMarker.NextVisibilityStart.Value.ToString("mm/dd/yy hh:mm:ss.fff") : "null");
                objArray2[0] = obj;
                stringDataEventStream1.Log("ListMessageImpl marker.NextVisibilityStart: {0}", objArray1);
            }
            IQueueContainer queueContainer = operationStatus;

            if (listMessagesMarker == null)
            {
                nextQueueStart = null;
            }
            else
            {
                nextQueueStart = listMessagesMarker.NextQueueStart;
            }
            if (listMessagesMarker == null)
            {
                nextVisibilityStart = null;
            }
            else
            {
                nextVisibilityStart = listMessagesMarker.NextVisibilityStart;
            }
            guid = (listMessagesMarker == null ? Guid.Empty : listMessagesMarker.NextMessageIdStart);
            if (listMessagesMarker == null)
            {
                subQueueId = null;
            }
            else
            {
                subQueueId = listMessagesMarker.SubQueueId;
            }
            asyncResult = queueContainer.BeginListMessages(nextQueueStart, nextVisibilityStart, guid, subQueueId, includeInvisibleMessages, maxMessages, context.GetResumeCallback(), context.GetResumeState("QueueManager.PeekMessagesImpl"));
            yield return(asyncResult);

            ListMessagesResult listMessagesResults = operationStatus.EndListMessages(asyncResult);

            listMessagesResults.PoppedMessages = this.WrapGetMessageResults(listMessagesResults.Messages);
            context.ResultData = listMessagesResults;
            StringBuilder stringBuilder = new StringBuilder();
            int           num           = 0;

            foreach (PoppedMessage poppedMessage in context.ResultData.PoppedMessages)
            {
                stringBuilder.Append(string.Format("[{0}],", poppedMessage.ToString()));
                num++;
            }
            IStringDataEventStream verboseDebug2 = Logger <IRestProtocolHeadLogger> .Instance.VerboseDebug;

            object[] str = new object[] { num, stringBuilder.ToString() };
            verboseDebug2.Log("ListMessages response: Count={0} Messages={1}", str);
        }
Exemplo n.º 4
0
        protected override IEnumerator <IAsyncResult> DeleteQueueImpl(IAccountIdentifier identity, string account, string queue, TimeSpan?timeout, RequestContext requestContext, AsyncIteratorContext <NoResults> context)
        {
            RemainingTime remainingTime = new RemainingTime(timeout);
            SASAuthorizationParameters sASAuthorizationParameter = new SASAuthorizationParameters()
            {
                SupportedSasTypes  = SasType.AccountSas,
                SignedResourceType = SasResourceType.Container,
                SignedPermission   = SASPermission.Delete
            };
            SASAuthorizationParameters sASAuthorizationParameter1 = sASAuthorizationParameter;
            IAsyncResult asyncResult = this.authorizationManager.BeginCheckAccess(identity, account, null, null, PermissionLevel.Delete, sASAuthorizationParameter1, remainingTime, context.GetResumeCallback(), context.GetResumeState("QueueManager.DeleteQueueImpl"));

            yield return(asyncResult);

            this.authorizationManager.EndCheckAccess(asyncResult);
            IStorageAccount storageAccount = this.storageManager.CreateAccountInstance(account);

            storageAccount.Timeout = remainingTime;
            asyncResult            = storageAccount.BeginDeleteQueueContainer(queue, null, context.GetResumeCallback(), context.GetResumeState("QueueManager.DeleteQueueImpl"));
            yield return(asyncResult);

            storageAccount.EndDeleteQueueContainer(asyncResult);
        }
Exemplo n.º 5
0
        protected override IEnumerator <IAsyncResult> GetQueueAclImpl(IAccountIdentifier identifier, string account, string queue, TimeSpan timeout, RequestContext requestContext, AsyncIteratorContext <ContainerAclSettings> context)
        {
            Duration startingNow = Duration.StartingNow;

            if (identifier == null)
            {
                throw new ArgumentNullException("identifier");
            }
            if (string.IsNullOrEmpty(account))
            {
                throw new ArgumentException("account", "Cannot be null or empty");
            }
            if (string.IsNullOrEmpty(queue))
            {
                throw new ArgumentException("queue", "Cannot be null or empty");
            }
            if (timeout <= TimeSpan.Zero)
            {
                throw new TimeoutException("Timed out in GetQueueAcl");
            }
            RemainingTime remainingTime = new RemainingTime(timeout);
            IAsyncResult  asyncResult   = this.BeginGetQueue(identifier, account, queue, PermissionLevel.ReadAcl, ContainerPropertyNames.ServiceMetadata, remainingTime, requestContext, context.GetResumeCallback(), context.GetResumeState("QueueManager.GetQueueAclImpl"));

            yield return(asyncResult);

            IQueueContainer operationStatus = this.EndGetQueue(asyncResult);

            if (requestContext != null)
            {
                operationStatus.OperationStatus = requestContext.OperationStatus;
            }
            context.ResultData = new ContainerAclSettings(operationStatus.ServiceMetadata);
        }
Exemplo n.º 6
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;
            }
        }
Exemplo n.º 7
0
        private IEnumerator <IAsyncResult> SetExpiryTimeImpl(DateTime expiryTime, IBlobObjectCondition condition, AsyncIteratorContext <NoResults> context)
        {
            IAsyncResult asyncResult;

            try
            {
                asyncResult = this.blob.BeginSetExpiryTime(StorageStampHelpers.AdjustDateTimeRange(expiryTime), Helpers.Convert(condition), context.GetResumeCallback(), context.GetResumeState("BaseBlobObject.SetExpiryTimeImpl"));
            }
            catch (Exception exception)
            {
                StorageStamp.TranslateException(exception);
                throw;
            }
            yield return(asyncResult);

            try
            {
                this.blob.EndSetExpiryTime(asyncResult);
            }
            catch (Exception exception1)
            {
                StorageStamp.TranslateException(exception1);
                throw;
            }
        }
Exemplo n.º 8
0
        private IEnumerator <IAsyncResult> ExecuteImpl <T>(AsyncProcessor.WorkItem <T> workItem, TimeSpan timeout, AsyncIteratorContext <T> context)
        {
            object   obj         = null;
            object   obj1        = null;
            Duration startingNow = Duration.StartingNow;

            if (timeout == TimeSpan.Zero)
            {
                throw new TimeoutException("Timed out in AsyncSemaphore");
            }
            if (timeout < TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException("timeout", (object)timeout, "Must be >= 0");
            }
            bool flag = false;

            try
            {
                object obj2 = this.syncObj;
                object obj3 = obj2;
                obj = obj2;
                Monitor.Enter(obj3, ref flag);
                if (this.state != AsyncProcessor.State.Running)
                {
                    throw new InvalidOperationException("AsyncProcessor must be running first");
                }
            }
            finally
            {
                if (flag)
                {
                    Monitor.Exit(obj);
                }
            }
            IAsyncResult asyncResult = this.asyncSemaphore.BeginAcquire(timeout, context.GetResumeCallback(), context.GetResumeState("AsyncProcessor.ExecuteImpl"));

            yield return(asyncResult);

            this.asyncSemaphore.EndAcquire(asyncResult);
            using (AsyncSignal <T> asyncSignal = new AsyncSignal <T>())
            {
                asyncResult = asyncSignal.BeginWait(startingNow.Remaining(timeout), context.GetResumeCallback(), context.GetResumeState("AsyncProcessor.ExecuteImpl"));
                Guid activityId = AsyncHelper.Trace.ActivityId;
                bool flag1      = false;
                try
                {
                    object obj4 = this.syncObj;
                    object obj5 = obj4;
                    obj1 = obj4;
                    Monitor.Enter(obj5, ref flag1);
                    Queue <AsyncProcessor.WorkItemJob> workItemJobs = this.workItemQueue;
                    workItemJobs.Enqueue(new AsyncProcessor.WorkItemJob(() => {
                        Exception exception          = null;
                        T cSu0024u003cu003e8_localsa = default(T);
                        try
                        {
                            AsyncHelper.Trace.ActivityId = activityId;
                            cSu0024u003cu003e8_localsa   = workItem(startingNow.Remaining(timeout));
                        }
                        catch (Exception exception1)
                        {
                            exception = exception1;
                        }
                        if (exception != null)
                        {
                            asyncSignal.Abort(exception);
                        }
                        else
                        {
                            asyncSignal.Set(cSu0024u003cu003e8_localsa);
                        }
                        this.asyncSemaphore.Release(1);
                    }));
                }
                finally
                {
                    if (flag1)
                    {
                        Monitor.Exit(obj1);
                    }
                }
                this.semaphore.Release();
                yield return(asyncResult);

                context.ResultData = asyncSignal.EndWait(asyncResult);
            }
        }
Exemplo n.º 9
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;
            }
        }
Exemplo n.º 10
0
        private IEnumerator <IAsyncResult> GetPropertiesNoCacheSynchronizationImpl(ContainerPropertyNames propertyNames, IContainerCondition condition, CacheRefreshOptions cacheRefreshOptions, bool shouldUpdateCacheEntryOnRefresh, AsyncIteratorContext <NoResults> context)
        {
            IAsyncResult asyncResult;

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

            try
            {
                this.container.EndGetProperties(asyncResult);
            }
            catch (Exception exception1)
            {
                StorageStamp.TranslateException(exception1);
                throw;
            }
        }
Exemplo n.º 11
0
        private IEnumerator <IAsyncResult> SetPropertiesImpl(ContainerPropertyNames propertyNames, IContainerCondition condition, AsyncIteratorContext <NoResults> context)
        {
            IAsyncResult asyncResult;

            try
            {
                asyncResult = this.container.BeginSetProperties(propertyNames, Helpers.Convert(condition), context.GetResumeCallback(), context.GetResumeState("BlobContainer.SetProperties"));
            }
            catch (Exception exception)
            {
                StorageStamp.TranslateException(exception);
                throw;
            }
            yield return(asyncResult);

            try
            {
                this.container.EndSetProperties(asyncResult);
            }
            catch (Exception exception1)
            {
                StorageStamp.TranslateException(exception1);
                throw;
            }
        }
Exemplo n.º 12
0
        private IEnumerator <IAsyncResult> GetPropertiesImpl(ContainerPropertyNames propertyNames, IContainerCondition condition, CacheRefreshOptions cacheRefreshOptions, bool shouldUpdateCacheEntryOnRefresh, AsyncIteratorContext <NoResults> context)
        {
            IAsyncResult asyncResult = this.Account.BeginGetProperties(AccountPropertyNames.None, null, context.GetResumeCallback(), context.GetResumeState("Container.GetPropertiesImpl"));

            yield return(asyncResult);

            this.Account.EndGetProperties(asyncResult);
            asyncResult = this.BeginGetPropertiesNoCacheSynchronization(propertyNames, condition, cacheRefreshOptions, shouldUpdateCacheEntryOnRefresh, context.GetResumeCallback(), context.GetResumeState("Container.GetPropertiesImpl"));
            yield return(asyncResult);

            this.EndGetPropertiesNoCacheSynchronization(asyncResult);
        }
Exemplo n.º 13
0
        private IEnumerator <IAsyncResult> AuthenticateImpl(IStorageAccount storageAccount, RequestContext requestContext, NephosUriComponents uriComponents, AuthenticationManager.GetStringToSignCallback getStringToSignCallback, TimeSpan timeout, AsyncIteratorContext <IAuthenticationResult> context)
        {
            bool flag;
            bool flag1;
            SignedAccessHelper   queueSignedAccessHelper;
            IStorageAccount      operationStatus;
            ContainerAclSettings containerAclSetting;
            string              signedVersion   = null;
            Duration            startingNow     = Duration.StartingNow;
            NameValueCollection queryParameters = requestContext.QueryParameters;

            if (AuthenticationManager.IsInvalidAccess(requestContext))
            {
                throw new InvalidAuthenticationInfoException("Ambiguous authentication scheme credentials providedRequest contains authentication credentials for signed access and authenticated access");
            }
            bool flag2 = AuthenticationManager.IsAuthenticatedAccess(requestContext);
            bool flag3 = AuthenticationManager.IsSignatureAccess(requestContext);

            flag = (!flag2 ? false : AuthenticationManager.IsAuthenticatedAccess(requestContext, "SignedKey"));
            bool flag4 = flag;

            flag1 = (flag2 ? false : !flag3);
            if ((!flag2 || flag4) && !flag1)
            {
                NephosAssertionException.Assert((flag3 ? true : flag4));
                bool flag5 = (flag3 ? false : flag4);
                if (!AuthenticationManager.IsAccountSasAccess(requestContext.QueryParameters))
                {
                    queueSignedAccessHelper = new QueueSignedAccessHelper(requestContext, uriComponents, flag5);
                }
                else
                {
                    if (flag5)
                    {
                        throw new AuthenticationFailureException("SignedKey is not supported with account-level SAS.");
                    }
                    queueSignedAccessHelper = new AccountSasHelper(requestContext, uriComponents);
                }
                queueSignedAccessHelper.ParseAccessPolicyFields(flag5);
                queueSignedAccessHelper.PerformSignedAccessAuthenticationFirstPhaseValidations();
                AccountIdentifier signedAccessAccountIdentifier = null;
                if (!flag5)
                {
                    byte[] sign = queueSignedAccessHelper.ComputeUrlDecodedUtf8EncodedStringToSign();
                    if (storageAccount == null || !string.Equals(storageAccount.Name, uriComponents.AccountName))
                    {
                        try
                        {
                            operationStatus = this.storageManager.CreateAccountInstance(uriComponents.AccountName);
                            if (requestContext != null)
                            {
                                operationStatus.OperationStatus = requestContext.OperationStatus;
                            }
                        }
                        catch (ArgumentOutOfRangeException argumentOutOfRangeException)
                        {
                            throw new AuthenticationFailureException(string.Format(CultureInfo.InvariantCulture, "The account name is invalid.", new object[0]));
                        }
                        operationStatus.Timeout = startingNow.Remaining(timeout);
                        IAsyncResult asyncResult = operationStatus.BeginGetProperties(AccountPropertyNames.All, null, context.GetResumeCallback(), context.GetResumeState("XFEQueueAuthenticationManager.AuthenticateImpl"));
                        yield return(asyncResult);

                        try
                        {
                            operationStatus.EndGetProperties(asyncResult);
                        }
                        catch (AccountNotFoundException accountNotFoundException1)
                        {
                            AccountNotFoundException accountNotFoundException = accountNotFoundException1;
                            CultureInfo invariantCulture = CultureInfo.InvariantCulture;
                            object[]    name             = new object[] { operationStatus.Name };
                            throw new AuthenticationFailureException(string.Format(invariantCulture, "Cannot find the claimed account when trying to GetProperties for the account {0}.", name), accountNotFoundException);
                        }
                        catch (Exception exception1)
                        {
                            Exception exception            = exception1;
                            IStringDataEventStream warning = Logger <IRestProtocolHeadLogger> .Instance.Warning;
                            object[] objArray = new object[] { operationStatus.Name, exception };
                            warning.Log("Rethrow exception when trying to GetProperties for the account {0}: {1}", objArray);
                            throw;
                        }
                    }
                    else
                    {
                        operationStatus = storageAccount;
                    }
                    if (!queueSignedAccessHelper.ComputeSignatureAndCompare(sign, operationStatus.SecretKeysV3))
                    {
                        throw new AuthenticationFailureException(string.Concat("Signature did not match. String to sign used was ", (new UTF8Encoding()).GetString(sign)));
                    }
                    NephosAssertionException.Assert(queueSignedAccessHelper.KeyUsedForSigning != null, "Key used for signing cannot be null");
                    signedAccessAccountIdentifier = queueSignedAccessHelper.CreateAccountIdentifier(operationStatus);
                    if (storageAccount != operationStatus)
                    {
                        operationStatus.Dispose();
                    }
                }
                else
                {
                    IAsyncResult asyncResult1 = this.nephosAuthenticationManager.BeginAuthenticate(storageAccount, requestContext, uriComponents, getStringToSignCallback, startingNow.Remaining(timeout), context.GetResumeCallback(), context.GetResumeState("XFEQueueAuthenticationManager.AuthenticateImpl"));
                    yield return(asyncResult1);

                    IAuthenticationResult authenticationResult = this.nephosAuthenticationManager.EndAuthenticate(asyncResult1);
                    signedAccessAccountIdentifier = new SignedAccessAccountIdentifier(authenticationResult.AccountIdentifier);
                }
                signedVersion = queueSignedAccessHelper.SignedVersion;
                if (queueSignedAccessHelper.IsRevocableAccess)
                {
                    using (IQueueContainer queueContainer = this.storageManager.CreateQueueContainerInstance(uriComponents.AccountName, uriComponents.ContainerName))
                    {
                        if (requestContext != null)
                        {
                            queueContainer.OperationStatus = requestContext.OperationStatus;
                        }
                        ContainerPropertyNames containerPropertyName = ContainerPropertyNames.ServiceMetadata;
                        queueContainer.Timeout = startingNow.Remaining(timeout);
                        IAsyncResult asyncResult2 = queueContainer.BeginGetProperties(containerPropertyName, null, context.GetResumeCallback(), context.GetResumeState("XFEQueueAuthenticationManager.AuthenticateImpl"));
                        yield return(asyncResult2);

                        try
                        {
                            queueContainer.EndGetProperties(asyncResult2);
                        }
                        catch (Exception exception3)
                        {
                            Exception exception2 = exception3;
                            if (exception2 is ContainerNotFoundException)
                            {
                                throw new AuthenticationFailureException("Error locating SAS identifier", exception2);
                            }
                            IStringDataEventStream stringDataEventStream = Logger <IRestProtocolHeadLogger> .Instance.Warning;
                            object[] accountName = new object[] { uriComponents.AccountName, uriComponents.ContainerName, exception2 };
                            stringDataEventStream.Log("Rethrow exception when trying to fetch SAS identifier account {0} container {1} : {2}", accountName);
                            throw;
                        }
                        try
                        {
                            containerAclSetting = new ContainerAclSettings(queueContainer.ServiceMetadata);
                        }
                        catch (MetadataFormatException metadataFormatException1)
                        {
                            MetadataFormatException metadataFormatException = metadataFormatException1;
                            throw new NephosStorageDataCorruptionException(string.Format("Error decoding Acl setting for container {0}", uriComponents.ContainerName), metadataFormatException);
                        }
                    }
                    try
                    {
                        queueSignedAccessHelper.ValidateAndDeriveEffectiveAccessPolicy(queueSignedAccessHelper.LocateSasIdentifier(containerAclSetting.SASIdentifiers));
                        queueSignedAccessHelper.PerformSignedAccessAuthenticationSecondPhaseValidations();
                        signedAccessAccountIdentifier.Initialize(queueSignedAccessHelper);
                        context.ResultData = new AuthenticationResult(signedAccessAccountIdentifier, signedVersion, true);
                    }
                    catch (FormatException formatException)
                    {
                        throw new AuthenticationFailureException("Signature fields not well formed.", formatException);
                    }
                }
                else
                {
                    signedAccessAccountIdentifier.Initialize(queueSignedAccessHelper);
                    context.ResultData = new AuthenticationResult(signedAccessAccountIdentifier, signedVersion, true);
                }
            }
            else
            {
                IAsyncResult asyncResult3 = this.nephosAuthenticationManager.BeginAuthenticate(storageAccount, requestContext, uriComponents, getStringToSignCallback, startingNow.Remaining(timeout), context.GetResumeCallback(), context.GetResumeState("XFEQueueAuthenticationManager.AuthenticateImpl"));
                yield return(asyncResult3);

                context.ResultData = this.nephosAuthenticationManager.EndAuthenticate(asyncResult3);
            }
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
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;
            }
        }
Exemplo n.º 16
0
        private IEnumerator <IAsyncResult> SnapshotBlobImpl(byte[] metadata, IBlobObjectCondition condition, AsyncIteratorContext <DateTime> context)
        {
            IAsyncResult asyncResult;

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

            DateTime minValue = DateTime.MinValue;

            try
            {
                minValue = this.blob.EndSnapshotBlob(asyncResult);
            }
            catch (Exception exception1)
            {
                StorageStamp.TranslateException(exception1);
                throw;
            }
            NephosAssertionException.Assert(minValue != DateTime.MinValue, "The snapshot timestamp must be set!");
            context.ResultData = minValue;
        }
Exemplo n.º 17
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;
            }
        }
Exemplo n.º 18
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;
        }
Exemplo n.º 19
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;
            }
        }
Exemplo n.º 20
0
        private IEnumerator <IAsyncResult> AbortCopyBlobImpl(Guid copyId, IBlobObjectCondition condition, AsyncIteratorContext <NoResults> context)
        {
            IAsyncResult asyncResult;

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

            try
            {
                this.blob.EndAbortCopyBlob(asyncResult);
            }
            catch (Exception exception1)
            {
                StorageStamp.TranslateException(exception1);
                throw;
            }
        }
Exemplo n.º 21
0
        protected override IEnumerator <IAsyncResult> DeleteMessageImpl(IAccountIdentifier identity, string account, string queue, string messageId, byte[] popReceipt, TimeSpan?timeout, RequestContext requestContext, AsyncIteratorContext <NoResults> context)
        {
            RemainingTime remainingTime = new RemainingTime(timeout);
            SASAuthorizationParameters sASAuthorizationParameter = new SASAuthorizationParameters()
            {
                SupportedSasTypes  = SasType.ResourceSas | SasType.AccountSas,
                SignedResourceType = SasResourceType.Object,
                SignedPermission   = SASPermission.Process
            };
            SASAuthorizationParameters sASAuthorizationParameter1 = sASAuthorizationParameter;

            NephosAssertionException.Assert(popReceipt != null);
            IAsyncResult asyncResult = this.BeginGetQueue(identity, account, queue, PermissionLevel.Delete, sASAuthorizationParameter1, remainingTime, requestContext, context.GetResumeCallback(), context.GetResumeState("QueueManager.DeleteMessageImpl"));

            yield return(asyncResult);

            IQueueContainer operationStatus = this.EndGetQueue(asyncResult);

            if (requestContext != null)
            {
                operationStatus.OperationStatus = requestContext.OperationStatus;
            }
            try
            {
                Guid guid = new Guid(messageId);
            }
            catch (Exception exception)
            {
                throw new MessageNotFoundException("Invalid message name", exception);
            }
            IQueueMessageReceipt queueMessageReceipt = this.DecodeReceipt(popReceipt, new Guid(messageId));

            operationStatus.Timeout = remainingTime;
            asyncResult             = operationStatus.BeginDeleteMessage(queueMessageReceipt, context.GetResumeCallback(), context.GetResumeState("QueueManager.DeleteMessageImpl"));
            yield return(asyncResult);

            bool flag = operationStatus.EndDeleteMessage(asyncResult);
            IStringDataEventStream verboseDebug = Logger <IRestProtocolHeadLogger> .Instance.VerboseDebug;

            object[] str = new object[] { flag, queueMessageReceipt.ToString() };
            verboseDebug.Log("DeleteMessage response: status={0} message={1}", str);
            if (!flag)
            {
                throw new MessageNotFoundException("The message could not be deleted or pop receipt invalid.");
            }
        }
Exemplo n.º 22
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;
        }
Exemplo n.º 23
0
        protected override IEnumerator <IAsyncResult> GetMessagesImpl(IAccountIdentifier identity, string account, string queue, int numMessages, long?visibilityTimeout, TimeSpan?timeout, RequestContext requestContext, AsyncIteratorContext <IEnumerable <PoppedMessage> > context)
        {
            object obj;

            this.ValidateNumMessages(numMessages, this.config.MaxMessagesToReturn);
            RemainingTime remainingTime = new RemainingTime(timeout);
            SASAuthorizationParameters sASAuthorizationParameter = new SASAuthorizationParameters()
            {
                SupportedSasTypes  = SasType.ResourceSas | SasType.AccountSas,
                SignedResourceType = SasResourceType.Object,
                SignedPermission   = SASPermission.Process
            };
            SASAuthorizationParameters sASAuthorizationParameter1 = sASAuthorizationParameter;
            IAsyncResult asyncResult = this.BeginGetQueue(identity, account, queue, PermissionLevel.ReadDelete, sASAuthorizationParameter1, remainingTime, requestContext, context.GetResumeCallback(), context.GetResumeState("QueueManager.GetMessagesImpl"));

            yield return(asyncResult);

            IQueueContainer operationStatus = this.EndGetQueue(asyncResult);

            if (requestContext != null)
            {
                operationStatus.OperationStatus = requestContext.OperationStatus;
            }
            long?nullable = visibilityTimeout;

            obj = (nullable.HasValue ? nullable.GetValueOrDefault() : this.config.DefaultVisibilityTimeoutSeconds);
            TimeSpan timeSpan = TimeSpan.FromSeconds((double)obj);

            operationStatus.Timeout = remainingTime;
            asyncResult             = operationStatus.BeginGetMessage(numMessages, timeSpan, context.GetResumeCallback(), context.GetResumeState("QueueManager.GetMessagesImpl"));
            yield return(asyncResult);

            IEnumerable <IMessageData> messageDatas = operationStatus.EndGetMessage(asyncResult);
            StringBuilder stringBuilder             = new StringBuilder();

            context.ResultData = this.WrapGetMessageResults(messageDatas);
            int num = 0;

            foreach (PoppedMessage resultDatum in context.ResultData)
            {
                stringBuilder.Append(string.Format("[{0}],", resultDatum.ToString()));
                num++;
            }
            IStringDataEventStream verboseDebug = Logger <IRestProtocolHeadLogger> .Instance.VerboseDebug;

            object[] str = new object[] { num, stringBuilder.ToString() };
            verboseDebug.Log("GetMessages response: Count={0} Messages={1}", str);
        }
Exemplo n.º 24
0
        private IEnumerator <IAsyncResult> BreakLeaseImpl(TimeSpan?leaseBreakPeriod, IBlobObjectCondition condition, AsyncIteratorContext <NoResults> context)
        {
            IAsyncResult asyncResult;

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

            try
            {
                this.blob.EndBreakLease(asyncResult);
            }
            catch (Exception exception1)
            {
                StorageStamp.TranslateException(exception1);
                throw;
            }
        }
Exemplo n.º 25
0
        private IEnumerator <IAsyncResult> GetQueueImpl(IAccountIdentifier identity, string account, string queue, PermissionLevel permission, SASAuthorizationParameters sasParams, ContainerPropertyNames propertyNames, TimeSpan timeout, RequestContext requestContext, AsyncIteratorContext <IQueueContainer> context)
        {
            RemainingTime remainingTime = new RemainingTime(timeout);
            IAsyncResult  asyncResult   = this.authorizationManager.BeginCheckAccess(identity, account, null, null, permission, sasParams, remainingTime, context.GetResumeCallback(), context.GetResumeState("QueueManager.GetQueueImpl"));

            yield return(asyncResult);

            this.authorizationManager.EndCheckAccess(asyncResult);
            IStorageAccount storageAccount = this.storageManager.CreateAccountInstance(account);
            IQueueContainer queueContainer = storageAccount.CreateQueueContainerInstance(queue);

            queueContainer.Timeout = remainingTime;
            asyncResult            = queueContainer.BeginGetProperties(propertyNames, null, context.GetResumeCallback(), context.GetResumeState("QueueManager.GetQueueImpl"));
            yield return(asyncResult);

            queueContainer.EndGetProperties(asyncResult);
            context.ResultData = queueContainer;
        }
Exemplo n.º 26
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;
            }
        }
Exemplo n.º 27
0
        protected override IEnumerator <IAsyncResult> GetQueueServiceStatsImpl(IAccountIdentifier identifier, string ownerAccountName, TimeSpan timeout, RequestContext requestContext, AsyncIteratorContext <GeoReplicationStats> context)
        {
            Duration startingNow = Duration.StartingNow;

            if (identifier == null)
            {
                throw new ArgumentNullException("identifier");
            }
            if (string.IsNullOrEmpty(ownerAccountName))
            {
                throw new ArgumentException("ownerAccountName", "Cannot be null");
            }
            if (timeout <= TimeSpan.Zero)
            {
                throw new TimeoutException("Timed out in GetQueueServiceStats");
            }
            SASAuthorizationParameters sASAuthorizationParameter = new SASAuthorizationParameters()
            {
                SupportedSasTypes  = SasType.AccountSas,
                SignedResourceType = SasResourceType.Service,
                SignedPermission   = SASPermission.Read
            };
            SASAuthorizationParameters sASAuthorizationParameter1 = sASAuthorizationParameter;
            IAsyncResult asyncResult = this.authorizationManager.BeginCheckAccess(identifier, ownerAccountName, null, null, PermissionLevel.Read | PermissionLevel.Owner, sASAuthorizationParameter1, timeout, context.GetResumeCallback(), context.GetResumeState("RealQueueManager.GetQueueServiceStatsImpl"));

            yield return(asyncResult);

            this.authorizationManager.EndCheckAccess(asyncResult);
            IStorageAccount storageAccount = this.storageManager.CreateAccountInstance(ownerAccountName);

            storageAccount.Timeout = timeout;
            AccountCondition accountCondition = new AccountCondition(false, false, storageAccount.LastModificationTime, null);

            asyncResult = storageAccount.BeginGetProperties(new AccountPropertyNames(AccountLevelPropertyNames.None, (AccountServiceMetadataPropertyNames)((long)1073741824)), accountCondition, context.GetResumeCallback(), context.GetResumeState("RealQueueManager.GetQueueServiceStatsImpl"));
            yield return(asyncResult);

            storageAccount.EndGetProperties(asyncResult);
            context.ResultData = storageAccount.ServiceMetadata.QueueGeoReplicationStats;
        }
Exemplo n.º 28
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;
            }
        }
Exemplo n.º 29
0
        protected override IEnumerator <IAsyncResult> ListQueuesImpl(IAccountIdentifier identity, string account, string queuePrefix, string delimiter, string marker, int maxResults, TimeSpan?timeout, RequestContext requestContext, AsyncIteratorContext <IListQueuesResultCollection> context)
        {
            RemainingTime remainingTime = new RemainingTime(timeout);
            SASAuthorizationParameters sASAuthorizationParameter = new SASAuthorizationParameters()
            {
                SupportedSasTypes  = SasType.AccountSas,
                SignedResourceType = SasResourceType.Service,
                SignedPermission   = SASPermission.List
            };
            SASAuthorizationParameters sASAuthorizationParameter1 = sASAuthorizationParameter;
            IAsyncResult asyncResult = this.authorizationManager.BeginCheckAccess(identity, account, null, null, PermissionLevel.Read, sASAuthorizationParameter1, remainingTime, context.GetResumeCallback(), context.GetResumeState("QueueManager.ListQueuesImpl"));

            yield return(asyncResult);

            this.authorizationManager.EndCheckAccess(asyncResult);
            IStorageAccount storageAccount = this.storageManager.CreateAccountInstance(account);

            storageAccount.Timeout = remainingTime;
            asyncResult            = storageAccount.BeginListQueueContainers(queuePrefix, ContainerPropertyNames.ApplicationMetadata, delimiter, marker, null, maxResults, context.GetResumeCallback(), context.GetResumeState("QueueManager.ListQueuesImpl"));
            yield return(asyncResult);

            context.ResultData = new ListQueuesResult(storageAccount.EndListQueueContainers(asyncResult));
        }
Exemplo n.º 30
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);
        }