Ejemplo n.º 1
0
        /// <summary>
        /// Set service properties
        /// </summary>
        /// <param name="account">Cloud storage account</param>
        /// <param name="type">Service type</param>
        /// <param name="properties">Service properties</param>
        /// <param name="options">Request options</param>
        /// <param name="operationContext">Operation context</param>
        public void SetStorageServiceProperties(StorageServiceType type, ServiceProperties properties, IRequestOptions options, OperationContext operationContext)
        {
            CloudStorageAccount account = StorageContext.StorageAccount;

            switch (type)
            {
            case StorageServiceType.Blob:
                account.CreateCloudBlobClient().SetServiceProperties(properties, (BlobRequestOptions)options, operationContext);
                break;

            case StorageServiceType.Queue:
                account.CreateCloudQueueClient().SetServiceProperties(properties, (QueueRequestOptions)options, operationContext);
                break;

            case StorageServiceType.Table:
                account.CreateCloudTableClient().SetServiceProperties(properties, (TableRequestOptions)options, operationContext);
                break;

            case StorageServiceType.File:
                if (null != properties.Logging)
                {
                    throw new InvalidOperationException(Resources.FileNotSupportLogging);
                }

                FileServiceProperties fileServiceProperties = new FileServiceProperties();
                fileServiceProperties.Cors          = properties.Cors;
                fileServiceProperties.HourMetrics   = properties.HourMetrics;
                fileServiceProperties.MinuteMetrics = properties.MinuteMetrics;
                account.CreateCloudFileClient().SetServiceProperties(fileServiceProperties, (FileRequestOptions)options, operationContext);
                break;

            default:
                throw new ArgumentException(Resources.InvalidStorageServiceType, "type");
            }
        }
        /// <summary>
        /// Get the service properties
        /// </summary>
        /// <param name="account">Cloud storage account</param>
        /// <param name="type">Service type</param>
        /// <param name="options">Request options</param>
        /// <param name="operationContext">Operation context</param>
        /// <returns>The service properties of the specified service type</returns>
        public XSCLProtocol.ServiceProperties GetStorageServiceProperties(StorageServiceType type, IRequestOptions options, XSCL.OperationContext operationContext)
        {
            XSCL.CloudStorageAccount account = StorageContext.StorageAccount;
            try
            {
                switch (type)
                {
                case StorageServiceType.Blob:
                    return(account.CreateCloudBlobClient().GetServicePropertiesAsync((BlobRequestOptions)options, operationContext).Result);

                case StorageServiceType.Queue:
                    return(account.CreateCloudQueueClient().GetServicePropertiesAsync((QueueRequestOptions)options, operationContext).Result);

                case StorageServiceType.File:
                    FileServiceProperties          fileServiceProperties = account.CreateCloudFileClient().GetServicePropertiesAsync((FileRequestOptions)options, operationContext).Result;
                    XSCLProtocol.ServiceProperties sp = new XSCLProtocol.ServiceProperties();
                    sp.Clean();
                    sp.Cors          = fileServiceProperties.Cors;
                    sp.HourMetrics   = fileServiceProperties.HourMetrics;
                    sp.MinuteMetrics = fileServiceProperties.MinuteMetrics;
                    return(sp);

                default:
                    throw new ArgumentException(Resources.InvalidStorageServiceType, "type");
                }
            }
            catch (AggregateException e) when(e.InnerException is XSCL.StorageException)
            {
                throw e.InnerException;
            }
        }
