/// <summary>
 /// The <see cref="SetPropertiesInternal"/> operation sets properties for
 /// a storage account’s File service endpoint, including properties
 /// for Storage Analytics, CORS (Cross-Origin Resource Sharing) rules
 /// and soft delete settings.  You can also use this operation to set
 /// the default request version for all incoming requests to the File
 /// service that do not have a version specified.
 ///
 /// For more information, see <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/set-file-service-properties"/>.
 /// </summary>
 /// <param name="properties">The file service properties.</param>
 /// <param name="async">
 /// Whether to invoke the operation asynchronously.
 /// </param>
 /// <param name="cancellationToken">
 /// Optional <see cref="CancellationToken"/> to propagate
 /// notifications that the operation should be cancelled.
 /// </param>
 /// <returns>
 /// A <see cref="Response"/> if the operation was successful.
 /// </returns>
 /// <remarks>
 /// A <see cref="RequestFailedException"/> will be thrown if
 /// a failure occurs.
 /// </remarks>
 private async Task <Response> SetPropertiesInternal(
     ShareServiceProperties properties,
     bool async,
     CancellationToken cancellationToken)
 {
     using (Pipeline.BeginLoggingScope(nameof(ShareServiceClient)))
     {
         Pipeline.LogMethodEnter(
             nameof(ShareServiceClient),
             message: $"{nameof(Uri)}: {Uri}");
         try
         {
             return(await FileRestClient.Service.SetPropertiesAsync(
                        ClientDiagnostics,
                        Pipeline,
                        Uri,
                        version : Version.ToVersionString(),
                        properties : properties,
                        async : async,
                        operationName : $"{nameof(ShareServiceClient)}.{nameof(SetProperties)}",
                        cancellationToken : cancellationToken)
                    .ConfigureAwait(false));
         }
         catch (Exception ex)
         {
             Pipeline.LogException(ex);
             throw;
         }
         finally
         {
             Pipeline.LogMethodExit(nameof(ShareServiceClient));
         }
     }
 }
Пример #2
0
        internal HttpMessage CreateSetPropertiesRequest(ShareServiceProperties storageServiceProperties, int?timeout)
        {
            var message = _pipeline.CreateMessage();
            var request = message.Request;

            request.Method = RequestMethod.Put;
            var uri = new RawRequestUriBuilder();

            uri.AppendRaw(url, false);
            uri.AppendPath("/", false);
            uri.AppendQuery("restype", "service", true);
            uri.AppendQuery("comp", "properties", true);
            if (timeout != null)
            {
                uri.AppendQuery("timeout", timeout.Value, true);
            }
            request.Uri = uri;
            request.Headers.Add("x-ms-version", version);
            request.Headers.Add("Accept", "application/xml");
            request.Headers.Add("Content-Type", "application/xml");
            var content = new XmlWriterContent();

            content.XmlWriter.WriteObjectValue(storageServiceProperties, "StorageServiceProperties");
            request.Content = content;
            return(message);
        }
 /// <summary>
 /// The <see cref="SetPropertiesAsync"/> operation sets properties for
 /// a storage account’s File service endpoint, including properties
 /// for Storage Analytics, CORS (Cross-Origin Resource Sharing) rules
 /// and soft delete settings.  You can also use this operation to set
 /// the default request version for all incoming requests to the File
 /// service that do not have a version specified.
 ///
 /// For more information, see <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/set-file-service-properties"/>.
 /// </summary>
 /// <param name="properties">The file service properties.</param>
 /// <param name="cancellationToken">
 /// Optional <see cref="CancellationToken"/> to propagate
 /// notifications that the operation should be cancelled.
 /// </param>
 /// <returns>
 /// A <see cref="Response"/> if the operation was successful.
 /// </returns>
 /// <remarks>
 /// A <see cref="RequestFailedException"/> will be thrown if
 /// a failure occurs.
 /// </remarks>
 public virtual async Task <Response> SetPropertiesAsync(
     ShareServiceProperties properties,
     CancellationToken cancellationToken = default) =>
 await SetPropertiesInternal(
     properties,
     true,     // async
     cancellationToken)
 .ConfigureAwait(false);
 /// <summary>
 /// The <see cref="SetProperties"/> operation sets properties for
 /// a storage account’s File service endpoint, including properties
 /// for Storage Analytics, CORS (Cross-Origin Resource Sharing) rules
 /// and soft delete settings.  You can also use this operation to set
 /// the default request version for all incoming requests to the File
 /// service that do not have a version specified.
 ///
 /// For more information, see <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/set-file-service-properties"/>.
 /// </summary>
 /// <param name="properties">The file service properties.</param>
 /// <param name="cancellationToken">
 /// Optional <see cref="CancellationToken"/> to propagate
 /// notifications that the operation should be cancelled.
 /// </param>
 /// <returns>
 /// A <see cref="Response"/> if the operation was successful.
 /// </returns>
 /// <remarks>
 /// A <see cref="RequestFailedException"/> will be thrown if
 /// a failure occurs.
 /// </remarks>
 public virtual Response SetProperties(
     ShareServiceProperties properties,
     CancellationToken cancellationToken = default) =>
 SetPropertiesInternal(
     properties,
     false,     // async
     cancellationToken)
 .EnsureCompleted();
