public void ListQueues(string queuePrefix, Action<CloudOperationResponse<IEnumerable<ICloudQueue>>> callback)
        {
            var serviceOperation = string.Concat(this.queueBaseUri, "?comp=list");

            if (!string.IsNullOrWhiteSpace(queuePrefix))
            {
                serviceOperation = string.Concat(serviceOperation, "&prefix=", queuePrefix);
            }

            // Adding an incremental seed to avoid a cached response.
            serviceOperation = string.Concat(serviceOperation, "&incrementalSeed=", DateTime.UtcNow.Ticks);

            var request = (HttpWebRequest)WebRequestCreator.ClientHttp.Create(new Uri(serviceOperation));
            request.Headers["x-ms-version"] = "2009-09-19";
            request.Method = "GET";

            this.StorageCredentials.SignRequest(request, -1);
            request.BeginGetResponse(
                ar =>
                {
                    try
                    {
                            var response = (HttpWebResponse)request.EndGetResponse(ar);
                            var serializer = new QueueDataContractSerializer(this.StorageCredentials);
                            var results = serializer.ReadObject(response.GetResponseStream());

                            callback(new CloudOperationResponse<IEnumerable<ICloudQueue>>((results != null) ? results.ToArray() : new CloudQueue[0], null));
                    }
                    catch (Exception exception)
                    {
                        callback(new CloudOperationResponse<IEnumerable<ICloudQueue>>(null, StorageClientExceptionParser.ParseXmlWebException(exception as WebException) ?? exception));
                    }
                },
                null);
        }
Пример #2
0
        public void Exists(Action<CloudOperationResponse<bool>> callback)
        {
            var serviceOperation = string.Format(CultureInfo.InvariantCulture, "{0}?comp=list&prefix={1}", this.BaseUri, this.Name);

            // Adding an incremental seed to avoid a cached response.
            serviceOperation = string.Concat(serviceOperation, "&incrementalSeed=", DateTime.UtcNow.Ticks);

            var request = (HttpWebRequest)WebRequestCreator.ClientHttp.Create(new Uri(serviceOperation));
            request.Headers["x-ms-version"] = "2009-09-19";
            request.Method = "GET";

            this.StorageCredentials.SignRequest(request, -1);
            request.BeginGetResponse(
                ar =>
                {
                    try
                    {
                        var response = (HttpWebResponse)request.EndGetResponse(ar);
                        var serializer = new QueueDataContractSerializer(this.StorageCredentials);
                        var queues = serializer.ReadObject(response.GetResponseStream());
                        var result = queues.SingleOrDefault(q => q.Name.Equals(this.Name));
                        callback(new CloudOperationResponse<bool>(result != null, null));
                    }
                    catch (Exception exception)
                    {
                        callback(new CloudOperationResponse<bool>(false, StorageClientExceptionParser.ParseXmlWebException(exception as WebException) ?? exception));
                    }
                },
                null);
        }