/// <summary>
        /// Constructs a <c>ServiceProperties</c> object from an XML document received from the service.
        /// </summary>
        /// <param name="servicePropertiesDocument">
        /// The XML document. 
        /// </param>
        /// <returns>
        /// A <c>ServiceProperties</c> object containing the properties in the XML document. 
        /// </returns>
        internal static ServiceProperties FromServiceXml(XDocument servicePropertiesDocument)
        {
            var servicePropertiesElement = servicePropertiesDocument.Element(StorageServicePropertiesName);
            Debug.Assert(servicePropertiesElement != null, "servicePropertiesElement != null");
            var properties = new ServiceProperties
                {
                    Logging = ReadLoggingPropertiesFromXml(servicePropertiesElement.Element(LoggingName)),
                    Metrics = ReadMetricsPropertiesFromXml(servicePropertiesElement.Element(MetricsName))
                };

            var defaultServiceVersionXml = servicePropertiesElement.Element(DefaultServiceVersionName);
            if (defaultServiceVersionXml != null)
            {
                properties.DefaultServiceVersion = defaultServiceVersionXml.Value;
            }

            return properties;
        }
Example #2
0
        /// <summary>
        ///   Writes service properties to a stream, formatted in XML.
        /// </summary>
        /// <param name="properties"> The service properties to format and write to the stream. </param>
        /// <param name="outputStream"> The stream to which the formatted properties are to be written. </param>
        internal static void WriteServiceProperties(ServiceProperties properties, Stream outputStream)
        {
            var propertiesDocument = properties.ToServiceXml();
            var settings = new XmlWriterSettings
                { Encoding = Encoding.UTF8, NewLineHandling = NewLineHandling.Entitize };

            using (var writer = XmlWriter.Create(outputStream, settings))
            {
                propertiesDocument.Save(writer);
                writer.Close();
            }
        }
 /// <summary>
 /// Writes service properties to a stream, formatted in XML.
 /// </summary>
 /// <param name="properties">The service properties to format and write to the stream.</param>
 /// <param name="outputStream">The stream to which the formatted properties are to be written.</param>
 public static void WriteServiceProperties(ServiceProperties properties, Stream outputStream)
 {
     Request.WriteServiceProperties(properties, outputStream);
 }
        /// <summary>Generates a task sequence for setting the properties of the blob service.</summary>
        /// <param name="properties">The blob service properties to set. </param>
        /// <returns>A task sequence that sets the properties of the blob service. </returns>
        private TaskSequence SetServicePropertiesImpl(ServiceProperties properties)
        {
            CommonUtils.AssertNotNull("properties", properties);

            var request = BlobRequest.SetServiceProperties(this.BaseUri, this.Timeout.RoundUpToSeconds());
            using (var memoryStream = new MemoryStream())
            {
                try
                {
                    BlobRequest.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
                var getStreamTask = request.GetRequestStreamAsync();
                yield return getStreamTask;

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

                    // Materialize any exceptions.
                    var scratch = uploadTask.Result;
                }
            }

            // Get the web response.
            var responseTask = request.GetResponseAsyncWithTimeout(this, this.Timeout);
            yield return responseTask;

            // Materialize any exceptions.
            using (var response = responseTask.Result as HttpWebResponse)
            {
            }
        }
        /// <summary>
        /// Constructs a <c>ServiceProperties</c> object from an XML document received from the service.
        /// </summary>
        /// <param name="servicePropertiesDocument">The XML document.</param>
        /// <returns>A <c>ServiceProperties</c> object containing the properties in the XML document.</returns>
        internal static ServiceProperties FromServiceXml(XDocument servicePropertiesDocument)
        {
            XElement servicePropertiesElement = servicePropertiesDocument.Element(StorageServicePropertiesName);
            ServiceProperties properties = new ServiceProperties()
            {
                Logging = ReadLoggingPropertiesFromXml(servicePropertiesElement.Element(LoggingName)),
                Metrics = ReadMetricsPropertiesFromXml(servicePropertiesElement.Element(MetricsName))
            };

            XElement defaultServiceVersionXml = servicePropertiesElement.Element(DefaultServiceVersionName);
            if (defaultServiceVersionXml != null)
            {
                properties.DefaultServiceVersion = defaultServiceVersionXml.Value;
            }

            return properties;
        }
 /// <summary>Sets the properties of the blob service.</summary>
 /// <param name="properties">The blob service properties. </param>
 public void SetServiceProperties(ServiceProperties properties)
 {
     TaskImplHelper.ExecuteImplWithRetry(() => this.SetServicePropertiesImpl(properties), this.RetryPolicy);
 }
 /// <summary>Begins an asynchronous operation to set the properties of the blob service.</summary>
 /// <param name="properties">The blob service properties. </param>
 /// <param name="callback">The callback delegate that will receive notification when the asynchronous operation completes. </param>
 /// <param name="state">A user defined object to be passed to the callback delegate. </param>
 /// <returns>An <see cref="IAsyncResult"/> that references the asynchronous operation. </returns>
 public IAsyncResult BeginSetServiceProperties(
     ServiceProperties properties, AsyncCallback callback, object state)
 {
     return TaskImplHelper.BeginImplWithRetry(
         () => this.SetServicePropertiesImpl(properties), this.RetryPolicy, callback, state);
 }
 public IAsyncResult BeginSetServiceProperties(ServiceProperties properties, AsyncCallback callback, object state);
 public void SetServiceProperties(ServiceProperties properties);
 /// <summary>
 /// Writes service properties to a stream, formatted in XML.
 /// </summary>
 /// <param name="properties">The service properties to format and write to the stream.</param>
 /// <param name="outputStream">The stream to which the formatted properties are to be written.</param>
 public static void WriteServiceProperties(ServiceProperties properties, Stream outputStream)
 {
     Request.WriteServiceProperties(properties, outputStream);
 }