예제 #1
0
        protected override IEnumerator <IAsyncResult> SetQueueMetadataImpl(IAccountIdentifier identity, string account, string queue, NameValueCollection metadata, TimeSpan?timeout, RequestContext requestContext, AsyncIteratorContext <NoResults> context)
        {
            RemainingTime remainingTime = new RemainingTime(timeout);
            SASAuthorizationParameters sASAuthorizationParameter = new SASAuthorizationParameters()
            {
                SupportedSasTypes  = SasType.AccountSas,
                SignedResourceType = SasResourceType.Container,
                SignedPermission   = SASPermission.Write
            };
            SASAuthorizationParameters sASAuthorizationParameter1 = sASAuthorizationParameter;
            IAsyncResult asyncResult = this.BeginGetQueue(identity, account, queue, PermissionLevel.Write, sASAuthorizationParameter1, remainingTime, requestContext, context.GetResumeCallback(), context.GetResumeState("QueueManager.SetQueueMetadataImpl"));

            yield return(asyncResult);

            IQueueContainer operationStatus = this.EndGetQueue(asyncResult);

            if (requestContext != null)
            {
                operationStatus.OperationStatus = requestContext.OperationStatus;
            }
            operationStatus.ApplicationMetadata = QueueHelpers.SerializeMetadata(metadata);
            operationStatus.Timeout             = remainingTime;
            asyncResult = operationStatus.BeginSetProperties(ContainerPropertyNames.ApplicationMetadata, null, context.GetResumeCallback(), context.GetResumeState("QueueManager.SetQueueMetadataImpl"));
            yield return(asyncResult);

            operationStatus.EndSetProperties(asyncResult);
        }
예제 #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);
        }
예제 #3
0
 public static NameValueCollection DeserializeMetadata(byte[] data)
 {
     if (data == null || (int)data.Length <= 0)
     {
         return(new NameValueCollection());
     }
     return(QueueHelpers.StringToMetadata(Encoding.Unicode.GetString(data)));
 }
예제 #4
0
 public ListQueuesResultQueueProperties(IQueueContainer queue)
 {
     if (queue == null)
     {
         throw new ArgumentNullException("queue");
     }
     this.queueName = queue.ContainerName;
     if (queue.ApplicationMetadata != null)
     {
         this.metadata = QueueHelpers.DeserializeMetadata(queue.ApplicationMetadata);
     }
 }
예제 #5
0
 public static byte[] SerializeMetadata(NameValueCollection metadata)
 {
     return(Encoding.Unicode.GetBytes(QueueHelpers.MetadataToString(metadata)));
 }
예제 #6
0
 public static bool IsMetadataSame(NameValueCollection m1, NameValueCollection m2)
 {
     return(QueueHelpers.MetadataToString(m1) == QueueHelpers.MetadataToString(m2));
 }
예제 #7
0
        protected override IEnumerator <IAsyncResult> CreateQueueImpl(IAccountIdentifier identity, string account, string queue, long defaultMessageTtl, long defaultMessageVisibilityTimeout, NameValueCollection metadata, TimeSpan?timeout, RequestContext requestContext, AsyncIteratorContext <CreateQueueResult> context)
        {
            RemainingTime        remainingTime  = new RemainingTime(timeout);
            List <SASPermission> sASPermissions = new List <SASPermission>()
            {
                SASPermission.Write,
                SASPermission.Create
            };
            SASAuthorizationParameters sASAuthorizationParameter = this.authorizationManager.CheckAccessWithMultiplePermissions(identity, account, null, null, PermissionLevel.Write, SasType.AccountSas, SasResourceType.Container, sASPermissions, remainingTime);

            if (metadata == null)
            {
                metadata = new NameValueCollection();
            }
            IStorageAccount storageAccount = this.storageManager.CreateAccountInstance(account);
            IAsyncResult    asyncResult    = base.BeginGetQueueProperties(identity, account, queue, false, sASAuthorizationParameter, new TimeSpan?(remainingTime), requestContext, context.GetResumeCallback(), context.GetResumeState("QueueManager.CreateQueueImpl"));

            yield return(asyncResult);

            QueueProperties queueProperty = null;
            bool            flag          = true;

            try
            {
                queueProperty = base.EndGetQueueProperties(asyncResult);
            }
            catch (ContainerNotFoundException containerNotFoundException)
            {
                flag = false;
            }
            if (!flag)
            {
                Logger <IRestProtocolHeadLogger> .Instance.Info.Log("Contacting XAC Server in order to create the queue");

                storageAccount.Timeout = remainingTime;
                DateTime?nullable = null;
                asyncResult = storageAccount.BeginCreateQueueContainer(queue, nullable, null, QueueHelpers.SerializeMetadata(metadata), context.GetResumeCallback(), context.GetResumeState("QueueManager.CreateQueueImpl"));
                yield return(asyncResult);

                bool flag1 = false;
                try
                {
                    storageAccount.EndCreateQueueContainer(asyncResult);
                }
                catch (ContainerAlreadyExistsException containerAlreadyExistsException)
                {
                    flag1 = true;
                }
                if (flag1)
                {
                    flag        = true;
                    asyncResult = base.BeginGetQueueProperties(identity, account, queue, false, new TimeSpan?(remainingTime), requestContext, context.GetResumeCallback(), context.GetResumeState("QueueManager.CreateQueueImpl"));
                    try
                    {
                        queueProperty = base.EndGetQueueProperties(asyncResult);
                    }
                    catch (ContainerNotFoundException containerNotFoundException1)
                    {
                        flag = false;
                    }
                    if (flag)
                    {
                        if (!QueueHelpers.IsMetadataSame(queueProperty.Metadata, metadata))
                        {
                            throw new ContainerAlreadyExistsException(string.Concat("Queue '", queue, "' already exists, and the metadata is different."));
                        }
                        context.ResultData = CreateQueueResult.AlreadyExists;
                    }
                }
            }
            else
            {
                Logger <IRestProtocolHeadLogger> .Instance.Info.Log("Queue already exists no need to contact XAC Server.");

                if (!QueueHelpers.IsMetadataSame(queueProperty.Metadata, metadata))
                {
                    throw new ContainerAlreadyExistsException(string.Concat("Queue '", queue, "' already exists, and the metadata is different."));
                }
                context.ResultData = CreateQueueResult.AlreadyExists;
            }
        }