Ejemplo n.º 3
0
        private RESTCommand <NullType> SetServicePropertiesImpl(FileServiceProperties properties, FileRequestOptions requestOptions)
        {
            MultiBufferMemoryStream memoryStream = new MultiBufferMemoryStream(null /* bufferManager */, (int)(1 * Constants.KB));

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

            RESTCommand <NullType> retCmd = new RESTCommand <NullType>(this.Credentials, this.StorageUri, this.HttpClient);

            requestOptions.ApplyToStorageCommand(retCmd);
            retCmd.BuildRequest           = (cmd, uri, builder, cnt, serverTimeout, ctx) => FileHttpRequestMessageFactory.SetServiceProperties(uri, serverTimeout, cnt, ctx, this.GetCanonicalizer(), this.Credentials);
            retCmd.BuildContent           = (cmd, ctx) => HttpContentFactory.BuildContentFromStream(memoryStream, 0, memoryStream.Length, Checksum.None, cmd, ctx);
            retCmd.StreamToDispose        = memoryStream;
            retCmd.RetrieveResponseStream = true;
            retCmd.PreProcessResponse     =
                (cmd, resp, ex, ctx) =>
                HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.Accepted, resp, null /* retVal */, cmd, ex);
            requestOptions.ApplyToStorageCommand(retCmd);
            return(retCmd);
        }
        public virtual ICancellableAsyncResult BeginSetServiceProperties(FileServiceProperties properties, FileRequestOptions requestOptions, OperationContext operationContext, AsyncCallback callback, object state)
        {
            requestOptions   = FileRequestOptions.ApplyDefaults(requestOptions, this);
            operationContext = operationContext ?? new OperationContext();

            return(CancellableAsyncResultTaskWrapper.Create(token => this.SetServicePropertiesAsync(properties, requestOptions, operationContext), callback, state));
        }
 /// <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="StorageRequestFailedException"/> will be thrown if
 /// a failure occurs.
 /// </remarks>
 private async Task <Response> SetPropertiesInternal(
     FileServiceProperties properties,
     bool async,
     CancellationToken cancellationToken)
 {
     using (this.Pipeline.BeginLoggingScope(nameof(FileServiceClient)))
     {
         this.Pipeline.LogMethodEnter(
             nameof(FileServiceClient),
             message: $"{nameof(this.Uri)}: {this.Uri}");
         try
         {
             return(await FileRestClient.Service.SetPropertiesAsync(
                        this.Pipeline,
                        this.Uri,
                        properties : properties,
                        async : async,
                        operationName : Constants.File.Service.SetPropertiesOperationName,
                        cancellationToken : cancellationToken)
                    .ConfigureAwait(false));
         }
         catch (Exception ex)
         {
             this.Pipeline.LogException(ex);
             throw;
         }
         finally
         {
             this.Pipeline.LogMethodExit(nameof(FileServiceClient));
         }
     }
 }
Ejemplo n.º 6
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            // Check input parameter
            // ShareRetentionDays should only be specified when EnableShareDeleteRetentionPolicy is true
            if (this.enableShareDeleteRetentionPolicy == null || this.enableShareDeleteRetentionPolicy.Value == false)
            {
                if (this.ShareRetentionDays != 0)
                {
                    throw new ArgumentException("ShareRetentionDays should only be specified when EnableShareDeleteRetentionPolicy is true.");
                }
            }
            else
            {
                if (this.ShareRetentionDays == 0)
                {
                    throw new ArgumentException("ShareRetentionDays must be specified when EnableShareDeleteRetentionPolicy is true.");
                }
            }

            if (ShouldProcess("FileServiceProperties", "Update"))
            {
                switch (ParameterSetName)
                {
                case AccountObjectParameterSet:
                    this.ResourceGroupName  = StorageAccount.ResourceGroupName;
                    this.StorageAccountName = StorageAccount.StorageAccountName;
                    break;

                case PropertiesResourceIdParameterSet:
                    ResourceIdentifier blobServicePropertiesResource = new ResourceIdentifier(ResourceId);
                    this.ResourceGroupName  = blobServicePropertiesResource.ResourceGroupName;
                    this.StorageAccountName = PSBlobServiceProperties.GetStorageAccountNameFromResourceId(ResourceId);
                    break;

                default:
                    // For AccountNameParameterSet, the ResourceGroupName and StorageAccountName can get from input directly
                    break;
                }
                DeleteRetentionPolicy deleteRetentionPolicy = null;
                if (this.enableShareDeleteRetentionPolicy != null)
                {
                    deleteRetentionPolicy         = new DeleteRetentionPolicy();
                    deleteRetentionPolicy.Enabled = this.enableShareDeleteRetentionPolicy.Value;
                    if (this.enableShareDeleteRetentionPolicy.Value == true)
                    {
                        deleteRetentionPolicy.Days = ShareRetentionDays;
                    }
                }

                FileServiceProperties serviceProperties = this.StorageClient.FileServices.SetServiceProperties(this.ResourceGroupName, this.StorageAccountName,
                                                                                                               new FileServiceProperties(shareDeleteRetentionPolicy: deleteRetentionPolicy));

                // Get all File service properties from server for output
                serviceProperties = this.StorageClient.FileServices.GetServiceProperties(this.ResourceGroupName, this.StorageAccountName);

                WriteObject(new PSFileServiceProperties(serviceProperties));
            }
        }
