public static void Run(string connectionString, bool disableLogging) { _connectionString = connectionString; _storageAccount = CloudStorageAccount.Parse(connectionString); _queueClient = _storageAccount.CreateCloudQueueClient(); try { TimeSpan azureSDKTime = RunAzureSDKTest(); TimeSpan webJobsSDKTime = RunWebJobsSDKTest(disableLogging); // Convert to ulong because the measurment block does not support other data type ulong perfRatio = (ulong)((webJobsSDKTime.TotalMilliseconds / azureSDKTime.TotalMilliseconds) * 100); Console.WriteLine("--- Results ---"); Console.WriteLine("Azure SDK: {0} ms: ", azureSDKTime.TotalMilliseconds); Console.WriteLine("WebJobs SDK: {0} ms: ", webJobsSDKTime.TotalMilliseconds); Console.WriteLine("Perf ratio (x100, long): {0}", perfRatio); MeasurementBlock.Mark( perfRatio, (disableLogging ? QueueNoLoggingOverheadMetric : QueueLoggingOverheadMetric) + ";Ratio;Percent"); } finally { Cleanup(); } }
public override void Run() { // This is a sample worker implementation. Replace with your logic. Trace.TraceInformation("QueueProcessor_WorkerRole entry point called", "Information"); // Initialize the account information var storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString")); // retrieve a reference to the messages queue var queueClient = new CloudQueueClient(this.uri, new StorageCredentials(this.GetProcessSasForQueues())); var queue = queueClient.GetQueueReference("messagequeue"); while (true) { Thread.Sleep(10000); Trace.TraceInformation("Working", "Information"); if (queue.Exists()) { if (DateTime.UtcNow.AddMinutes(1) >= this.serviceQueueSasExpiryTime) { queueClient = new CloudQueueClient(this.uri, new StorageCredentials(this.GetProcessSasForQueues())); queue = queueClient.GetQueueReference("messagequeue"); } var msg = queue.GetMessage(); if (msg != null) { Trace.TraceInformation(string.Format("Message '{0}' processed.", msg.AsString)); queue.DeleteMessage(msg); } } } }
public AzureQueueController() { var credentials = new StorageCredentials(ConfigurationManager.AppSettings["AzureAccountName"], ConfigurationManager.AppSettings["AzureKeyValue"]); var azureTableUri = new Uri("https://" + ConfigurationManager.AppSettings["AzureAccountName"] + ".queue.core.windows.net"); var client = new CloudQueueClient(azureTableUri, credentials); _queue = client.GetQueueReference(QueueName); }
public BlobManager(string conStr) { //RoleEnvironment.GetConfigurationSettingValue("UploadCon") Storage = CloudStorageAccount.Parse(conStr); BlobClient = Storage.CreateCloudBlobClient(); QueueClient = Storage.CreateCloudQueueClient(); }
public override void Run() { Trace.TraceInformation("QueueProcessor_WorkerRole entry point called", "Information"); var queueClient = new CloudQueueClient(this.uri, new StorageCredentials(this.GetQueueSas())); var queue = queueClient.GetQueueReference("messagequeue"); while (true) { Thread.Sleep(10000); Trace.TraceInformation("Working", "Information"); if (DateTime.UtcNow.AddMinutes(1) >= this.serviceQueueSasExpiryTime) { queueClient = new CloudQueueClient(this.uri, new StorageCredentials(this.GetQueueSas())); queue = queueClient.GetQueueReference("messagequeue"); } var msg = queue.GetMessage(); if (msg != null) { Trace.TraceInformation(string.Format("Message '{0}' processed.", msg.AsString)); queue.DeleteMessage(msg); } } }
public QueueManager(string storageAccountName, string storageAccessKey, string queueName) : base(storageAccountName, storageAccessKey) { this._queueName = queueName.ToLowerInvariant(); this._queueClient = _storageAccount.CreateCloudQueueClient(); this._queue = this._queueClient.GetQueueReference(this._queueName); this._queue.CreateIfNotExistsAsync().GetAwaiter().GetResult(); }
protected EndToEndTestFixture(string rootPath) { string connectionString = AmbientConnectionStringProvider.Instance.GetConnectionString(ConnectionStringNames.Storage); CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString); _queueClient = storageAccount.CreateCloudQueueClient(); _blobClient = storageAccount.CreateCloudBlobClient(); CreateTestStorageEntities(); TraceWriter = new TestTraceWriter(TraceLevel.Verbose); ScriptHostConfiguration config = new ScriptHostConfiguration() { RootScriptPath = rootPath, TraceWriter = TraceWriter, FileLoggingEnabled = true }; HostManager = new ScriptHostManager(config); Thread t = new Thread(_ => { HostManager.RunAndBlock(); }); t.Start(); TestHelpers.Await(() => HostManager.IsRunning).Wait(); }
protected virtual void configureQueue(CloudStorageAccount storageAccount) { // Create the queue client this.queueClient = storageAccount.CreateCloudQueueClient(); this.queue = createQueue(this.queueClient, this.queueName); }
public static CloudQueueClient GenerateCloudQueueClient() { Uri baseAddressUri = new Uri(TestBase.TargetTenantConfig.QueueServiceEndpoint); CloudQueueClient client = new CloudQueueClient(baseAddressUri, TestBase.StorageCredentials); client.AuthenticationScheme = DefaultAuthenticationScheme; return client; }
public void CloudQueueClientConstructor() { Uri baseAddressUri = new Uri(TestBase.TargetTenantConfig.QueueServiceEndpoint); CloudQueueClient queueClient = new CloudQueueClient(baseAddressUri, TestBase.StorageCredentials); Assert.IsTrue(queueClient.BaseUri.ToString().StartsWith(TestBase.TargetTenantConfig.QueueServiceEndpoint)); Assert.AreEqual(TestBase.StorageCredentials, queueClient.Credentials); }
public void Setup() { client = CloudStorageAccount.DevelopmentStorageAccount.CreateCloudQueueClient(); client.ServerTimeout = TimeSpan.FromSeconds(10); nativeQueue = client.GetQueueReference(QueueName); nativeQueue.CreateIfNotExists(); nativeQueue.Clear(); sender = new AzureMessageQueueSender { Client = client, MessageSerializer = new JsonMessageSerializer(new MessageMapper()) }; sender.Init(QueueName, true); receiver = new AzureMessageQueueReceiver { Client = client, MessageSerializer = new JsonMessageSerializer(new MessageMapper()), }; receiver.Init(QueueName, true); }
/// <summary> /// Constructs the transport /// </summary> public AzureStorageQueuesTransport(CloudStorageAccount storageAccount, string inputQueueName) { if (storageAccount == null) throw new ArgumentNullException("storageAccount"); if (inputQueueName == null) throw new ArgumentNullException("inputQueueName"); _inputQueueName = inputQueueName.ToLowerInvariant(); _queueClient = storageAccount.CreateCloudQueueClient(); }
public QueueHelper(string storageAccountConnectionString) : base(storageAccountConnectionString) { queueClient = base.StorageAccount.CreateCloudQueueClient(); subscribeQueue = queueClient.GetQueueReference(ConfigurationManager.AppSettings["QueueAzuremailsubscribequeue"]); subscribeQueue.CreateIfNotExists(); }
private void CreateShipQueue(CloudQueueClient queueClient) { var shipQueueName = CloudConfigurationManager.GetSetting("ShipQueue.Name"); var queue = queueClient.GetQueueReference(shipQueueName); queue.CreateIfNotExists(); }
public AnalyzeSummonerMatchHistoryQueue(CloudQueueClient queueClient) { Guard.NotNull(queueClient, nameof(queueClient)); this._queueClient = queueClient; this._dequeuedMessages = new ConcurrentDictionary<int, CloudQueueMessage>(); }
// Constructor - pass in a storage connection string. public QueueHelper(string connectionString) { Account = CloudStorageAccount.Parse(connectionString); QueueClient = Account.CreateCloudQueueClient(); IRetryPolicy linearRetryPolicy = new LinearRetry(TimeSpan.Zero, 4); QueueClient.RetryPolicy = linearRetryPolicy; }
public UpdateSummonerQueue(CloudQueueClient queueClient) { Guard.NotNull(queueClient, nameof(queueClient)); this._queueClient = queueClient; this._dequeuedMessages = new ConcurrentDictionary<int, CloudQueueMessage>(); }
public static void Initialize(string storageConnectionString, string ocrQueueName, string emailQueueName) { storageAccount = CloudStorageAccount.Parse(storageConnectionString); queueClient = storageAccount.CreateCloudQueueClient(); ocrQueue = InitializeQueue(ocrQueueName); emailQueue = InitializeQueue(emailQueueName); }
/// <summary> /// Initializes a new instance of the <see cref="CloudQueue"/> class. /// </summary> /// <param name="queueName">The queue name.</param> /// <param name="serviceClient">A client object that specifies the endpoint for the queue service.</param> internal CloudQueue(string queueName, CloudQueueClient serviceClient) { this.Uri = NavigationHelper.AppendPathToUri(serviceClient.BaseUri, queueName); this.ServiceClient = serviceClient; this.Name = queueName; this.Metadata = new Dictionary<string, string>(); this.EncodeMessage = true; }
public EmailQueue(CloudQueueClient queueClient) { Guard.NotNull(queueClient, nameof(queueClient)); this._queueClient = queueClient; this._dequeuedMessages = new ConcurrentDictionary<Email, CloudQueueMessage>(); }
public QueueHelper(string connection, string queueName) { var account = CloudStorageAccount.Parse(connection); var retry = new LinearRetry(TimeSpan.FromSeconds(1), 3); queueClient = account.CreateCloudQueueClient(); queueClient.RetryPolicy = retry; queue = queueClient.GetQueueReference(queueName); queue.CreateIfNotExists(); }
public HostMessageSender(CloudQueueClient client) { if (client == null) { throw new ArgumentNullException("client"); } _client = client; }
static StorageHelper() { if (!string.IsNullOrEmpty(SimpleSettings.StorageConnectionString)) { StorageAccount = CloudStorageAccount.Parse(SimpleSettings.StorageConnectionString); BlobClient = StorageAccount.CreateCloudBlobClient(); QueueClient = StorageAccount.CreateCloudQueueClient(); } }
public CallQueueService(string storageConnectionStringConfigName = "StorageConnectionString") { var connectionString = CloudConfigurationManager.GetSetting(storageConnectionStringConfigName); var storageAccount = CloudStorageAccount.Parse(connectionString); this.queueClient = storageAccount.CreateCloudQueueClient(); this.queue = queueClient.GetQueueReference("calls"); this.queue.CreateIfNotExists(); }
protected virtual CloudQueue createQueue(CloudQueueClient client, string queueName) { // Retrieve a reference to a queues var queue = client.GetQueueReference(queueName); // Create the queue if it doesn't already exist queue.CreateIfNotExists(); return queue; }
public azureStorageHelper(string acountName, string accountKey) { sCredentials = new StorageCredentials(acountName, accountKey); storageAccount = new CloudStorageAccount(sCredentials, true); queueClient = storageAccount.CreateCloudQueueClient(); blobClient = storageAccount.CreateCloudBlobClient(); permisions = new BlobContainerPermissions(); permisions.PublicAccess = BlobContainerPublicAccessType.Container; }
public QueueHelper(Config config) { var connectionString = config.AzureConnectionString; CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(connectionString); cloudQueueClient = cloudStorageAccount.CreateCloudQueueClient(); cloudQueueClient.ServerTimeout = TimeSpan.FromSeconds(config.TimeoutInSeconds); cloudQueueClient.RetryPolicy = new LinearRetry(TimeSpan.FromSeconds(3), config.RetryCount); }
public QueueRepository() { try { _storageAccount = CloudStorageAccount.Parse(ConfigReader<string>.GetSetting("EarthOnlineStorage")); _blobClient = _storageAccount.CreateCloudBlobClient(); _queueClient = _storageAccount.CreateCloudQueueClient(); } catch (Exception) { }//fail silently for developers without valid storage settings }
/// <summary> /// Initializes a new instance of the <see cref="CloudQueue"/> class. /// </summary> /// <param name="queueName">The queue name.</param> /// <param name="serviceClient">A client object that specifies the endpoint for the Queue service.</param> internal CloudQueue(string queueName, CloudQueueClient serviceClient) { this.StorageUri = NavigationHelper.AppendPathToUri(serviceClient.StorageUri, queueName); this.ServiceClient = serviceClient; // Set the relativized name from the URI. this.Name = NavigationHelper.GetQueueNameFromUri(this.Uri, this.ServiceClient.UsePathStyleUris); ; this.Metadata = new Dictionary<string, string>(); this.EncodeMessage = true; }
public QueueHelper() { string connectionString = Settings.AzureConnectionString(); CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(connectionString); cloudQueueClient = cloudStorageAccount.CreateCloudQueueClient(); cloudQueueClient.ServerTimeout = Settings.Timeout(); cloudQueueClient.RetryPolicy = new LinearRetry( TimeSpan.FromSeconds(3), Settings.RetryCount() ); }
public static void MyClassInitialize(TestContext testContext) { client = GenerateCloudQueueClient(); startProperties = client.GetServiceProperties(); if (TestBase.QueueBufferManager != null) { TestBase.QueueBufferManager.OutstandingBufferCount = 0; } }
public Microsoft.WindowsAzure.Storage.Queue.CloudQueue GetStorageQueue(string name) { Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse( StorageConnectionString); ServicePoint tableServicePoint = ServicePointManager.FindServicePoint(storageAccount.TableEndpoint); tableServicePoint.UseNagleAlgorithm = false; Microsoft.WindowsAzure.Storage.Queue.CloudQueueClient client = storageAccount.CreateCloudQueueClient(); CloudQueue queue = client.GetQueueReference(name); queue.CreateIfNotExistsAsync().Wait(); return(queue); }
public async Task CloudQueueAddMessageFullParameterAsync() { CloudQueueMessage futureMessage = new CloudQueueMessage("This message is for the future."); CloudQueueMessage presentMessage = new CloudQueueMessage("This message is for the present."); CloudQueueClient client = GenerateCloudQueueClient(); CloudQueue queue = client.GetQueueReference(GenerateNewQueueName()); try { await queue.CreateIfNotExistsAsync(); await queue.AddMessageAsync(futureMessage, null, TimeSpan.FromDays(2), null, null); VerifyAddMessageResult(futureMessage); // We should not be able to see the future message yet. CloudQueueMessage retrievedMessage = await queue.GetMessageAsync(); Assert.IsNull(retrievedMessage); await queue.AddMessageAsync(presentMessage, null, TimeSpan.Zero, null, null); VerifyAddMessageResult(presentMessage); await queue.AddMessageAsync(presentMessage, TimeSpan.FromDays(1), null, null, null); VerifyAddMessageResult(presentMessage); // We should be able to see the present message. retrievedMessage = await queue.GetMessageAsync(); Assert.IsNotNull(retrievedMessage); Assert.AreEqual <string>(presentMessage.AsString, retrievedMessage.AsString); await queue.AddMessageAsync(futureMessage, TimeSpan.FromDays(2), TimeSpan.FromDays(1), null, null); VerifyAddMessageResult(futureMessage); await queue.ClearAsync(); // -1 seconds should set an infinite ttl await queue.AddMessageAsync(presentMessage, TimeSpan.FromSeconds(-1), null, null, null); retrievedMessage = await queue.PeekMessageAsync(); Assert.AreEqual(DateTime.MaxValue.Year, retrievedMessage.ExpirationTime.Value.Year); // There should be no upper bound on ttl await queue.AddMessageAsync(presentMessage, TimeSpan.MaxValue, null, null, null); // Check other edge cases await queue.AddMessageAsync(presentMessage, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(0), null, null); await queue.AddMessageAsync(presentMessage, TimeSpan.FromSeconds(7 * 24 * 60 * 60), TimeSpan.FromSeconds(7 * 24 * 60 * 60 - 1), null, null); await queue.AddMessageAsync(presentMessage, TimeSpan.FromSeconds(-1), TimeSpan.FromSeconds(1), null, null); await TestHelper.ExpectedExceptionAsync <ArgumentException>( async() => await queue.AddMessageAsync(futureMessage, TimeSpan.FromDays(1), TimeSpan.FromDays(2), null, null), "Using a visibility timeout longer than the time to live should fail"); await TestHelper.ExpectedExceptionAsync <ArgumentException>( async() => await queue.AddMessageAsync(futureMessage, null, TimeSpan.FromDays(8), null, null), "Using a visibility longer than the maximum visibility timeout should fail"); await TestHelper.ExpectedExceptionAsync <ArgumentException>( async() => await queue.AddMessageAsync(futureMessage, null, TimeSpan.FromMinutes(-1), null, null), "Using a negative visibility should fail"); await TestHelper.ExpectedExceptionAsync <ArgumentException>( async() => await queue.AddMessageAsync(futureMessage, TimeSpan.FromMinutes(-1), null, null, null), "Using a negative TTL other than -1 seconds (infinite) should fail"); await TestHelper.ExpectedExceptionAsync <ArgumentException>( () => queue.AddMessageAsync(futureMessage, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1), null, null), "Visibility timeout must be strictly less than the TTL"); await TestHelper.ExpectedExceptionAsync <ArgumentException>( () => queue.AddMessageAsync(presentMessage, null, CloudQueueMessage.MaxVisibilityTimeout, null, null), "Null TTL will default to 7 days, which is the max visibility timeout. They cannot be equal."); } finally { queue.DeleteIfExistsAsync().Wait(); } }
internal static QueueRequestOptions ApplyDefaults(QueueRequestOptions options, CloudQueueClient serviceClient) { QueueRequestOptions modifiedOptions = new QueueRequestOptions(options); modifiedOptions.RetryPolicy = modifiedOptions.RetryPolicy ?? serviceClient.RetryPolicy; modifiedOptions.ServerTimeout = modifiedOptions.ServerTimeout ?? serviceClient.ServerTimeout; modifiedOptions.MaximumExecutionTime = modifiedOptions.MaximumExecutionTime ?? serviceClient.MaximumExecutionTime; if (!modifiedOptions.OperationExpiryTime.HasValue && modifiedOptions.MaximumExecutionTime.HasValue) { modifiedOptions.OperationExpiryTime = DateTime.Now + modifiedOptions.MaximumExecutionTime.Value; } return(modifiedOptions); }
internal static QueueRequestOptions ApplyDefaults(QueueRequestOptions options, CloudQueueClient serviceClient) { QueueRequestOptions modifiedOptions = new QueueRequestOptions(options); modifiedOptions.RetryPolicy = modifiedOptions.RetryPolicy ?? serviceClient.DefaultRequestOptions.RetryPolicy ?? BaseDefaultRequestOptions.RetryPolicy; #if !(WINDOWS_RT || NETCORE) modifiedOptions.EncryptionPolicy = modifiedOptions.EncryptionPolicy ?? serviceClient.DefaultRequestOptions.EncryptionPolicy ?? BaseDefaultRequestOptions.EncryptionPolicy; modifiedOptions.RequireEncryption = modifiedOptions.RequireEncryption ?? serviceClient.DefaultRequestOptions.RequireEncryption ?? BaseDefaultRequestOptions.RequireEncryption; #endif modifiedOptions.LocationMode = modifiedOptions.LocationMode ?? serviceClient.DefaultRequestOptions.LocationMode ?? BaseDefaultRequestOptions.LocationMode; modifiedOptions.ServerTimeout = modifiedOptions.ServerTimeout ?? serviceClient.DefaultRequestOptions.ServerTimeout ?? BaseDefaultRequestOptions.ServerTimeout; modifiedOptions.MaximumExecutionTime = modifiedOptions.MaximumExecutionTime ?? serviceClient.DefaultRequestOptions.MaximumExecutionTime ?? BaseDefaultRequestOptions.MaximumExecutionTime; if (!modifiedOptions.OperationExpiryTime.HasValue && modifiedOptions.MaximumExecutionTime.HasValue) { modifiedOptions.OperationExpiryTime = DateTime.Now + modifiedOptions.MaximumExecutionTime.Value; } return(modifiedOptions); }
internal CloudQueue(string queueName, CloudQueueClient serviceClient) : this((IDictionary <string, string>) new Dictionary <string, string>(), queueName, serviceClient) { throw new System.NotImplementedException(); }
public async Task QueueContinuationTokenVerifyXmlWithinXml() { CloudQueueClient client = GenerateCloudQueueClient(); string prefix = "dotnetqueuetest" + Guid.NewGuid().ToString("N"); List <string> queueNames = new List <string>(); int count = 30; for (int i = 0; i < count; i++) { queueNames.Add(prefix + i); client.GetQueueReference(prefix + i).Create(); } QueueContinuationToken token = null; List <CloudQueue> results = new List <CloudQueue>(); do { QueueResultSegment segment = client.ListQueuesSegmented(prefix, QueueListingDetails.None, 5, token, null, null); token = segment.ContinuationToken; results.AddRange(segment.Results); if (token != null) { Assert.AreEqual(null, token.GetSchema()); XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; StringBuilder sb = new StringBuilder(); using (XmlWriter writer = XmlWriter.Create(sb, settings)) { writer.WriteStartElement("test1"); writer.WriteStartElement("test2"); token.WriteXml(writer); writer.WriteEndElement(); writer.WriteEndElement(); } using (XmlReader reader = XMLReaderExtensions.CreateAsAsync(new MemoryStream(Encoding.Unicode.GetBytes(sb.ToString())))) { token = new QueueContinuationToken(); await reader.ReadStartElementAsync(); await reader.ReadStartElementAsync(); await token.ReadXmlAsync(reader); await reader.ReadEndElementAsync(); await reader.ReadEndElementAsync(); } } }while (token != null); foreach (CloudQueue queue in results) { if (queueNames.Remove(queue.Name)) { queue.Delete(); } else { Assert.Fail(); } } Assert.AreEqual <int>(0, queueNames.Count); }
public async Task CloudQueueTestAnalyticsRetentionPoliciesAsync() { CloudQueueClient client = GenerateCloudQueueClient(); ServiceProperties props = await client.GetServicePropertiesAsync(); // Set retention policy null with metrics disabled. props.Metrics.RetentionDays = null; props.Metrics.MetricsLevel = MetricsLevel.None; await client.SetServicePropertiesAsync(props); // Wait for analytics server to update await Task.Delay(60 * 1000); AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync()); // Set retention policy not null with metrics disabled. props.Metrics.RetentionDays = 1; props.Metrics.MetricsLevel = MetricsLevel.Service; await client.SetServicePropertiesAsync(props); // Wait for analytics server to update await Task.Delay(60 * 1000); AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync()); // Set retention policy not null with metrics enabled. props.Metrics.MetricsLevel = MetricsLevel.ServiceAndApi; props.Metrics.RetentionDays = 2; await client.SetServicePropertiesAsync(props); // Wait for analytics server to update await Task.Delay(60 * 1000); AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync()); // Set retention policy null with logging disabled. props.Logging.RetentionDays = null; props.Logging.LoggingOperations = LoggingOperations.None; await client.SetServicePropertiesAsync(props); // Wait for analytics server to update await Task.Delay(60 * 1000); AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync()); // Set retention policy not null with logging disabled. props.Logging.RetentionDays = 3; props.Logging.LoggingOperations = LoggingOperations.None; await client.SetServicePropertiesAsync(props); // Wait for analytics server to update await Task.Delay(60 * 1000); AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync()); // Set retention policy null with logging enabled. props.Logging.RetentionDays = null; props.Logging.LoggingOperations = LoggingOperations.All; await client.SetServicePropertiesAsync(props); // Wait for analytics server to update await Task.Delay(60 * 1000); AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync()); // Set retention policy not null with logging enabled. props.Logging.RetentionDays = 4; props.Logging.LoggingOperations = LoggingOperations.All; await client.SetServicePropertiesAsync(props); // Wait for analytics server to update await Task.Delay(60 * 1000); AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync()); }
public static async Task MyClassCleanup() { CloudQueueClient client = GenerateCloudQueueClient(); await client.SetServicePropertiesAsync(startProperties); }
public static void MyClassInitialize(TestContext testContext) { client = GenerateCloudQueueClient(); startProperties = client.GetServicePropertiesAsync().Result; }
public async Task CloudQueueTestCorsMaxHeadersAsync() { CorsRule ruleManyHeaders = new CorsRule() { AllowedOrigins = new List <string>() { "www.xyz.com" }, AllowedMethods = CorsHttpMethods.Get, AllowedHeaders = new List <string>() { "x-ms-meta-target*", "x-ms-meta-other*" }, ExposedHeaders = new List <string>() { "x-ms-meta-data*", "x-ms-meta-source*" } }; // Add maximum number of non-prefixed headers for (int i = 0; i < 64; i++) { ruleManyHeaders.ExposedHeaders.Add("x-ms-meta-" + i); ruleManyHeaders.AllowedHeaders.Add("x-ms-meta-" + i); } CloudQueueClient client = GenerateCloudQueueClient(); await this.TestCorsRulesAsync(client, null, new List <CorsRule>() { ruleManyHeaders }); // Test with too many Exposed Headers (65) ruleManyHeaders.ExposedHeaders.Add("x-ms-meta-toomany"); OperationContext context = new OperationContext(); await TestHelper.ExpectedExceptionAsync( async() => await this.TestCorsRulesAsync(client, context, new List <CorsRule>() { ruleManyHeaders }), context, "A maximum of 64 literal exposed headers are allowed.", HttpStatusCode.BadRequest, "InvalidXmlNodeValue"); ruleManyHeaders.ExposedHeaders.Remove("x-ms-meta-toomany"); // Test with too many Allowed Headers (65) ruleManyHeaders.AllowedHeaders.Add("x-ms-meta-toomany"); await TestHelper.ExpectedExceptionAsync( async() => await this.TestCorsRulesAsync(client, context, new List <CorsRule>() { ruleManyHeaders }), context, "A maximum of 64 literal allowed headers are allowed.", HttpStatusCode.BadRequest, "InvalidXmlNodeValue"); ruleManyHeaders.AllowedHeaders.Remove("x-ms-meta-toomany"); // Test with too many Exposed Prefixed Headers (three) ruleManyHeaders.ExposedHeaders.Add("x-ms-meta-toomany*"); await TestHelper.ExpectedExceptionAsync( async() => await this.TestCorsRulesAsync(client, context, new List <CorsRule>() { ruleManyHeaders }), context, "A maximum of two prefixed exposed headers are allowed.", HttpStatusCode.BadRequest, "InvalidXmlNodeValue"); ruleManyHeaders.ExposedHeaders.Remove("x-ms-meta-toomany*"); // Test with too many Allowed Prefixed Headers (three) ruleManyHeaders.AllowedHeaders.Add("x-ms-meta-toomany*"); await TestHelper.ExpectedExceptionAsync( async() => await this.TestCorsRulesAsync(client, context, new List <CorsRule>() { ruleManyHeaders }), context, "A maximum of two prefixed allowed headers are allowed.", HttpStatusCode.BadRequest, "InvalidXmlNodeValue"); ruleManyHeaders.AllowedHeaders.Remove("x-ms-meta-toomany*"); }
public async Task CloudQueueTestValidCorsRulesAsync() { CorsRule ruleMinRequired = new CorsRule() { AllowedOrigins = new List <string>() { "www.xyz.com" }, AllowedMethods = CorsHttpMethods.Get }; CorsRule ruleBasic = 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" } }; CorsRule ruleAllMethods = new CorsRule() { AllowedOrigins = new List <string>() { "www.xyz.com" }, AllowedMethods = CorsHttpMethods.Put | CorsHttpMethods.Trace | CorsHttpMethods.Connect | CorsHttpMethods.Delete | CorsHttpMethods.Get | CorsHttpMethods.Head | CorsHttpMethods.Options | CorsHttpMethods.Post | CorsHttpMethods.Merge }; CorsRule ruleSingleExposedHeader = new CorsRule() { AllowedOrigins = new List <string>() { "www.ab.com" }, AllowedMethods = CorsHttpMethods.Get, ExposedHeaders = new List <string>() { "x-ms-meta-bcd" }, }; CorsRule ruleSingleExposedPrefixHeader = new CorsRule() { AllowedOrigins = new List <string>() { "www.ab.com" }, AllowedMethods = CorsHttpMethods.Get, ExposedHeaders = new List <string>() { "x-ms-meta-data*" }, }; CorsRule ruleSingleAllowedHeader = new CorsRule() { AllowedOrigins = new List <string>() { "www.ab.com" }, AllowedMethods = CorsHttpMethods.Get, AllowedHeaders = new List <string>() { "x-ms-meta-xyz", }, }; CorsRule ruleSingleAllowedPrefixHeader = new CorsRule() { AllowedOrigins = new List <string>() { "www.ab.com" }, AllowedMethods = CorsHttpMethods.Get, AllowedHeaders = new List <string>() { "x-ms-meta-target*" }, }; CorsRule ruleAllowAll = new CorsRule() { AllowedOrigins = new List <string>() { "*" }, AllowedMethods = CorsHttpMethods.Get, AllowedHeaders = new List <string>() { "*" }, ExposedHeaders = new List <string>() { "*" } }; CloudQueueClient client = GenerateCloudQueueClient(); await this.TestCorsRulesAsync(client, null, new List <CorsRule>() { ruleBasic }); await this.TestCorsRulesAsync(client, null, new List <CorsRule>() { ruleMinRequired }); await this.TestCorsRulesAsync(client, null, new List <CorsRule>() { ruleAllMethods }); await this.TestCorsRulesAsync(client, null, new List <CorsRule>() { ruleSingleExposedHeader }); await this.TestCorsRulesAsync(client, null, new List <CorsRule>() { ruleSingleExposedPrefixHeader }); await this.TestCorsRulesAsync(client, null, new List <CorsRule>() { ruleSingleAllowedHeader }); await this.TestCorsRulesAsync(client, null, new List <CorsRule>() { ruleSingleAllowedPrefixHeader }); await this.TestCorsRulesAsync(client, null, new List <CorsRule>() { ruleAllowAll }); // Empty rule set should delete all rules await this.TestCorsRulesAsync(client, null, new List <CorsRule>() { }); // Test duplicate rules await this.TestCorsRulesAsync(client, null, new List <CorsRule>() { ruleBasic, ruleBasic }); // Test max number of rules (five) await this.TestCorsRulesAsync( client, null, new List <CorsRule>() { ruleBasic, ruleMinRequired, ruleAllMethods, ruleSingleExposedHeader, ruleSingleExposedPrefixHeader }); // Test max number of rules + 1 (six) OperationContext context = new OperationContext(); await TestHelper.ExpectedExceptionAsync( async() => await this.TestCorsRulesAsync( client, context, new List <CorsRule>() { ruleBasic, ruleMinRequired, ruleAllMethods, ruleSingleExposedHeader, ruleSingleExposedPrefixHeader, ruleSingleAllowedHeader }), context, "Services are limited to a maximum of five CORS rules.", HttpStatusCode.BadRequest, "InvalidXmlDocument"); }
internal CloudQueue(IDictionary <string, string> metadata, string queueName, CloudQueueClient serviceClient) { throw new System.NotImplementedException(); }
public static async Task MyClassInitialize(TestContext testContext) { CloudQueueClient client = GenerateCloudQueueClient(); startProperties = await client.GetServicePropertiesAsync(); }
public void CloudQueueMessageEncryptionWithStrictMode() { // Create the Key to be used for wrapping. SymmetricKey aesKey = new SymmetricKey("symencryptionkey"); // Create the resolver to be used for unwrapping. DictionaryKeyResolver resolver = new DictionaryKeyResolver(); resolver.Add(aesKey); CloudQueueClient client = GenerateCloudQueueClient(); string name = GenerateNewQueueName(); CloudQueue queue = client.GetQueueReference(name); try { queue.CreateIfNotExists(); string messageStr = Guid.NewGuid().ToString(); CloudQueueMessage message = new CloudQueueMessage(messageStr); QueueEncryptionPolicy policy = new QueueEncryptionPolicy(aesKey, null); // Add message with policy. QueueRequestOptions createOptions = new QueueRequestOptions() { EncryptionPolicy = policy }; createOptions.RequireEncryption = true; queue.AddMessage(message, null, null, createOptions, null); // Set policy to null and add message while RequireEncryption flag is still set to true. This should throw. createOptions.EncryptionPolicy = null; TestHelper.ExpectedException <InvalidOperationException>( () => queue.AddMessage(message, null, null, createOptions, null), "Not specifying a policy when RequireEnryption is set to true should throw."); // Retrieve message QueueEncryptionPolicy retrPolicy = new QueueEncryptionPolicy(null, resolver); QueueRequestOptions retrieveOptions = new QueueRequestOptions() { EncryptionPolicy = retrPolicy }; retrieveOptions.RequireEncryption = true; CloudQueueMessage retrMessage = queue.GetMessage(null, retrieveOptions, null); // Update message with plain text. string updatedMessage = Guid.NewGuid().ToString("N"); retrMessage.SetMessageContent(updatedMessage); queue.UpdateMessage(retrMessage, TimeSpan.FromSeconds(0), MessageUpdateFields.Content | MessageUpdateFields.Visibility); // Retrieve updated message with RequireEncryption flag but no metadata on the service. This should throw. TestHelper.ExpectedException <StorageException>( () => queue.GetMessage(null, retrieveOptions, null), "Retrieving with RequireEncryption set to true and no metadata on the service should fail."); // Set RequireEncryption to false and retrieve. retrieveOptions.RequireEncryption = false; queue.GetMessage(null, retrieveOptions, null); } finally { queue.DeleteIfExists(); } }
public async Task QueueRegionalSASTestAsync() { #if ASPNET_K //CultureInfo currentCulture = CultureInfo.CurrentCulture; //CultureInfo.CurrentCulture = new CultureInfo("it"); #else string currentPrimaryLanguage = ApplicationLanguages.PrimaryLanguageOverride; ApplicationLanguages.PrimaryLanguageOverride = "it"; #endif CloudQueueClient client = GenerateCloudQueueClient(); CloudQueue queue = client.GetQueueReference(GenerateNewQueueName()); try { await queue.CreateAsync(); string messageContent = Guid.NewGuid().ToString(); CloudQueueMessage message = new CloudQueueMessage(messageContent); await queue.AddMessageAsync(message); // Prepare SAS authentication with full permissions string id = Guid.NewGuid().ToString(); DateTime start = DateTime.UtcNow; DateTime expiry = start.AddMinutes(30); QueuePermissions permissions = new QueuePermissions(); SharedAccessQueuePermissions queuePerm = SharedAccessQueuePermissions.Add | SharedAccessQueuePermissions.ProcessMessages | SharedAccessQueuePermissions.Read | SharedAccessQueuePermissions.Update; permissions.SharedAccessPolicies.Add(id, new SharedAccessQueuePolicy() { SharedAccessStartTime = start, SharedAccessExpiryTime = expiry, Permissions = queuePerm }); await queue.SetPermissionsAsync(permissions); await Task.Delay(30 * 1000); string sasTokenFromId = queue.GetSharedAccessSignature(null, id); StorageCredentials sasCredsFromId = new StorageCredentials(sasTokenFromId); CloudQueue sasQueueFromId = new CloudQueue(queue.Uri, sasCredsFromId); CloudQueueMessage receivedMessage1 = await sasQueueFromId.PeekMessageAsync(); Assert.AreEqual(messageContent, receivedMessage1.AsString); string sasTokenFromPolicy = queue.GetSharedAccessSignature(permissions.SharedAccessPolicies[id], null); StorageCredentials sasCredsFromPolicy = new StorageCredentials(sasTokenFromPolicy); CloudQueue sasQueueFromPolicy = new CloudQueue(queue.Uri, sasCredsFromPolicy); CloudQueueMessage receivedMessage2 = await sasQueueFromPolicy.PeekMessageAsync(); Assert.AreEqual(messageContent, receivedMessage2.AsString); } finally { #if ASPNET_K //CultureInfo.CurrentCulture = currentCulture; #else ApplicationLanguages.PrimaryLanguageOverride = currentPrimaryLanguage; #endif queue.DeleteAsync().Wait(); } }
internal static QueueRequestOptions ApplyDefaults(QueueRequestOptions options, CloudQueueClient serviceClient) { QueueRequestOptions modifiedOptions = new QueueRequestOptions(options); modifiedOptions.RetryPolicy = modifiedOptions.RetryPolicy ?? serviceClient.RetryPolicy; modifiedOptions.ServerTimeout = modifiedOptions.ServerTimeout ?? serviceClient.ServerTimeout; modifiedOptions.MaximumExecutionTime = modifiedOptions.MaximumExecutionTime ?? serviceClient.MaximumExecutionTime; return(modifiedOptions); }
private AzureStorageHelper(string connectionString) { _storageAccount = CloudStorageAccount.Parse(connectionString); _tableClient = _storageAccount.CreateCloudTableClient(); _queueClient = _storageAccount.CreateCloudQueueClient(); }
/// <summary> /// Initializes a new instance of the <see cref="CloudQueue"/> class. /// </summary> /// <param name="queueName">The queue name.</param> /// <param name="serviceClient">A client object that specifies the endpoint for the Queue service.</param> internal CloudQueue(string queueName, CloudQueueClient serviceClient) : this(new Dictionary <string, string>(), queueName, serviceClient) { }