/// <summary>
 /// Initializes a new instance of the <see cref="FileServiceProperties"/> class.
 /// </summary>
 public FileServiceProperties()
 {
     this.serviceProperties = new ServiceProperties();
     this.serviceProperties.HourMetrics = null;
     this.serviceProperties.MinuteMetrics = null;
     this.serviceProperties.Logging = null;
 }
 public Task SetServiceProperties(ServiceProperties properties, BlobRequestOptions requestOptions = null, OperationContext operationContext = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     return AsyncTaskUtil.RunAsyncCancellable(
         _inner.BeginSetServiceProperties(properties, requestOptions, operationContext, null, null),
         _inner.EndSetServiceProperties,
         cancellationToken);
 }
 public StorageSettings(string storageName, ServiceProperties serviceProperties)
 {
     InitializeComponent();
     this.Icon = Bitmaps.Azure_Explorer_ico;
     labelStorageAccount.Text = string.Format(labelStorageAccount.Text, storageName);
     _serviceProperties = serviceProperties;
 }
Esempio n. 4
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;
            }
        }
Esempio n. 5
0
        private void InitializeCors()
        {
            var tableServiceProperties = new ServiceProperties();
            var tableClient =
                new CloudStorageAccount(
                    new StorageCredentials(
                        CloudConfigurationManager.GetSetting("storageAccountName"),
                        CloudConfigurationManager.GetSetting("storageAccountKey")),
                    true).CreateCloudTableClient();

            tableServiceProperties.HourMetrics = null;
            tableServiceProperties.MinuteMetrics = null;
            tableServiceProperties.Logging = null;

            tableServiceProperties.Cors = new CorsProperties();
            tableServiceProperties.Cors.CorsRules.Add(new CorsRule()
            {
                AllowedHeaders = new List<string>() { "*" },
                AllowedMethods =  CorsHttpMethods.Get | CorsHttpMethods.Head ,
                //AllowedOrigins = new List<string>() { "http://ercenkbike.azurewebsites.net/" },
                AllowedOrigins = new List<string>() { "*" },
                ExposedHeaders = new List<string>() { "*" },
                MaxAgeInSeconds = 1800 // 30 minutes
            });

            tableClient.SetServiceProperties(tableServiceProperties);
        }
Esempio n. 6
0
        public void OverwriteExistingCORSRuleOfXSCL()
        {
            Action <Constants.ServiceType> setCORSRules = (serviceType) =>
            {
                PSCorsRule[] corsRules = CORSRuleUtil.GetRandomValidCORSRules(random.Next(1, 5));

                Microsoft.WindowsAzure.Storage.Shared.Protocol.ServiceProperties serviceProperties = new Microsoft.WindowsAzure.Storage.Shared.Protocol.ServiceProperties();
                serviceProperties.Clean();
                serviceProperties.Cors = new CorsProperties();

                foreach (var rule in corsRules)
                {
                    serviceProperties.Cors.CorsRules.Add(new CorsRule()
                    {
                        AllowedHeaders  = rule.AllowedHeaders,
                        AllowedOrigins  = rule.AllowedOrigins,
                        ExposedHeaders  = rule.ExposedHeaders,
                        MaxAgeInSeconds = rule.MaxAgeInSeconds,
                        AllowedMethods  = (CorsHttpMethods)random.Next(1, 512)
                    });
                }

                SetSerivceProperties(serviceType, serviceProperties);
            };

            this.OverwriteCORSRules(setCORSRules, Constants.ServiceType.Blob);
            this.OverwriteCORSRules(setCORSRules, Constants.ServiceType.Queue);
            this.OverwriteCORSRules(setCORSRules, Constants.ServiceType.Table);
            this.OverwriteCORSRules(setCORSRules, Constants.ServiceType.File);
        }
        /// <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;
            }
        }
        public void MyTestInitialize()
        {
            props = DefaultServiceProperties();

            if (TestBase.QueueBufferManager != null)
            {
                TestBase.QueueBufferManager.OutstandingBufferCount = 0;
            }
        }