Ejemplo n.º 7
0
 /// <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="cancellation">
 /// Optional <see cref="CancellationToken"/> to propagate
 /// notifications that the operation should be cancelled.
 /// </param>
 /// <returns>
 /// A <see cref="Task{Response}"/> if the operation was successful.
 /// </returns>
 /// <remarks>
 /// A <see cref="StorageRequestFailedException"/> will be thrown if
 /// a failure occurs.
 /// </remarks>
 public async Task <Response> SetPropertiesAsync(
     FileServiceProperties properties,
     CancellationToken cancellation = default)
 {
     using (this._pipeline.BeginLoggingScope(nameof(FileServiceClient)))
     {
         this._pipeline.LogMethodEnter(
             nameof(FileServiceClient),
             message: $"{nameof(this.Uri)}: {this.Uri}");
         try
         {
             return(await FileRestClient.Service.SetPropertiesAsync(
                        this._pipeline,
                        this.Uri,
                        properties : properties,
                        cancellation : cancellation)
                    .ConfigureAwait(false));
         }
         catch (Exception ex)
         {
             this._pipeline.LogException(ex);
             throw;
         }
         finally
         {
             this._pipeline.LogMethodExit(nameof(FileServiceClient));
         }
     }
 }
Ejemplo n.º 8
0
        internal static void AssertFileServicePropertiesAreEqual(FileServiceProperties propsA, FileServiceProperties propsB)
        {
            if (propsA.Cors != null && propsB.Cors != null)
            {
                Assert.AreEqual(propsA.Cors.CorsRules.Count, propsB.Cors.CorsRules.Count);

                // Check that rules are equal and in the same order.
                for (int i = 0; i < propsA.Cors.CorsRules.Count; i++)
                {
                    CorsRule ruleA = propsA.Cors.CorsRules.ElementAt(i);
                    CorsRule ruleB = propsB.Cors.CorsRules.ElementAt(i);

                    Assert.IsTrue(
                        ruleA.AllowedOrigins.Count == ruleB.AllowedOrigins.Count &&
                        !ruleA.AllowedOrigins.Except(ruleB.AllowedOrigins).Any());

                    Assert.IsTrue(
                        ruleA.ExposedHeaders.Count == ruleB.ExposedHeaders.Count &&
                        !ruleA.ExposedHeaders.Except(ruleB.ExposedHeaders).Any());

                    Assert.IsTrue(
                        ruleA.AllowedHeaders.Count == ruleB.AllowedHeaders.Count &&
                        !ruleA.AllowedHeaders.Except(ruleB.AllowedHeaders).Any());

                    Assert.IsTrue(ruleA.AllowedMethods == ruleB.AllowedMethods);

                    Assert.IsTrue(ruleA.MaxAgeInSeconds == ruleB.MaxAgeInSeconds);
                }
            }
            else
            {
                Assert.IsNull(propsA.Cors);
                Assert.IsNull(propsB.Cors);
            }
        }
Ejemplo n.º 9
0
        private RESTCommand <NullType> SetServicePropertiesImpl(FileServiceProperties properties, FileRequestOptions requestOptions)
        {
            MultiBufferMemoryStream str = new MultiBufferMemoryStream(null /* bufferManager */, (int)(1 * Constants.KB));

            try
            {
                properties.WriteServiceProperties(str);
            }
            catch (InvalidOperationException invalidOpException)
            {
                str.Dispose();
                throw new ArgumentException(invalidOpException.Message, "properties");
            }

            str.Seek(0, SeekOrigin.Begin);

            RESTCommand <NullType> retCmd = new RESTCommand <NullType>(this.Credentials, this.StorageUri);

            retCmd.SendStream           = str;
            retCmd.StreamToDispose      = str;
            retCmd.BuildRequestDelegate = FileHttpWebRequestFactory.SetServiceProperties;
            retCmd.RecoveryAction       = RecoveryActions.RewindStream;
            retCmd.SignRequest          = this.AuthenticationHandler.SignRequest;
            retCmd.PreProcessResponse   =
                (cmd, resp, ex, ctx) =>
                HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.Accepted, resp, NullType.Value, cmd, ex);
            requestOptions.ApplyToStorageCommand(retCmd);
            return(retCmd);
        }
