public static async Task Run(CloudQueueMessage msg, System.Threading.CancellationToken cancellationToken, ExecutionContext executionContext, // note that this name is also found in namespace "System.Threading" we don't want that TraceWriter log) { var func = await FunctionExecutor.GetAndInvalidateAsync(executionContext.FunctionDirectory, log); var arguments = new FunctionArgumentList(); // queue message type var parameters = func.Function.Method.GetParameters(); var parameter0Type = parameters[0].ParameterType; if (parameter0Type != typeof(CloudQueueMessage)) { arguments.AddArgument(parameter0Type, JsonConvert.DeserializeObject(msg.AsString, parameter0Type)); } arguments.AddArgument(typeof(CloudQueueMessage), msg); // common arguments.AddArgument(typeof(System.Threading.CancellationToken), cancellationToken); arguments.AddArgument(typeof(ITraceWriter), new TraceWriterWrapper(log)); var cloudStorageHelperType = typeof(ICloudStorage); if (func.Function.ParameterBindings.HasBinding(cloudStorageHelperType)) { arguments.AddArgument(cloudStorageHelperType, new CloudStorage(CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("AzureWebJobsStorage")))); } await func.InvokeAsync(arguments, log); }
public static async Task <HttpResponseMessage> Run( HttpRequestMessage req, System.Threading.CancellationToken cancellationToken, ExecutionContext executionContext, // note that this name is also found in namespace "System.Threading" we don't want that TraceWriter log) { var func = await FunctionExecutor.GetAndInvalidateAsync(executionContext.FunctionDirectory, log); var arguments = new FunctionArgumentList(); arguments.AddArgument(typeof(HttpRequestMessage), req); arguments.AddArgument(typeof(System.Threading.CancellationToken), cancellationToken); arguments.AddArgument(typeof(ITraceWriter), new TraceWriterWrapper(log)); var cloudStorageHelperType = typeof(ICloudStorage); if (func.Function.ParameterBindings.HasBinding(cloudStorageHelperType)) { arguments.AddArgument(cloudStorageHelperType, new CloudStorage(CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("AzureWebJobsStorage")))); } object result; try { result = await func.InvokeAsync(arguments, log); } catch (ArgumentException ex) { // special sauce for HTTP trigger log.Error(ex.Message, ex); return(req.CreateResponse(HttpStatusCode.BadRequest, new { ok = false, message = ex.Message })); } catch { throw; } var taskWithValue = result as Task <HttpResponseMessage>; if (taskWithValue != null) { return(await taskWithValue); // unwrap async http response } var value = result as HttpResponseMessage; if (value != null) { return(value); // return synchronous http response } return(req.CreateResponse(HttpStatusCode.NoContent)); }
public static async Task Run( CloudBlockBlob blob, System.Threading.CancellationToken cancellationToken, ExecutionContext executionContext, // note that this name is also found in namespace "System.Threading" we don't want that TraceWriter log) { var func = await FunctionExecutor.GetAndInvalidateAsync(executionContext.FunctionDirectory, log); var arguments = new FunctionArgumentList(); arguments.AddArgument(typeof(CloudBlockBlob), blob); arguments.AddArgument(typeof(System.Threading.CancellationToken), cancellationToken); arguments.AddArgument(typeof(ITraceWriter), new TraceWriterWrapper(log)); var cloudStorageHelperType = typeof(ICloudStorage); if (func.Function.ParameterBindings.HasBinding(cloudStorageHelperType)) { arguments.AddArgument(cloudStorageHelperType, new CloudStorage(CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("AzureWebJobsStorage")))); } await func.InvokeAsync(arguments, log); }