Esempio n. 9
0
        public static void ClearCorsRules(Constants.ServiceType serviceType)
        {
            Microsoft.WindowsAzure.Storage.Shared.Protocol.ServiceProperties serviceProperties = new Microsoft.WindowsAzure.Storage.Shared.Protocol.ServiceProperties();
            serviceProperties.Clean();
            serviceProperties.Cors = new CorsProperties();
            serviceProperties.Cors.CorsRules.Clear();

            SetSerivceProperties(serviceType, serviceProperties);
        }
 public static void MyClassInitialize(TestContext testContext)
 {
     CloudQueueClient client = GenerateCloudQueueClient();
     startProperties = client.GetServiceProperties();
     if (TestBase.QueueBufferManager != null)
     {
         TestBase.QueueBufferManager.OutstandingBufferCount = 0;
     }
 }
        public override void ExecuteCmdlet()
        {
            ServiceProperties currentServiceProperties = Channel.GetStorageServiceProperties(ServiceType, GetRequestOptions(ServiceType), OperationContext);
            ServiceProperties serviceProperties = new ServiceProperties();
            serviceProperties.Clean();
            serviceProperties.Cors = currentServiceProperties.Cors;
            serviceProperties.Cors.CorsRules.Clear();

            Channel.SetStorageServiceProperties(ServiceType, serviceProperties,
                GetRequestOptions(ServiceType), OperationContext);
        }
Esempio n. 12
0
 private void ConfigureCors(ServiceProperties serviceProperties)
 {
     serviceProperties.Cors = new CorsProperties();
     serviceProperties.Cors.CorsRules.Add(new CorsRule
     {
         AllowedHeaders = new[] { "*" },
         AllowedMethods = CorsHttpMethods.Get | CorsHttpMethods.Head,
         AllowedOrigins = new[] { "*" },
         ExposedHeaders = new[] { "Cache-Control", "Content-Type", "Last-Modified", "ETag", "Accept-Ranges" },
         MaxAgeInSeconds = 31536000
     });
 }
