/// <summary> /// Handles messages of a given query type asynchronously. /// </summary> /// <typeparam name="TQuery">A query type.</typeparam> /// <param name="topic">A topic.</param> /// <param name="handler">An asynchronous handler.</param> /// <returns>A subscription.</returns> public static IDisposable HandleQueryAsync <TQuery>(this ITopic topic, IAsyncHandler <TQuery> handler) where TQuery : IQuery { if (topic == null) { throw new ArgumentNullException(nameof(topic)); } if (handler == null) { throw new ArgumentNullException(nameof(handler)); } return(topic.SubscribeWhen((env) => handler.HandleAsync((TQuery)env.Data), (env) => env.Data is TQuery)); }
/// <summary> /// Handles messages of a given command type asynchronously. /// </summary> /// <typeparam name="TCommand">A command type.</typeparam> /// <param name="topic">A topic.</param> /// <param name="handler">An asynchronous handler.</param> /// <returns>A subscription.</returns> public static IDisposable HandleCommandAsync <TCommand>(this ITopic topic, IAsyncHandler <TCommand> handler) where TCommand : ICommand { if (topic == null) { throw new ArgumentNullException(nameof(topic)); } if (handler == null) { throw new ArgumentNullException(nameof(handler)); } return(topic.SubscribeWhen((env) => handler.HandleAsync((TCommand)env.Data), (env) => env.Data is TCommand)); }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log, [Blob("httptrigger1", FileAccess.Write, Connection = "StorageConnectionString")] CloudBlobContainer cloudBlobContainer, [Queue("queuetrigger1", Connection = "StorageConnectionString")] IAsyncCollector <QueueTrigger1Request> queueTrigger1RequestQueue) { log.LogInformation( "HttpTrigger1 function processed a request."); var httpTrigger1Request = JsonConvert.DeserializeObject <HttpTrigger1Request>( await new StreamReader(req.Body).ReadToEndAsync()); try { var httpTrigger1Response = await _httpTrigger1Handler.HandleAsync( httpTrigger1Request); return(new OkObjectResult( httpTrigger1Response)); } catch (Exception ex) { var blobName = $"{httpTrigger1Request.TransactionId}-{DateTime.UtcNow.ToString().Replace(" ", "").Replace(":", "")}.json"; var cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(blobName); cloudBlockBlob.Properties.ContentType = "application/json"; await cloudBlockBlob.UploadTextAsync( JsonConvert.SerializeObject(httpTrigger1Request, Formatting.Indented)); await queueTrigger1RequestQueue.AddAsync( new QueueTrigger1Request { Recipients = new[] { "*****@*****.**" }, Subject = $"An error was encountered with {nameof(HttpTrigger1)}", Body = ex.ToString() }); throw ex; } }
/// <summary> /// Adds an asynchronous event handler. /// </summary> /// <typeparam name="T">The message type.</typeparam> /// <param name="box">A Postal.NET implementation.</param> /// <param name="handler">The handler.</param> /// <param name="channel">An optional channel.</param> /// <param name="topic">An optional topic.</param> /// <returns>A subscription.</returns> public static IDisposable AddAsyncHandler <T>(this IBox box, IAsyncHandler <T> handler, string channel = null, string topic = null) { if (channel == string.Empty) { channel = null; } if (topic == string.Empty) { topic = null; } return(box .Channel(channel ?? Postal.All) .Topic(topic ?? Postal.All) .SubscribeWhen(async(env) => await handler.HandleAsync((T)env.Data), env => env.Data is T)); }
public Task <TNewOutput> ConvertAsync(IAsyncHandler <TInput, TOutput> handler, TInput input) => handler.HandleAsync(input).ContinueWith(t => (TNewOutput)t.Result);
public Task <TOutput> ConvertAsync(IAsyncHandler <TInput, TOutput> handler, TNewInput input) => handler.HandleAsync(input);