public static FunctionMetadata GetFunctionMetadata(string functionName)
        {
            var functionErrors = new Dictionary <string, Collection <string> >();
            var functions      = ScriptHost.ReadFunctionsMetadata(Directory.EnumerateDirectories(Environment.CurrentDirectory), 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);
            }
        }
Пример #2
0
 private IEnumerable <FunctionMetadata> GetFunctionsMetadata()
 {
     return(ScriptHost
            .ReadFunctionsMetadata(FileUtility.EnumerateDirectories(_config.RootScriptPath), _logger, new Dictionary <string, Collection <string> >(), fileSystem: FileUtility.Instance));
 }
 /// <summary>
 /// Calls into ScriptHost to retrieve list of FunctionMetadata
 /// and maps them to FunctionMetadataResponse.
 /// </summary>
 /// <param name="request">Current HttpRequest for figuring out baseUrl</param>
 /// <returns>collection of FunctionMetadataResponse</returns>
 public async Task <IEnumerable <FunctionMetadataResponse> > GetFunctionsMetadata(HttpRequest request)
 {
     return(await ScriptHost.ReadFunctionsMetadata(FileUtility.EnumerateDirectories(_config.RootScriptPath), _logger, new Dictionary <string, Collection <string> >())
            .Select(fm => fm.ToFunctionMetadataResponse(request, _config))
            .WhenAll());
 }