Esempio n. 13
0
 /// <summary>
 /// Adds CORS rule to the service properties.
 /// </summary>
 /// <param name="serviceProperties">ServiceProperties</param>
 private static void ConfigureCors(ServiceProperties serviceProperties)
 {
     serviceProperties.Cors = new CorsProperties();
     serviceProperties.Cors.CorsRules.Add(new CorsRule()
     {
         AllowedHeaders = new List<string>() { "*" },
         AllowedMethods = CorsHttpMethods.Put | CorsHttpMethods.Get | CorsHttpMethods.Head | CorsHttpMethods.Post,
         AllowedOrigins = new List<string>() { "*" },
         ExposedHeaders = new List<string>() { "*" },
         MaxAgeInSeconds = 1800 // 30 minutes
     });
 }
        /// <summary>
        ///     Sets the properties of the table service asynchronously.
        /// </summary>
        /// <param name="tableClient">Cloud table client.</param>
        /// <param name="serviceProperties">The table service properties.</param>
        /// <param name="cancellationToken">Cancellation token.</param>
        /// <returns>Task.</returns>
        public static Task SetServicePropertiesAsync(
            this CloudTableClient tableClient,
            ServiceProperties serviceProperties,
            CancellationToken cancellationToken = default (CancellationToken))
        {
            ICancellableAsyncResult asyncResult = tableClient.BeginSetServiceProperties(serviceProperties, null, null);
            CancellationTokenRegistration registration = cancellationToken.Register(p => asyncResult.Cancel(), null);

            return Task.Factory.FromAsync(
                asyncResult,
                result =>
                    {
                        registration.Dispose();
                        tableClient.EndSetServiceProperties(result);
                    });
        }
        public override void ExecuteCmdlet()
        {
            ServiceProperties serviceProperties = new ServiceProperties();
            serviceProperties.Clean();
            serviceProperties.Cors = new CorsProperties();

            foreach (var corsRuleObject in this.CorsRules)
            {
                CorsRule corsRule = new CorsRule();
                corsRule.AllowedHeaders = corsRuleObject.AllowedHeaders;
                corsRule.AllowedOrigins = corsRuleObject.AllowedOrigins;
                corsRule.ExposedHeaders = corsRuleObject.ExposedHeaders;
                corsRule.MaxAgeInSeconds = corsRuleObject.MaxAgeInSeconds;
                this.SetAllowedMethods(corsRule, corsRuleObject.AllowedMethods);
                serviceProperties.Cors.CorsRules.Add(corsRule);
            }

            try
            {
                Channel.SetStorageServiceProperties(ServiceType, serviceProperties,
                    GetRequestOptions(ServiceType), OperationContext);
            }
            catch (StorageException se)
            {
                if ((null != se.RequestInformation) &&
                    ((int)HttpStatusCode.BadRequest == se.RequestInformation.HttpStatusCode) &&
                    (null != se.RequestInformation.ExtendedErrorInformation) &&
                    (string.Equals(InvalidXMLNodeValueError, se.RequestInformation.ExtendedErrorInformation.ErrorCode, StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(InvalidXMLDocError, se.RequestInformation.ExtendedErrorInformation.ErrorCode, StringComparison.OrdinalIgnoreCase)))
                {
                    throw new InvalidOperationException(Resources.CORSRuleError);
                }
                else
                {
                    throw;
                }
            }

            if (PassThru)
            {
                WriteObject(this.CorsRules);
            }
        }
Esempio n. 16
0
        static void Main(string[] args)
        {
            StorageCredentials storageCredentials = new StorageCredentials(args[0], args[1]);
            CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true);

            var blobClient = storageAccount.CreateCloudBlobClient();

            // Define our basics for quick op
            ServiceProperties blobServiceProperties = new ServiceProperties()
            {
                HourMetrics = null,
                MinuteMetrics = null,
                Logging = null,
            };

            // Define our CORS rules (wide open here)
            CorsRule corsRule = new CorsRule()
            {
                AllowedHeaders = new List<string>() { "*" },
                AllowedMethods = CorsHttpMethods.Get | CorsHttpMethods.Post | CorsHttpMethods.Head | CorsHttpMethods.Put,
                AllowedOrigins = new List<string>() { "*" },
                ExposedHeaders = new List<string>() { "*", "Accept-Ranges", "Content-Range"},

                MaxAgeInSeconds = 7200
            };

            // Set our rule
            blobServiceProperties.Cors.CorsRules.Add(corsRule);

            try
            {
                blobClient.SetServiceProperties(blobServiceProperties);
                Console.Out.WriteLine("CORS is rollin' for " + args[0]);
            }
            catch (Exception e)
            {
                Console.Out.WriteLine(e.ToString());
            }
        }
        /// <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, XSCLProtocol.ServiceProperties properties, IRequestOptions options, XSCL.OperationContext operationContext)
        {
            XSCL.CloudStorageAccount account = StorageContext.StorageAccount;
            try
            {
                switch (type)
                {
                case StorageServiceType.Blob:
                    Task.Run(() => account.CreateCloudBlobClient().SetServicePropertiesAsync(properties, (BlobRequestOptions)options, operationContext)).Wait();
                    break;

                case StorageServiceType.Queue:
                    Task.Run(() => account.CreateCloudQueueClient().SetServicePropertiesAsync(properties, (QueueRequestOptions)options, operationContext)).Wait();
                    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;
                    Task.Run(() => account.CreateCloudFileClient().SetServicePropertiesAsync(fileServiceProperties, (FileRequestOptions)options, operationContext)).Wait();
                    break;

                default:
                    throw new ArgumentException(Resources.InvalidStorageServiceType, "type");
                }
            }
            catch (AggregateException e) when(e.InnerException is XSCL.StorageException)
            {
                throw e.InnerException;
            }
        }
 public void SetServiceProperties(ServiceProperties properties, BlobRequestOptions requestOptions = null, OperationContext operationContext = null)
 {
     requestOptions = BlobRequestOptions.ApplyDefaults(requestOptions, BlobType.Unspecified, this);
     operationContext = operationContext ?? new OperationContext();
     Executor.ExecuteSync(
         this.SetServicePropertiesImpl(properties, requestOptions),
         requestOptions.RetryPolicy,
         operationContext);
 }
 public ICancellableAsyncResult BeginSetServiceProperties(ServiceProperties properties, BlobRequestOptions requestOptions, OperationContext operationContext, AsyncCallback callback, object state)
 {
     requestOptions = BlobRequestOptions.ApplyDefaults(requestOptions, BlobType.Unspecified, this);
     operationContext = operationContext ?? new OperationContext();
     return Executor.BeginExecuteAsync(
         this.SetServicePropertiesImpl(properties, requestOptions),
         requestOptions.RetryPolicy,
         operationContext,
         callback,
         state);
 }
 public ICancellableAsyncResult BeginSetServiceProperties(ServiceProperties properties, AsyncCallback callback, object state)
 {
     return this.BeginSetServiceProperties(properties, null /* requestOptions */, null /* operationContext */, callback, state);
 }
        /// <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)),
                HourMetrics = ReadMetricsPropertiesFromXml(servicePropertiesElement.Element(HourMetricsName)),
                MinuteMetrics = ReadMetricsPropertiesFromXml(servicePropertiesElement.Element(MinuteMetricsName)),
                Cors = ReadCorsPropertiesFromXml(servicePropertiesElement.Element(CorsName))
            };

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

            return properties;
        }
