/// <summary> /// Calls a function by its number /// </summary> /// <param name="functionNumber"> /// The number of the function /// </param> /// <param name="self"> /// The self. /// </param> /// <param name="caller"> /// The caller. /// </param> /// <param name="target"> /// The target. /// </param> /// <param name="arguments"> /// The arguments. /// </param> /// <returns> /// </returns> public bool CallFunction( int functionNumber, INamedEntity self, INamedEntity caller, IInstancedEntity target, MessagePackObject[] arguments) { FunctionPrototype func = this.GetFunctionByNumber(functionNumber); if (func != null) { if (Program.DebugGameFunctions) { LogUtil.Debug("Called " + func.GetType().Name + ": "); LogUtil.Debug(FunctionArgumentList.List(arguments)); } return(func.Execute(self, caller, target, arguments)); } if (Program.DebugGameFunctions) { LogUtil.Debug("Function " + (FunctionType)functionNumber + "(" + functionNumber + ")" + " not found!"); LogUtil.Debug(FunctionArgumentList.List(arguments)); } return(false); }
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 async Task <object> InvokeAsync(FunctionArgumentList arguments, TraceWriter log) { var m = Function.Method; using (var scope = Function.Activator.CreateScope(this)) { object userQuery; using (new LoaderLock(ApplicationBase)) { // the user query constructor must run with a loader like lock // this is because there's no other way for us to inject context // in a reliable manner userQuery = scope.CreateInstance(); // pass application base? } var result = m.Invoke(userQuery, arguments.Apply(Function.ParameterBindings)); var task = result as Task; if (task != null) { await task; // do not exit activation scope until task is finished } return(result); } }
public void AddFunction(string functionName, FunctionArgumentList argList, string expression) { var fc = new FunctionClass { Arguments = argList, Expression = expression, Name = functionName }; var numClass = new NumberClass { NumberType = NumberClass.NumberTypes.Expression, Expression = expression }; EvaluateFunction(numClass, fc); _functions.Add(fc); }
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); }