Пример #1
0
        public IActionResult Invoke(string name, [FromBody] FunctionInvocation invocation, [FromServices] IScriptJobHost scriptHost)
        {
            if (invocation == null)
            {
                return(BadRequest());
            }

            FunctionDescriptor function = scriptHost.GetFunctionOrNull(name);

            if (function == null)
            {
                return(NotFound());
            }

            ParameterDescriptor         inputParameter = function.Parameters.First(p => p.IsTrigger);
            Dictionary <string, object> arguments      = new Dictionary <string, object>()
            {
                { inputParameter.Name, invocation.Input }
            };

            Task.Run(async() =>
            {
                IDictionary <string, object> loggerScope = new Dictionary <string, object>
                {
                    { "MS_IgnoreActivity", null }
                };

                using (_logger.BeginScope(loggerScope))
                {
                    await scriptHost.CallAsync(function.Name, arguments);
                }
            });

            return(Accepted());
        }
Пример #2
0
        public IActionResult Invoke(string name, [FromBody] FunctionInvocation invocation, [FromServices] IScriptJobHost scriptHost)
        {
            if (invocation == null)
            {
                return(BadRequest());
            }

            FunctionDescriptor function = scriptHost.GetFunctionOrNull(name);

            if (function == null)
            {
                return(NotFound());
            }

            ParameterDescriptor         inputParameter = function.Parameters.First(p => p.IsTrigger);
            Dictionary <string, object> arguments      = new Dictionary <string, object>()
            {
                { inputParameter.Name, invocation.Input }
            };
            // LiveLogs session id is used to show only contextual logs in the "Code + Test" experience.
            string sessionId = this.Request?.Headers[ScriptConstants.LiveLogsSessionAIKey];

            using (System.Threading.ExecutionContext.SuppressFlow())
            {
                Task.Run(async() =>
                {
                    IDictionary <string, object> loggerScope = new Dictionary <string, object>
                    {
                        { "MS_IgnoreActivity", null }
                    };

                    using (_logger.BeginScope(loggerScope))
                    {
                        if (!string.IsNullOrWhiteSpace(sessionId))
                        {
                            // Current activity is null due to SuppressFlow. Start a new activity and set baggage so that it's included in the custom dimensions.
                            Activity activity = new Activity($"{nameof(FunctionsController)}.Invoke");
                            activity?.Start();
                            activity?.AddBaggage(ScriptConstants.LiveLogsSessionAIKey, sessionId);
                            try
                            {
                                await scriptHost.CallAsync(function.Name, arguments);
                            }
                            finally
                            {
                                activity?.Stop();
                            }
                        }
                        else
                        {
                            await scriptHost.CallAsync(function.Name, arguments);
                        }
                    }
                });
            }

            return(Accepted());
        }
        public IActionResult Invoke(string name, [FromBody] FunctionInvocation invocation, [FromServices] IScriptJobHost scriptHost)
        {
            if (invocation == null)
            {
                return(BadRequest());
            }

            FunctionDescriptor function = scriptHost.GetFunctionOrNull(name);

            if (function == null)
            {
                return(NotFound());
            }

            ParameterDescriptor         inputParameter = function.Parameters.First(p => p.IsTrigger);
            Dictionary <string, object> arguments      = new Dictionary <string, object>()
            {
                { inputParameter.Name, invocation.Input }
            };

            Task.Run(() => scriptHost.CallAsync(function.Name, arguments));

            return(Accepted());
        }