Esempio n. 22
0
 public Task SetServicePropertiesAsync(ServiceProperties properties, TableRequestOptions requestOptions, OperationContext operationContext, CancellationToken cancellationToken)
 {
     TableRequestOptions modifiedOptions = TableRequestOptions.ApplyDefaults(requestOptions, this);
     operationContext = operationContext ?? new OperationContext();
     return Task.Run(async () => await Executor.ExecuteAsyncNullReturn(
                                                         this.SetServicePropertiesImpl(properties, modifiedOptions),
                                                         modifiedOptions.RetryPolicy,
                                                         operationContext,
                                                         cancellationToken), cancellationToken);
 }
Esempio n. 23
0
        /// <returns>An <see cref="IAsyncAction"/> that represents an asynchronous action.</returns>
        public IAsyncAction SetServicePropertiesAsync(ServiceProperties properties)
#endif
        {
            return this.SetServicePropertiesAsync(properties, null /* RequestOptions */, null /* OperationContext */);
        }
 public static void MyClassInitialize(TestContext testContext)
 {
     CloudTableClient tableClient = GenerateCloudTableClient();
     startProperties = tableClient.GetServiceProperties();
 }
        private void AssertServicePropertiesAreEqual(ServiceProperties propsA, ServiceProperties propsB)
        {
            Assert.AreEqual(propsA.Logging.LoggingOperations, propsB.Logging.LoggingOperations);
            Assert.AreEqual(propsA.Logging.RetentionDays, propsB.Logging.RetentionDays);
            Assert.AreEqual(propsA.Logging.Version, propsB.Logging.Version);

            Assert.AreEqual(propsA.Metrics.MetricsLevel, propsB.Metrics.MetricsLevel);
            Assert.AreEqual(propsA.Metrics.RetentionDays, propsB.Metrics.RetentionDays);
            Assert.AreEqual(propsA.Metrics.Version, propsB.Metrics.Version);

            Assert.AreEqual(propsA.DefaultServiceVersion, propsB.DefaultServiceVersion);
        }
