public void ReadFunctionMetadata_Succeeds()
        {
            var config = new ScriptHostConfiguration
            {
                RootScriptPath = Path.Combine(Environment.CurrentDirectory, @"..\..\..\..\sample")
            };
            var traceWriter    = new TestTraceWriter(TraceLevel.Verbose);
            var functionErrors = new Dictionary <string, Collection <string> >();
            var metadata       = ScriptHost.ReadFunctionMetadata(config, traceWriter, functionErrors);

            Assert.Equal(49, metadata.Count);
        }
Exemplo n.º 2
0
        /// <summary>
        /// maps a functionName to its FunctionMetadataResponse
        /// </summary>
        /// <param name="name">Function name to retrieve</param>
        /// <param name="request">Current HttpRequest</param>
        /// <returns>(success, FunctionMetadataResponse)</returns>
        public async Task <(bool, FunctionMetadataResponse)> TryGetFunction(string name, HttpRequest request)
        {
            var functionMetadata = ScriptHost.ReadFunctionMetadata(Path.Combine(_config.RootScriptPath, name), new Dictionary <string, Collection <string> >(), fileSystem: FileUtility.Instance);

            if (functionMetadata != null)
            {
                return(true, await functionMetadata.ToFunctionMetadataResponse(request, _config));
            }
            else
            {
                return(false, null);
            }
        }
        public static FunctionMetadata GetFunctionMetadata(string functionName)
        {
            var functionErrors = new Dictionary <string, Collection <string> >();
            var functions      = ScriptHost.ReadFunctionMetadata(new ScriptHostConfiguration(), new ConsoleTraceWriter(System.Diagnostics.TraceLevel.Info), null, functionErrors);
            var function       = functions.FirstOrDefault(f => f.Name.Equals(functionName, StringComparison.OrdinalIgnoreCase));

            if (function == null)
            {
                var error = functionErrors
                            .FirstOrDefault(f => f.Key.Equals(functionName, StringComparison.OrdinalIgnoreCase))
                            .Value
                            ?.Aggregate(string.Empty, (a, b) => string.Join(Environment.NewLine, a, b));
                throw new FunctionNotFoundException($"Unable to get metadata for function {functionName}. Error: {error}");
            }
            else
            {
                return(function);
            }
        }
        public static FunctionMetadata GetFunctionMetadata(string functionName)
        {
            var functionErrors = new Dictionary <string, Collection <string> >();
            var functions      = ScriptHost.ReadFunctionMetadata(new ScriptHostConfiguration(), new ColoredConsoleLogger(LogCategories.Startup, (cat, level) => level >= Microsoft.Extensions.Logging.LogLevel.Information), functionErrors);
            var function       = functions.FirstOrDefault(f => f.Name.Equals(functionName, StringComparison.OrdinalIgnoreCase));

            if (function == null)
            {
                var error = functionErrors
                            .FirstOrDefault(f => f.Key.Equals(functionName, StringComparison.OrdinalIgnoreCase))
                            .Value
                            ?.Aggregate(string.Empty, (a, b) => string.Join(Environment.NewLine, a, b));
                throw new FunctionNotFoundException($"Unable to get metadata for function {functionName}. Error: {error}");
            }
            else
            {
                return(function);
            }
        }