Пример #5
0
        // </snippet_DeleteSnapshot>

        // <snippet_UseMetrics>
        //-------------------------------------------------
        // Use metrics
        //-------------------------------------------------
        public async Task UseMetricsAsync()
        {
            // Get the connection string from app settings
            string connectionString = ConfigurationManager.AppSettings["StorageConnectionString"];

            // Instatiate a ShareServiceClient
            ShareServiceClient shareService = new ShareServiceClient(connectionString);

            // Set metrics properties for File service
            await shareService.SetPropertiesAsync(new ShareServiceProperties()
            {
                // Set hour metrics
                HourMetrics = new ShareMetrics()
                {
                    Enabled     = true,
                    IncludeApis = true,
                    Version     = "1.0",

                    RetentionPolicy = new ShareRetentionPolicy()
                    {
                        Enabled = true,
                        Days    = 14
                    }
                },

                // Set minute metrics
                MinuteMetrics = new ShareMetrics()
                {
                    Enabled     = true,
                    IncludeApis = true,
                    Version     = "1.0",

                    RetentionPolicy = new ShareRetentionPolicy()
                    {
                        Enabled = true,
                        Days    = 7
                    }
                }
            });

            // Read the metrics properties we just set
            ShareServiceProperties serviceProperties = await shareService.GetPropertiesAsync();

            // Display the properties
            Console.WriteLine();
            Console.WriteLine($"HourMetrics.InludeApis: {serviceProperties.HourMetrics.IncludeApis}");
            Console.WriteLine($"HourMetrics.RetentionPolicy.Days: {serviceProperties.HourMetrics.RetentionPolicy.Days}");
            Console.WriteLine($"HourMetrics.Version: {serviceProperties.HourMetrics.Version}");
            Console.WriteLine();
            Console.WriteLine($"MinuteMetrics.InludeApis: {serviceProperties.MinuteMetrics.IncludeApis}");
            Console.WriteLine($"MinuteMetrics.RetentionPolicy.Days: {serviceProperties.MinuteMetrics.RetentionPolicy.Days}");
            Console.WriteLine($"MinuteMetrics.Version: {serviceProperties.MinuteMetrics.Version}");
            Console.WriteLine();
        }
        /// <summary>
        /// Query the Cross-Origin Resource Sharing (CORS) rules for the File service
        /// </summary>
        /// <param name="shareServiceClient"></param>
        private static async Task CorsSample(ShareServiceClient shareServiceClient)
        {
            Console.WriteLine();

            // Get service properties
            Console.WriteLine("Get service properties");
            ShareServiceProperties originalProperties = await shareServiceClient.GetPropertiesAsync();

            try
            {
                // Add CORS rule
                Console.WriteLine("Add CORS rule");

                var corsRule = new ShareCorsRule
                {
                    AllowedHeaders  = "*",
                    AllowedMethods  = "GET",
                    AllowedOrigins  = "*",
                    ExposedHeaders  = "*",
                    MaxAgeInSeconds = 3600
                };

                ShareServiceProperties serviceProperties = await shareServiceClient.GetPropertiesAsync();

                serviceProperties.Cors.Clear();
                serviceProperties.Cors.Add(corsRule);

                await shareServiceClient.SetPropertiesAsync(serviceProperties);

                Console.WriteLine("Set property successfully");
            }
            finally
            {
                // Revert back to original service properties
                Console.WriteLine("Revert back to original service properties");
                await shareServiceClient.SetPropertiesAsync(originalProperties);

                Console.WriteLine("Revert properties successfully.");
            }

            Console.WriteLine();
        }
Пример #7
0
        public ResponseWithHeaders <ServiceSetPropertiesHeaders> SetProperties(ShareServiceProperties storageServiceProperties, int?timeout = null, CancellationToken cancellationToken = default)
        {
            if (storageServiceProperties == null)
            {
                throw new ArgumentNullException(nameof(storageServiceProperties));
            }

            using var message = CreateSetPropertiesRequest(storageServiceProperties, timeout);
            _pipeline.Send(message, cancellationToken);
            var headers = new ServiceSetPropertiesHeaders(message.Response);

            switch (message.Response.Status)
            {
            case 202:
                return(ResponseWithHeaders.FromValue(headers, message.Response));

            default:
                throw _clientDiagnostics.CreateRequestFailedException(message.Response);
            }
        }
Пример #8
0
        public ResponseWithHeaders <ShareServiceProperties, ServiceGetPropertiesHeaders> GetProperties(int?timeout = null, CancellationToken cancellationToken = default)
        {
            using var message = CreateGetPropertiesRequest(timeout);
            _pipeline.Send(message, cancellationToken);
            var headers = new ServiceGetPropertiesHeaders(message.Response);

            switch (message.Response.Status)
            {
            case 200:
            {
                ShareServiceProperties value = default;
                var document = XDocument.Load(message.Response.ContentStream, LoadOptions.PreserveWhitespace);
                if (document.Element("StorageServiceProperties") is XElement storageServicePropertiesElement)
                {
                    value = ShareServiceProperties.DeserializeShareServiceProperties(storageServicePropertiesElement);
                }
                return(ResponseWithHeaders.FromValue(value, headers, message.Response));
            }

            default:
                throw _clientDiagnostics.CreateRequestFailedException(message.Response);
            }
        }