Пример #1
0
        /// <summary>
        /// Generates a task sequence for getting the properties of the queue service.
        /// </summary>
        /// <param name="setResult">A delegate to receive the service properties.</param>
        /// <returns>A task sequence that gets the properties of the queue service.</returns>
        private TaskSequence GetServicePropertiesImpl(Action <ServiceProperties> setResult)
        {
            HttpWebRequest request = QueueRequest.GetServiceProperties(this.BaseUri, this.Timeout.RoundUpToSeconds());

            CommonUtils.ApplyRequestOptimizations(request, -1);
            this.Credentials.SignRequest(request);

            // Get the web response.
            Task <WebResponse> responseTask = request.GetResponseAsyncWithTimeout(this, this.Timeout);

            yield return(responseTask);

            using (HttpWebResponse response = responseTask.Result as HttpWebResponse)
                using (Stream responseStream = response.GetResponseStream())
                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        // Download the service properties.
                        Task <NullTaskReturn> downloadTask = new InvokeTaskSequenceTask(() => { return(responseStream.WriteTo(memoryStream)); });
                        yield return(downloadTask);

                        // Materialize any exceptions.
                        NullTaskReturn scratch = downloadTask.Result;

                        // Get the result from the memory stream.
                        memoryStream.Seek(0, SeekOrigin.Begin);
                        setResult(QueueResponse.ReadServiceProperties(memoryStream));
                    }
        }
        /// <summary>
        /// Generates a task sequence for setting the properties of the queue service.
        /// </summary>
        /// <param name="properties">The queue service properties to set.</param>
        /// <returns>A task sequence that sets the properties of the queue service.</returns>
        private TaskSequence SetServicePropertiesImpl(ServiceProperties properties)
        {
            CommonUtils.AssertNotNull("properties", properties);

            HttpWebRequest request = QueueRequest.SetServiceProperties(this.BaseUri, this.Timeout.RoundUpToSeconds());

            using (MemoryStream memoryStream = new MemoryStream())
            {
                try
                {
                    QueueRequest.WriteServiceProperties(properties, memoryStream);
                }
                catch (InvalidOperationException invalidOpException)
                {
                    throw new ArgumentException(invalidOpException.Message, "properties");
                }

                memoryStream.Seek(0, SeekOrigin.Begin);
                CommonUtils.ApplyRequestOptimizations(request, memoryStream.Length);
                this.Credentials.SignRequest(request);

                // Get the request stream
                Task <Stream> getStreamTask = request.GetRequestStreamAsync();
                yield return(getStreamTask);

                using (Stream requestStream = getStreamTask.Result)
                {
                    // Upload the service properties.
                    Task <NullTaskReturn> uploadTask = new InvokeTaskSequenceTask(() => { return((memoryStream as Stream).WriteTo(requestStream)); });
                    yield return(uploadTask);

                    // Materialize any exceptions.
                    NullTaskReturn scratch = uploadTask.Result;
                    Console.WriteLine(scratch);
                }
            }

            // Get the web response.
            Task <WebResponse> responseTask = request.GetResponseAsyncWithTimeout(this, this.Timeout);

            yield return(responseTask);

            // Materialize any exceptions.
            using (HttpWebResponse response = responseTask.Result as HttpWebResponse)
            {
            }
        }