private IStorageQueueMessage ConvertStringToCloudQueueMessage(string arg, QueueAttribute attrResolved) { IStorageQueue queue = GetQueue(attrResolved); var msg = queue.CreateMessage(arg); return(msg); }
private static void Atten() { ThreadPool.QueueUserWorkItem((x) => { DateTime time = QueueAttribute.StartDate; int index = 0; while (true) { DateTime currentTime = DateTime.Now; DateTime tempTime = time.AddMinutes(2); if (currentTime.Hour == time.Hour && currentTime.Minute == time.Minute && index == 0) { QueueAttribute.Atten(); index = 1; } else { Thread.Sleep(3000); } if (tempTime.Hour == currentTime.Hour && tempTime.Minute == currentTime.Minute && index == 1) { index = 0; } } }); }
public async Task <IBinding> TryCreateAsync(BindingProviderContext context) { ParameterInfo parameter = context.Parameter; QueueAttribute queueAttribute = parameter.GetCustomAttribute <QueueAttribute>(inherit: false); if (queueAttribute == null) { return(null); } string queueName = Resolve(queueAttribute.QueueName); IBindableQueuePath path = BindableQueuePath.Create(queueName); path.ValidateContractCompatibility(context.BindingDataContract); IArgumentBinding <IStorageQueue> argumentBinding = _innerProvider.TryCreate(parameter); if (argumentBinding == null) { throw new InvalidOperationException("Can't bind Queue to type '" + parameter.ParameterType + "'."); } IStorageAccount account = await _accountProvider.GetStorageAccountAsync(context.Parameter, context.CancellationToken); StorageClientFactoryContext clientFactoryContext = new StorageClientFactoryContext { Parameter = parameter }; IStorageQueueClient client = account.CreateQueueClient(clientFactoryContext); IBinding binding = new QueueBinding(parameter.Name, argumentBinding, client, path); return(binding); }
private static IStorageQueue GetQueue(QueueAttribute attrResolved) { var attr = (ResolvedQueueAttribute)attrResolved; IStorageQueue queue = attr.GetQueue(); return(queue); }
public void OnStateElection_OverridesTheQueue_OfTheCandidateState() { var filter = new QueueAttribute("override"); filter.OnStateElection(_context.Object); Assert.Equal("override", ((EnqueuedState)_context.Object.CandidateState).Queue); }
private IStorageQueueMessage ConvertByteArrayToCloudQueueMessage(byte[] arg, QueueAttribute attrResolved) { IStorageQueue queue = GetQueue(attrResolved); var msg = queue.CreateMessage(arg); return(msg); }
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864 public void ConfigureAuth(IAppBuilder app) { var name = String.Format( "{0}.{1}", Environment.MachineName, Guid.NewGuid().ToString()); var options = new SQLiteStorageOptions(); GlobalConfiguration.Configuration.UseSQLiteStorage("SQLiteHangfire", options); var option = new BackgroundJobServerOptions { ServerName = name, WorkerCount = 1, SchedulePollingInterval = TimeSpan.FromMinutes(1), Queues = new[] { "run", "delete", "deletefile" } }; QueueAttribute queue = new QueueAttribute("run"); RecurringJob.AddOrUpdate("run", () => Run(), "* * * * *", queue: "run"); RecurringJob.AddOrUpdate("delete", () => Delete(), "0 0 1 */6 *", queue: "delete"); RecurringJob.AddOrUpdate("deletefile", () => DeleteFile(), "0 0 * * *", queue: "deletefile"); app.UseHangfireDashboard(); app.UseHangfireServer(option); }
internal IStorageQueue GetQueue(QueueAttribute attrResolved) { // Avoid using the sync over async pattern (Async().GetAwaiter().GetResult()) whenever possible var account = _accountProvider.GetStorageAccountAsync(attrResolved, CancellationToken.None).GetAwaiter().GetResult(); return(GetQueue(attrResolved, account)); }
private async Task <IStorageQueue> BuildClientFromQueueAttributeAsync(QueueAttribute attrResolved) { IStorageQueue queue = GetQueue(attrResolved); await queue.CreateIfNotExistsAsync(CancellationToken.None); return(queue); }
public static async Task <IActionResult> Run( [HttpTrigger( AuthorizationLevel.Function, nameof(HttpMethods.Post), Route = null)] Player player, IBinder binder) { var serializedPlayer = JsonConvert.SerializeObject(player); var cloudQueueMessage = new CloudQueueMessage(serializedPlayer); // Not WindowsAzure.Storage.Queue! IActionResult result = null; if (string.IsNullOrEmpty(player.Id)) { var queueAttribute = new QueueAttribute(QueueConfig.NewPlayerErrorItems); var cloudQueue = await binder.BindAsync <CloudQueue>(queueAttribute); await cloudQueue.AddMessageAsync(cloudQueueMessage); result = new BadRequestObjectResult("No player data in request."); } else { var queueAttribute = new QueueAttribute(QueueConfig.NewPlayerItems); var cloudQueue = await binder.BindAsync <CloudQueue>(queueAttribute); await cloudQueue.AddMessageAsync(cloudQueueMessage); result = new AcceptedResult(); } return(result); }
public override Collection <Attribute> GetAttributes() { Collection <Attribute> attributes = new Collection <Attribute>(); string queueName = Context.GetMetadataValue <string>("queueName"); Attribute attribute = null; if (Context.IsTrigger) { attribute = new QueueTriggerAttribute(queueName); } else { attribute = new QueueAttribute(queueName); } attributes.Add(attribute); var connectionProvider = (IConnectionProvider)attribute; string connection = Context.GetMetadataValue <string>("connection"); if (!string.IsNullOrEmpty(connection)) { connectionProvider.Connection = connection; } return(attributes); }
public override async Task BindAsync(BindingContext context) { string boundQueueName = QueueName; if (context.BindingData != null) { boundQueueName = _queueNameBindingTemplate.Bind(context.BindingData); } boundQueueName = Resolve(boundQueueName); var attribute = new QueueAttribute(boundQueueName); Attribute[] additionalAttributes = null; if (!string.IsNullOrEmpty(Metadata.Connection)) { additionalAttributes = new Attribute[] { new StorageAccountAttribute(Metadata.Connection) }; } RuntimeBindingContext runtimeContext = new RuntimeBindingContext(attribute, additionalAttributes); await BindAsyncCollectorAsync <string>(context.Value, context.Binder, runtimeContext); }
public void OnStateElection_DoesNotDoAnything_IfStateIsNotEnqueuedState() { var filter = new QueueAttribute("override"); var context = new ElectStateContextMock(); context.ApplyContext.NewState = new Mock<IState>(); Assert.DoesNotThrow(() => filter.OnStateElection(context.Object)); }
// Hook JObject serialization to so we can stamp the object with a causality marker. private static JObject SerializeToJobject(object input, QueueAttribute attrResolved, ValueBindingContext context) { JObject objectToken = JObject.FromObject(input, JsonSerialization.Serializer); var functionInstanceId = context.FunctionInstanceId; QueueCausalityManager.SetOwner(functionInstanceId, objectToken); return(objectToken); }
public void OnStateElection_DoesNotDoAnything_IfStateIsNotEnqueuedState() { var filter = new QueueAttribute("override"); var context = new ElectStateContextMock(); context.CandidateStateValue = new Mock <IState>().Object; Assert.DoesNotThrow(() => filter.OnStateElection(context.Object)); }
internal IStorageQueue GetQueue(QueueAttribute attrResolved, IStorageAccount account) { var client = account.CreateQueueClient(); string queueName = attrResolved.QueueName.ToLowerInvariant(); QueueClient.ValidateQueueName(queueName); return(client.GetQueueReference(queueName)); }
// This is a static validation (so only %% are resolved; not {} ) // For runtime validation, the regular builder functions can do the resolution. private void ValidateQueueAttribute(QueueAttribute attribute, Type parameterType) { string queueName = NormalizeQueueName(attribute, null); // Queue pre-existing behavior: if there are { }in the path, then defer validation until runtime. if (!queueName.Contains("{")) { QueueClient.ValidateQueueName(queueName); } }
internal QueueClient GetQueue(QueueAttribute attrResolved) { var client = _queueServiceClientProvider.Get(attrResolved.Connection); string queueName = attrResolved.QueueName.ToLowerInvariant(); QueueClientExtensions.ValidateQueueName(queueName); return(client.GetQueueClient(queueName)); }
public void OnStateElection_DoesNotDoAnything_IfStateIsNotEnqueuedState() { var filter = new QueueAttribute("override"); var context = new ElectStateContextMock { ApplyContext = { NewState = new Mock <IState>() } }; // Does not throw filter.OnStateElection(context.Object); }
public void OnStateElection_DoesNotDoAnything_IfStateIsNotEnqueuedState() { var filter = new QueueAttribute("override"); var context = new ElectStateContextMock { ApplyContext = { NewState = new Mock<IState>() } }; // Does not throw filter.OnStateElection(context.Object); }
internal IStorageQueue GetQueue(QueueAttribute attrResolved) { var account = Task.Run(() => this._accountProvider.GetStorageAccountAsync(attrResolved, CancellationToken.None)).GetAwaiter().GetResult(); var client = account.CreateQueueClient(); string queueName = attrResolved.QueueName.ToLowerInvariant(); QueueClient.ValidateQueueName(queueName); return(client.GetQueueReference(queueName)); }
private static string NormalizeQueueName(QueueAttribute attribute, INameResolver nameResolver) { string queueName = attribute.QueueName; if (nameResolver != null) { queueName = nameResolver.ResolveWholeString(queueName); } queueName = queueName.ToLowerInvariant(); // must be lowercase. coerce here to be nice. return(queueName); }
internal async Task <IStorageQueue> GetQueueAsync(QueueAttribute attrResolved) { var account = await _accountProvider.GetStorageAccountAsync(attrResolved, CancellationToken.None); var client = account.CreateQueueClient(); string queueName = attrResolved.QueueName.ToLowerInvariant(); QueueClient.ValidateQueueName(queueName); return(client.GetQueueReference(queueName)); }
private ParameterDescriptor ToParameterDescriptorForCollector(QueueAttribute attr, ParameterInfo parameter, INameResolver nameResolver, FileAccess access) { var account = _accountProvider.Get(attr.Connection, nameResolver); var accountName = account.Name; return(new QueueParameterDescriptor { Name = parameter.Name, AccountName = accountName, QueueName = NormalizeQueueName(attr, nameResolver), Access = access }); }
// [Queue] has some pre-existing behavior where the storage account can be specified outside of the [Queue] attribute. // The storage account is pulled from the ParameterInfo (which could pull in a [Storage] attribute on the container class) // Resolve everything back down to a single attribute so we can use the binding helpers. // This pattern should be rare since other extensions can just keep everything directly on the primary attribute. private async Task <QueueAttribute> CollectAttributeInfo(QueueAttribute attrResolved, ParameterInfo parameter, INameResolver nameResolver) { // Look for [Storage] attribute and squirrel over IStorageAccount account = await _accountProvider.GetStorageAccountAsync(parameter, CancellationToken.None, nameResolver); StorageClientFactoryContext clientFactoryContext = new StorageClientFactoryContext { Parameter = parameter }; IStorageQueueClient client = account.CreateQueueClient(clientFactoryContext); return(new ResolvedQueueAttribute(attrResolved.QueueName, client)); }
internal Task <CloudQueue> GetQueueAsync(QueueAttribute attrResolved) { // var account = await _accountProvider.GetStorageAccountAsync(attrResolved, CancellationToken.None); var account = _accountProvider.Get(attrResolved.Connection); var client = account.CreateCloudQueueClient(); string queueName = attrResolved.QueueName.ToLowerInvariant(); QueueClient.ValidateQueueName(queueName); var queue = client.GetQueueReference(queueName); return(Task.FromResult(queue)); }
private void DeclareQueue(IModel channel, ExchangeAttribute exchange, QueueAttribute queue) { channel.QueueDeclare(queue: queue.Name, durable: true, exclusive: false, autoDelete: false, arguments: null); if (exchange.Name != string.Empty) { channel.ExchangeDeclare(exchange: exchange.Name, type: exchange.ExchangeType, durable: true, autoDelete: false, arguments: null); foreach (var routingKey in queue.RoutingKeys) { channel.QueueBind(queue: queue.Name, exchange: exchange.Name, routingKey: routingKey, arguments: null); } } }
private ParameterDescriptor ToParameterDescriptorForCollector(QueueAttribute attr, ParameterInfo parameter, INameResolver nameResolver, FileAccess access) { // Avoid using the sync over async pattern (Async().GetAwaiter().GetResult()) whenever possible IStorageAccount account = _accountProvider.GetStorageAccountAsync(attr, CancellationToken.None, nameResolver).GetAwaiter().GetResult(); string accountName = account.Credentials.AccountName; return(new QueueParameterDescriptor { Name = parameter.Name, AccountName = accountName, QueueName = NormalizeQueueName(attr, nameResolver), Access = access }); }
public EventBusConventions(ITypeNameSerializer typeNameSerializer) : base(typeNameSerializer) { ExchangeNamingConvention = type => { QueueAttribute MyAttribute = (QueueAttribute)Attribute.GetCustomAttribute(type, typeof(QueueAttribute)); return(MyAttribute.ExchangeName); }; RpcRoutingKeyNamingConvention = type => { QueueAttribute MyAttribute = (QueueAttribute)Attribute.GetCustomAttribute(type, typeof(QueueAttribute)); return(MyAttribute.QueueName); }; //ErrorQueueNamingConvention = info => "ErrorQueue"; //ErrorExchangeNamingConvention = info => "BusErrorExchange_" + info.RoutingKey + assemblyName; }
public async Task BindAsyncCollectorAsync_JObjectCollection() { JArray values = new JArray(); for (int i = 1; i <= 3; i++) { JObject jsonObject = new JObject { { "prop1", "value1" }, { "prop2", true }, { "prop3", 123 } }; values.Add(jsonObject); } string json = values.ToString(); var results = new JArray(); var collectorMock = new Mock <IAsyncCollector <JObject> >(MockBehavior.Strict); collectorMock.Setup(p => p.AddAsync(It.IsAny <JObject>(), CancellationToken.None)) .Callback <JObject, CancellationToken>((mockObject, mockToken) => { results.Add(mockObject); }).Returns(Task.CompletedTask); var binderMock = new Mock <IBinderEx>(MockBehavior.Strict); QueueAttribute attribute = new QueueAttribute("test"); RuntimeBindingContext runtimeBindingContext = new RuntimeBindingContext(attribute); binderMock.Setup(p => p.BindAsync <IAsyncCollector <JObject> >(runtimeBindingContext, CancellationToken.None)).ReturnsAsync(collectorMock.Object); BindingContext bindingContext = new BindingContext { Binder = binderMock.Object, Value = json }; await FunctionBinding.BindAsyncCollectorAsync <JObject>(bindingContext, runtimeBindingContext); Assert.Equal(3, results.Count); for (int i = 0; i < 3; i++) { JObject jsonObject = (JObject)results[i]; Assert.Equal("value1", (string)jsonObject["prop1"]); Assert.Equal(true, (bool)jsonObject["prop2"]); Assert.Equal(123, (int)jsonObject["prop3"]); } }
public static async Task ReQueueAvailableVstsInstance( [QueueTrigger("vstspendingavailableinstances", Connection = "SkillsBundleTablesConnectionsString")] string pendingInstance, IBinder binder, ILogger log) { var VstsInstanceService = new VstsInstanceService(Environment.GetEnvironmentVariable("SkillsBundleTablesConnectionsString")); var vstsInstanceEntity = await VstsInstanceService.Get(pendingInstance); var queueAttribute = new QueueAttribute($"vstsavailableinstances-{vstsInstanceEntity.Region}"); queueAttribute.Connection = "SkillsBundleTablesConnectionsString"; var queue = await binder.BindAsync <CloudQueue>(queueAttribute); await queue.AddMessageAsync(new CloudQueueMessage(pendingInstance)); }
private ParameterDescriptor ToParameterDescriptorForCollector(QueueAttribute attr, ParameterInfo parameter, INameResolver nameResolver, FileAccess access) { Task <IStorageAccount> t = Task.Run(() => _accountProvider.GetStorageAccountAsync(parameter, CancellationToken.None, nameResolver)); IStorageAccount account = t.GetAwaiter().GetResult(); string accountName = account.Credentials.AccountName; return(new QueueParameterDescriptor { Name = parameter.Name, AccountName = accountName, QueueName = NormalizeQueueName(attr, nameResolver), Access = access }); }
public override async Task BindAsync(BindingContext context) { string boundQueueName = QueueName; if (context.BindingData != null) { boundQueueName = _queueNameBindingTemplate.Bind(context.BindingData); } boundQueueName = Resolve(boundQueueName); var attribute = new QueueAttribute(boundQueueName); Attribute[] additionalAttributes = null; if (!string.IsNullOrEmpty(Metadata.Connection)) { additionalAttributes = new Attribute[] { new StorageAccountAttribute(Metadata.Connection) }; } RuntimeBindingContext runtimeContext = new RuntimeBindingContext(attribute, additionalAttributes); await BindAsyncCollectorAsync<string>(context.Value, context.Binder, runtimeContext); }
public void Ctor_CorrectlySets_AllPropertyValues() { var filter = new QueueAttribute("hello"); Assert.Equal("hello", filter.Queue); }