Ejemplo n.º 10
0
        public static void SetSerivceProperties(Constants.ServiceType serviceType, Microsoft.WindowsAzure.Storage.Shared.Protocol.ServiceProperties serviceProperties)
        {
            switch (serviceType)
            {
            case Constants.ServiceType.Blob:
                StorageAccount.CreateCloudBlobClient().SetServiceProperties(serviceProperties);
                break;

            case Constants.ServiceType.Queue:
                StorageAccount.CreateCloudQueueClient().SetServiceProperties(serviceProperties);
                break;

            case Constants.ServiceType.Table:
                StorageAccount.CreateCloudTableClient().SetServiceProperties(serviceProperties);
                break;

            case Constants.ServiceType.File:
                FileServiceProperties fileProperties = new FileServiceProperties();
                fileProperties.Cors          = serviceProperties.Cors;
                fileProperties.HourMetrics   = serviceProperties.HourMetrics;
                fileProperties.MinuteMetrics = serviceProperties.MinuteMetrics;
                StorageAccount.CreateCloudFileClient().SetServiceProperties(fileProperties);
                break;
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Get the service properties
        /// </summary>
        /// <param name="account">Cloud storage account</param>
        /// <param name="type">Service type</param>
        /// <param name="options">Request options</param>
        /// <param name="operationContext">Operation context</param>
        /// <returns>The service properties of the specified service type</returns>
        public ServiceProperties GetStorageServiceProperties(StorageServiceType type, IRequestOptions options, OperationContext operationContext)
        {
            CloudStorageAccount account = StorageContext.StorageAccount;

            switch (type)
            {
            case StorageServiceType.Blob:
                return(account.CreateCloudBlobClient().GetServiceProperties((BlobRequestOptions)options, operationContext));

            case StorageServiceType.Queue:
                return(account.CreateCloudQueueClient().GetServiceProperties((QueueRequestOptions)options, operationContext));

            case StorageServiceType.Table:
                return(account.CreateCloudTableClient().GetServiceProperties((TableRequestOptions)options, operationContext));

            case StorageServiceType.File:
                FileServiceProperties fileServiceProperties = account.CreateCloudFileClient().GetServiceProperties((FileRequestOptions)options, operationContext);
                ServiceProperties     sp = new ServiceProperties();
                sp.Clean();
                sp.Cors          = fileServiceProperties.Cors;
                sp.HourMetrics   = fileServiceProperties.HourMetrics;
                sp.MinuteMetrics = fileServiceProperties.MinuteMetrics;
                return(sp);

            default:
                throw new ArgumentException(Resources.InvalidStorageServiceType, "type");
            }
        }
Ejemplo n.º 12
0
        public void CloudFileTestAnalyticsRoundTripAPM()
        {
            props.Cors.CorsRules.Add(
                new CorsRule()
            {
                AllowedOrigins = new List <string>()
                {
                    "www.ab.com", "www.bc.com"
                },
                AllowedMethods  = CorsHttpMethods.Get | CorsHttpMethods.Put,
                MaxAgeInSeconds = 500,
                ExposedHeaders  =
                    new List <string>()
                {
                    "x-ms-meta-data*",
                    "x-ms-meta-source*",
                    "x-ms-meta-abc",
                    "x-ms-meta-bcd"
                },
                AllowedHeaders =
                    new List <string>()
                {
                    "x-ms-meta-data*",
                    "x-ms-meta-target*",
                    "x-ms-meta-xyz",
                    "x-ms-meta-foo"
                }
            });

            using (ManualResetEvent evt = new ManualResetEvent(false))
            {
                IAsyncResult result = null;
                client.BeginSetServiceProperties(props, (res) =>
                {
                    result = res;
                    evt.Set();
                }, null);
                evt.WaitOne();

                client.EndSetServiceProperties(result);
            }

            FileServiceProperties retrievedProps = null;

            using (ManualResetEvent evt = new ManualResetEvent(false))
            {
                IAsyncResult result = null;
                client.BeginGetServiceProperties((res) =>
                {
                    result = res;
                    evt.Set();
                }, null);
                evt.WaitOne();

                retrievedProps = client.EndGetServiceProperties(result);
            }

            TestHelper.AssertFileServicePropertiesAreEqual(props, retrievedProps);
        }
Ejemplo n.º 13
0
 /// <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="StorageRequestFailedException"/> will be thrown if
 /// a failure occurs.
 /// </remarks>
 public virtual async Task <Response> SetPropertiesAsync(
     FileServiceProperties properties,
     CancellationToken cancellationToken = default) =>
 await this.SetPropertiesInternal(
     properties,
     true,     // async
     cancellationToken)
 .ConfigureAwait(false);
Ejemplo n.º 14
0
 /// <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="StorageRequestFailedException"/> will be thrown if
 /// a failure occurs.
 /// </remarks>
 public virtual Response SetProperties(
     FileServiceProperties properties,
     CancellationToken cancellationToken = default) =>
 this.SetPropertiesInternal(
     properties,
     false,     // async
     cancellationToken)
 .EnsureCompleted();
Ejemplo n.º 15
0
        private static FileServiceProperties DefaultServiceProperties()
        {
            FileServiceProperties props = new FileServiceProperties();

            props.Cors.CorsRules = new List <CorsRule>();

            return(props);
        }
Ejemplo n.º 16
0
        public void MyTestInitialize()
        {
            props = DefaultServiceProperties();

            if (TestBase.FileBufferManager != null)
            {
                TestBase.FileBufferManager.OutstandingBufferCount = 0;
            }
        }
Ejemplo n.º 17
0
 public virtual void SetServiceProperties(FileServiceProperties properties, FileRequestOptions requestOptions = null, OperationContext operationContext = null)
 {
     requestOptions   = FileRequestOptions.ApplyDefaults(requestOptions, this);
     operationContext = operationContext ?? new OperationContext();
     Executor.ExecuteSync(
         this.SetServicePropertiesImpl(properties, requestOptions),
         requestOptions.RetryPolicy,
         operationContext);
 }
Ejemplo n.º 18
0
 public PSFileServiceProperties(FileServiceProperties policy)
 {
     this.ResourceGroupName  = (new ResourceIdentifier(policy.Id)).ResourceGroupName;
     this.StorageAccountName = PSBlobServiceProperties.GetStorageAccountNameFromResourceId(policy.Id);
     this.Id   = policy.Id;
     this.Name = policy.Name;
     this.Type = policy.Type;
     this.Cors = policy.Cors is null ? null : new PSCorsRules(policy.Cors);
     this.ShareDeleteRetentionPolicy = policy.ShareDeleteRetentionPolicy is null ? null : new PSDeleteRetentionPolicy(policy.ShareDeleteRetentionPolicy);
 }
 public virtual Task SetServicePropertiesAsync(FileServiceProperties properties, FileRequestOptions requestOptions, OperationContext operationContext, CancellationToken cancellationToken)
 {
     requestOptions   = FileRequestOptions.ApplyDefaults(requestOptions, this);
     operationContext = operationContext ?? new OperationContext();
     return(Executor.ExecuteAsync(
                this.SetServicePropertiesImpl(properties, requestOptions),
                requestOptions.RetryPolicy,
                operationContext,
                cancellationToken));
 }
Ejemplo n.º 20
0
        private static FileServiceProperties DefaultServiceProperties()
        {
            FileServiceProperties props = new FileServiceProperties(new MetricsProperties(), new MetricsProperties(), new CorsProperties());

            props.MinuteMetrics.Version = Constants.AnalyticsConstants.MetricsVersionV1;
            props.HourMetrics.Version   = Constants.AnalyticsConstants.MetricsVersionV1;

            props.Cors.CorsRules = new List <CorsRule>();

            return(props);
        }
Ejemplo n.º 21
0
        public virtual Task SetServicePropertiesAsync(FileServiceProperties properties, FileRequestOptions requestOptions, OperationContext operationContext, CancellationToken cancellationToken)
        {
            FileRequestOptions modifiedOptions = FileRequestOptions.ApplyDefaults(requestOptions, this);

            operationContext = operationContext ?? new OperationContext();
            return(Task.Run(async() => await Executor.ExecuteAsyncNullReturn(
                                this.SetServicePropertiesImpl(properties, modifiedOptions),
                                modifiedOptions.RetryPolicy,
                                operationContext,
                                cancellationToken), cancellationToken));
        }
Ejemplo n.º 22
0
        public IAsyncAction SetServicePropertiesAsync(FileServiceProperties properties, FileRequestOptions requestOptions, OperationContext operationContext)
        {
            FileRequestOptions modifiedOptions = FileRequestOptions.ApplyDefaults(requestOptions, this);

            operationContext = operationContext ?? new OperationContext();
            return(AsyncInfo.Run(async(token) => await Executor.ExecuteAsyncNullReturn(
                                     this.SetServicePropertiesImpl(properties, modifiedOptions),
                                     modifiedOptions.RetryPolicy,
                                     operationContext,
                                     token)));
        }
Ejemplo n.º 23
0
 public virtual ICancellableAsyncResult BeginSetServiceProperties(FileServiceProperties properties, FileRequestOptions requestOptions, OperationContext operationContext, AsyncCallback callback, object state)
 {
     requestOptions   = FileRequestOptions.ApplyDefaults(requestOptions, this);
     operationContext = operationContext ?? new OperationContext();
     return(Executor.BeginExecuteAsync(
                this.SetServicePropertiesImpl(properties, requestOptions),
                requestOptions.RetryPolicy,
                operationContext,
                callback,
                state));
 }
Ejemplo n.º 24
0
        public void FileServiceTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                var rgName = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = TestUtilities.GenerateName("sto");
                var    parameters  = new StorageAccountCreateParameters
                {
                    Sku = new Sku {
                        Name = SkuName.PremiumLRS
                    },
                    Kind     = Kind.FileStorage,
                    Location = "centraluseuap"
                };
                var account = storageMgmtClient.StorageAccounts.Create(rgName, accountName, parameters);

                // implement case
                try
                {
                    // Get after account create
                    FileServiceProperties properties1 = storageMgmtClient.FileServices.GetServiceProperties(rgName, accountName);
                    Assert.Equal(0, properties1.Cors.CorsRulesProperty.Count);

                    //Set and validated
                    FileServiceProperties properties2 = new FileServiceProperties();
                    properties2.ProtocolSettings     = new ProtocolSettings();
                    properties2.ProtocolSettings.Smb = new SmbSetting();
                    properties2.ProtocolSettings.Smb.Multichannel = new Multichannel(true);
                    FileServiceProperties properties3 = storageMgmtClient.FileServices.SetServiceProperties(rgName, accountName, properties2);
                    Assert.True(properties3.ProtocolSettings.Smb.Multichannel.Enabled);

                    // Get and validate
                    FileServiceProperties properties4 = storageMgmtClient.FileServices.GetServiceProperties(rgName, accountName);
                    Assert.True(properties3.ProtocolSettings.Smb.Multichannel.Enabled);
                }
                finally
                {
                    // clean up
                    storageMgmtClient.StorageAccounts.Delete(rgName, accountName);
                    resourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }
Ejemplo n.º 25
0
 private static void AssertPropertiesAreEqual(FileServiceProperties fileProps, ServiceProperties props)
 {
     if (fileProps == null || props == null)
     {
         Assert.IsNull(fileProps);
         Assert.IsNull(props);
     }
     else
     {
         Assert.AreEqual(fileProps.Cors, props.Cors);
         Assert.AreEqual(fileProps.MinuteMetrics, props.MinuteMetrics);
         Assert.AreEqual(fileProps.HourMetrics, props.HourMetrics);
     }
 }
Ejemplo n.º 26
0
 internal static void AssertFileServicePropertiesAreEqual(FileServiceProperties propsA, FileServiceProperties propsB)
 {
     if (propsA == null || propsB == null)
     {
         Assert.IsNull(propsA);
         Assert.IsNull(propsB);
     }
     else
     {
         AssertPropertiesAreEqual(propsA, propsA.serviceProperties);
         AssertPropertiesAreEqual(propsB, propsB.serviceProperties);
         AssertServicePropertiesAreEqual(propsA.serviceProperties, propsB.serviceProperties);
     }
 }
        private static FileServiceProperties DefaultServiceProperties()
        {
            FileServiceProperties props = new FileServiceProperties();

            props.HourMetrics.MetricsLevel  = MetricsLevel.None;
            props.HourMetrics.RetentionDays = null;
            props.HourMetrics.Version       = "1.0";

            props.MinuteMetrics.MetricsLevel  = MetricsLevel.None;
            props.MinuteMetrics.RetentionDays = null;
            props.MinuteMetrics.Version       = "1.0";

            props.Cors.CorsRules = new List <CorsRule>();

            return(props);
        }
Ejemplo n.º 28
0
        private static FileServiceProperties DefaultServiceProperties()
        {
            FileServiceProperties props = new FileServiceProperties(new MetricsProperties(), new MetricsProperties(), new CorsProperties());

            props.HourMetrics.MetricsLevel  = MetricsLevel.None;
            props.HourMetrics.RetentionDays = null;
            props.HourMetrics.Version       = "1.0";

            props.MinuteMetrics.MetricsLevel  = MetricsLevel.None;
            props.MinuteMetrics.RetentionDays = null;
            props.MinuteMetrics.Version       = "1.0";
#if !FACADE_NETCORE
            props.Cors.CorsRules = new List <CorsRule>();
#endif
            return(props);
        }
Ejemplo n.º 29
0
        public async Task CloudFileTestAnalyticsRoundTripAsync()
        {
            FileServiceProperties props = DefaultServiceProperties();

            props.Cors.CorsRules.Add(
                new CorsRule()
            {
                AllowedOrigins = new List <string>()
                {
                    "www.ab.com", "www.bc.com"
                },
                AllowedMethods = CorsHttpMethods.Get | CorsHttpMethods.Put,

                MaxAgeInSeconds = 500,
                ExposedHeaders  =
                    new List <string>()
                {
                    "x-ms-meta-data*",
                    "x-ms-meta-source*",
                    "x-ms-meta-abc",
                    "x-ms-meta-bcd"
                },
                AllowedHeaders =
                    new List <string>()
                {
                    "x-ms-meta-data*",
                    "x-ms-meta-target*",
                    "x-ms-meta-xyz",
                    "x-ms-meta-foo"
                }
            });

            props.MinuteMetrics.MetricsLevel  = MetricsLevel.Service;
            props.MinuteMetrics.RetentionDays = 8;

            props.HourMetrics.MetricsLevel  = MetricsLevel.None;
            props.HourMetrics.RetentionDays = 1;

            CloudFileClient client = GenerateCloudFileClient();
            await client.SetServicePropertiesAsync(props);

            TestHelper.AssertFileServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync());
        }
Ejemplo n.º 30
0
        public void Troubleshooting_File_storage_using_metrics()
        {
            // Parse your storage connection string from your application's configuration file.
            StorageCredentials  Credentials    = new StorageCredentials(this.Account, this.Key);
            CloudStorageAccount storageAccount = new CloudStorageAccount(Credentials, false);

            // Create the File service client.
            CloudFileClient fileClient = storageAccount.CreateCloudFileClient();

            // Set metrics properties for File service.
            // Note that the File service currently uses its own service properties type,
            // available in the Microsoft.WindowsAzure.Storage.File.Protocol namespace.
            fileClient.SetServiceProperties(new FileServiceProperties()
            {
                // Set hour metrics
                HourMetrics = new MetricsProperties()
                {
                    MetricsLevel  = MetricsLevel.ServiceAndApi,
                    RetentionDays = 14,
                    Version       = "1.0"
                },
                // Set minute metrics
                MinuteMetrics = new MetricsProperties()
                {
                    MetricsLevel  = MetricsLevel.ServiceAndApi,
                    RetentionDays = 7,
                    Version       = "1.0"
                }
            });

            // Read the metrics properties we just set.
            FileServiceProperties serviceProperties = fileClient.GetServiceProperties();

            Console.WriteLine("Hour metrics:");
            Console.WriteLine(serviceProperties.HourMetrics.MetricsLevel);
            Console.WriteLine(serviceProperties.HourMetrics.RetentionDays);
            Console.WriteLine(serviceProperties.HourMetrics.Version);
            Console.WriteLine();
            Console.WriteLine("Minute metrics:");
            Console.WriteLine(serviceProperties.MinuteMetrics.MetricsLevel);
            Console.WriteLine(serviceProperties.MinuteMetrics.RetentionDays);
            Console.WriteLine(serviceProperties.MinuteMetrics.Version);
        }