Esempio n. 26
0
        public void GetServiceProperties_AllService_AllProperties()
        {
            //prepare the service properties to set and get
            PSCorsRule[] corsRules = CORSRuleUtil.GetRandomValidCORSRules(random.Next(1, 5));

            Microsoft.WindowsAzure.Storage.Shared.Protocol.ServiceProperties serviceProperties = new Microsoft.WindowsAzure.Storage.Shared.Protocol.ServiceProperties();
            serviceProperties.Clean();
            serviceProperties.Cors = new CorsProperties();

            foreach (var rule in corsRules)
            {
                CorsRule corsRule = new CorsRule()
                {
                    AllowedHeaders  = rule.AllowedHeaders,
                    AllowedOrigins  = rule.AllowedOrigins,
                    ExposedHeaders  = rule.ExposedHeaders,
                    MaxAgeInSeconds = rule.MaxAgeInSeconds,
                };
                SetAllowedMethods(corsRule, rule.AllowedMethods);
                serviceProperties.Cors.CorsRules.Add(corsRule);
            }
            serviceProperties.HourMetrics = new MetricsProperties("1.0");
            serviceProperties.HourMetrics.MetricsLevel    = MetricsLevel.ServiceAndApi;
            serviceProperties.HourMetrics.RetentionDays   = 1;
            serviceProperties.MinuteMetrics               = new MetricsProperties("1.0");
            serviceProperties.MinuteMetrics.MetricsLevel  = MetricsLevel.Service;
            serviceProperties.MinuteMetrics.RetentionDays = 3;

            serviceProperties.Logging = new LoggingProperties("1.0");
            serviceProperties.Logging.LoggingOperations = LoggingOperations.All;
            serviceProperties.Logging.RetentionDays     = 5;


            foreach (string servicetype in ValidServiceType)
            {
                Constants.ServiceType service = Constants.ServiceType.Blob;
                Enum.TryParse <Constants.ServiceType>(servicetype, true, out service);
                if (service == Constants.ServiceType.Blob) //only Blob support default service version
                {
                    serviceProperties.DefaultServiceVersion = "2017-04-17";

                    serviceProperties.DeleteRetentionPolicy               = new DeleteRetentionPolicy();
                    serviceProperties.DeleteRetentionPolicy.Enabled       = true;
                    serviceProperties.DeleteRetentionPolicy.RetentionDays = 10;
                }

                //Set Service Properties with XSCL API
                ServiceCORSRule.SetSerivceProperties(service, serviceProperties);

                //Get Service Properties with PowerShell
                PSSeriviceProperties properties = GetServicePropertiesFromPSH(service);

                //Validate Cors, metric, logging
                CORSRuleUtil.ValidateCORSRules(corsRules, properties.Cors);

                if (service != Constants.ServiceType.File) // File service don't support logging
                {
                    ExpectEqual(serviceProperties.Logging.Version, properties.Logging.Version, "Logging version");
                    ExpectEqual(serviceProperties.Logging.LoggingOperations.ToString(), properties.Logging.LoggingOperations.ToString(), "Logging Operations");
                    ExpectEqual(serviceProperties.Logging.RetentionDays.Value, properties.Logging.RetentionDays.Value, "Logging RetentionDays");
                }

                ExpectEqual(serviceProperties.HourMetrics.Version, properties.HourMetrics.Version, "HourMetrics Version");
                ExpectEqual(serviceProperties.HourMetrics.MetricsLevel.ToString(), properties.HourMetrics.MetricsLevel.ToString(), "HourMetrics MetricsLevel");
                ExpectEqual(serviceProperties.HourMetrics.RetentionDays.Value, properties.HourMetrics.RetentionDays.Value, "HourMetrics RetentionDays");

                ExpectEqual(serviceProperties.MinuteMetrics.Version, properties.MinuteMetrics.Version, "MinuteMetrics Version");
                ExpectEqual(serviceProperties.MinuteMetrics.MetricsLevel.ToString(), properties.MinuteMetrics.MetricsLevel.ToString(), "MinuteMetrics MetricsLevel");
                ExpectEqual(serviceProperties.MinuteMetrics.RetentionDays.Value, properties.MinuteMetrics.RetentionDays.Value, "MinuteMetrics RetentionDays");


                if (service == Constants.ServiceType.Blob)
                {
                    ExpectEqual(serviceProperties.DefaultServiceVersion, properties.DefaultServiceVersion, "DefaultServiceVersion");

                    ExpectEqual(serviceProperties.DeleteRetentionPolicy.Enabled.ToString(), properties.DeleteRetentionPolicy.Enabled.ToString(), "DeleteRetentionPolicy Enabled");
                    ExpectEqual(serviceProperties.DeleteRetentionPolicy.RetentionDays.Value, properties.DeleteRetentionPolicy.RetentionDays.Value, "DeleteRetentionPolicy RetentionDays");

                    serviceProperties.DeleteRetentionPolicy = null;
                    serviceProperties.DefaultServiceVersion = null;
                }
            }
        }
        private static ServiceProperties DefaultServiceProperties()
        {
            ServiceProperties props = new ServiceProperties();

            props.Logging.LoggingOperations = LoggingOperations.None;
            props.Logging.RetentionDays = null;
            props.Logging.Version = "1.0";

            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;
        }
        private RESTCommand<NullType> SetServicePropertiesImpl(ServiceProperties properties, BlobRequestOptions requestOptions)
        {
            MemoryStream str = new MemoryStream();
            try
            {
                properties.WriteServiceProperties(str);
            }
            catch (InvalidOperationException invalidOpException)
            {
                throw new ArgumentException(invalidOpException.Message, "properties");
            }

            str.Seek(0, SeekOrigin.Begin);

            RESTCommand<NullType> retCmd = new RESTCommand<NullType>(this.Credentials, this.BaseUri);
            retCmd.SendStream = str;
            retCmd.BuildRequestDelegate = BlobHttpWebRequestFactory.SetServiceProperties;
            retCmd.RecoveryAction = RecoveryActions.RewindStream;
            retCmd.SignRequest = this.AuthenticationHandler.SignRequest;
            retCmd.PreProcessResponse =
                (cmd, resp, ex, ctx) =>
                HttpResponseParsers.ProcessExpectedStatusCodeNoException(System.Net.HttpStatusCode.Accepted, resp, NullType.Value, cmd, ex, ctx);
            retCmd.ApplyRequestOptions(requestOptions);
            return retCmd;
        }
Esempio n. 29
0
 /// <returns>An <see cref="Task"/> that represents an asynchronous action.</returns>
 public Task SetServicePropertiesAsync(ServiceProperties properties)
Esempio n. 30
0
        internal bool CheckStorageAnalytics(string storageAccountName, ServiceProperties currentConfig)
        {
            if ((currentConfig == null)
                || (currentConfig.Logging == null)
                || ((currentConfig.Logging.LoggingOperations & LoggingOperations.All) != LoggingOperations.All)
                || (currentConfig.MinuteMetrics == null)
                || (currentConfig.MinuteMetrics.MetricsLevel <= 0)
                || (currentConfig.MinuteMetrics.RetentionDays < 0))
            {
                WriteVerbose("Storage account {0} does not have the required metrics enabled", storageAccountName);
                return false;
            }

            WriteVerbose("Storage account {0} has required metrics enabled", storageAccountName);
            return true;
        }
Esempio n. 31
0
 public Task SetServicePropertiesAsync(ServiceProperties properties, TableRequestOptions requestOptions, OperationContext operationContext)
 {
     return this.SetServicePropertiesAsync(properties, requestOptions, operationContext, CancellationToken.None);
 }
 /// <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;
         default:
             throw new ArgumentException(Resources.InvalidStorageServiceType, "type");
     }
 }
Esempio n. 33
0
        private RESTCommand<NullType> SetServicePropertiesImpl(ServiceProperties properties, TableRequestOptions 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);
            requestOptions.ApplyToStorageCommand(retCmd);
            retCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => TableHttpRequestMessageFactory.SetServiceProperties(uri, serverTimeout, cnt, ctx);
            retCmd.BuildContent = (cmd, ctx) => HttpContentFactory.BuildContentFromStream(memoryStream, 0, memoryStream.Length, null /* md5 */, cmd, ctx);
            retCmd.Handler = this.AuthenticationHandler;
            retCmd.BuildClient = HttpClientFactory.BuildHttpClient;
            retCmd.PreProcessResponse =
                (cmd, resp, ex, ctx) =>
                HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.Accepted, resp, null /* retVal */, cmd, ex);

            requestOptions.ApplyToStorageCommand(retCmd);
            return retCmd;
        }
 public IAsyncAction SetServicePropertiesAsync(ServiceProperties properties, BlobRequestOptions requestOptions, OperationContext operationContext)
 {
     BlobRequestOptions modifiedOptions = BlobRequestOptions.ApplyDefaults(requestOptions, BlobType.Unspecified, this);
     operationContext = operationContext ?? new OperationContext();
     return AsyncInfo.Run(async (token) => await Executor.ExecuteAsyncNullReturn(
          this.SetServicePropertiesImpl(properties, modifiedOptions),
         modifiedOptions.RetryPolicy,
         operationContext,
         token));
 }
 public static void MyClassInitialize(TestContext testContext)
 {
     client = GenerateCloudQueueClient();
     startProperties = client.GetServicePropertiesAsync().AsTask().Result;
 }
        public void CloudTableTestAnalyticsDefaultServiceVersionThrows()
        {
            CloudTableClient client = GenerateCloudTableClient();
            OperationContext ctx = new OperationContext();

            ServiceProperties props = new ServiceProperties();
            props.DefaultServiceVersion = "2009-09-19";

            props.Logging.LoggingOperations = LoggingOperations.None;
            props.Logging.Version = "1.0";

            props.Metrics.MetricsLevel = MetricsLevel.None;
            props.Metrics.Version = "1.0";

            try
            {
                client.SetServiceProperties(props, null, ctx);
                Assert.Fail("Should not be able to set default Service Version for non Blob Client");
            }
            catch (StorageException ex)
            {
                Assert.AreEqual(ex.Message, "The remote server returned an error: (400) Bad Request.");
                Assert.AreEqual(ex.RequestInformation.HttpStatusCode, (int)HttpStatusCode.BadRequest);
                TestHelper.AssertNAttempts(ctx, 1);
            }
            catch (Exception)
            {
                Assert.Fail();
            }
        }