Esempio n. 1
0
        public void Compile()
        {
            IFunctionAppConfiguration configuration = ConfigurationLocator.FindConfiguration(_configurationSourceAssembly);

            if (configuration == null)
            {
                throw new ConfigurationException($"The assembly {_configurationSourceAssembly.GetName().Name} does not contain a public class implementing the IFunctionAppConfiguration interface");
            }

            string newAssemblyNamespace = $"{_configurationSourceAssembly.GetName().Name}.Functions";
            FunctionHostBuilder builder = new FunctionHostBuilder(_serviceCollection, _commandRegistry, false);

            configuration.Build(builder);
            new PostBuildPatcher().Patch(builder, newAssemblyNamespace);

            VerifyCommandAndResponseTypes(builder);

            IReadOnlyCollection <string> externalAssemblies = GetExternalAssemblyLocations(builder.FunctionDefinitions);
            OpenApiOutputModel           openApi            = _openApiCompiler.Compile(builder.OpenApiConfiguration, builder.FunctionDefinitions, _outputBinaryFolder);

            _jsonCompiler.Compile(builder.FunctionDefinitions, openApi, _outputBinaryFolder, newAssemblyNamespace);
            if (_outputProxiesJson && builder.AreProxiesEnabled)
            {
                _proxiesJsonCompiler.Compile(builder.FunctionDefinitions, builder.OpenApiConfiguration, openApi, _outputBinaryFolder);
            }

            _assemblyCompiler.Compile(builder.FunctionDefinitions,
                                      configuration.GetType(),
                                      newAssemblyNamespace,
                                      externalAssemblies,
                                      _outputBinaryFolder,
                                      $"{newAssemblyNamespace}.dll",
                                      openApi,
                                      _target, builder.OutputAuthoredSourceFolder);
        }
Esempio n. 2
0
        private static FunctionHostBuilder CreateBuilderFromConfiguration(ICommandRegistry commandRegistry,
                                                                          IFunctionAppConfiguration configuration)
        {
            FunctionHostBuilder builder = new FunctionHostBuilder(ServiceCollection, commandRegistry, true);

            configuration.Build(builder);
            new PostBuildPatcher().Patch(builder, "");
            return(builder);
        }
Esempio n. 3
0
        private FunctionHostBuilder CreateBuilderFromConfiguration(ICommandRegistry commandRegistry,
                                                                   IFunctionAppConfiguration configuration)
        {
            FunctionHostBuilder builder = new FunctionHostBuilder(ServiceCollection, commandRegistry, true);

            configuration.Build(builder);
            RegisterCommandHandlersForCommandsWithNoAssociatedHandler(builder, commandRegistry);
            new PostBuildPatcher().Patch(builder, "");
            return(builder);
        }
Esempio n. 4
0
        private FunctionHostBuilder CreateBuilderFromConfiguration(
            ICommandRegistry commandRegistry,
            IFunctionAppConfiguration configuration)
        {
            FunctionHostBuilder builder = new FunctionHostBuilder(ServiceCollection, commandRegistry, true);

            configuration.Build(builder);
            DefaultMediatorSettings.SetDefaultsIfRequired(builder);
            RegisterCommandHandlersForCommandsWithNoAssociatedHandler(builder, commandRegistry);
            IMediatorResultTypeExtractor extractor = (IMediatorResultTypeExtractor)Activator.CreateInstance(builder.Options.MediatorResultTypeExtractor);

            new PostBuildPatcher(extractor).Patch(builder, "");
            return(builder);
        }
Esempio n. 5
0
        public bool Compile()
        {
            string newAssemblyNamespace = $"{_configurationSourceAssembly.GetName().Name.Replace("-", "_")}.Functions";
            IFunctionCompilerMetadata functionCompilerMetadata = null;
            IFunctionAppConfiguration configuration            = ConfigurationLocator.FindConfiguration(_configurationSourceAssembly);

            if (configuration == null)
            {
                functionCompilerMetadata = ConfigurationLocator.FindCompilerMetadata(_configurationSourceAssembly);
                if (functionCompilerMetadata == null)
                {
                    _compilerLog.Error($"The assembly {_configurationSourceAssembly.GetName().Name} does not contain a public class implementing the IFunctionAppConfiguration interface");
                    return(false);
                }
            }
            else
            {
                FunctionHostBuilder builder = new FunctionHostBuilder(_serviceCollection, _commandRegistry, false);
                configuration.Build(builder);
                new PostBuildPatcher().Patch(builder, newAssemblyNamespace);
                if (!VerifyCommandAndResponseTypes(builder))
                {
                    return(false);
                }

                functionCompilerMetadata = new FunctionCompilerMetadata
                {
                    FunctionDefinitions        = builder.FunctionDefinitions,
                    OpenApiConfiguration       = builder.OpenApiConfiguration,
                    OutputAuthoredSourceFolder = builder.OutputAuthoredSourceFolder
                };
            }

            IReadOnlyCollection <string> externalAssemblies = GetExternalAssemblyLocations(functionCompilerMetadata.FunctionDefinitions);
            OpenApiOutputModel           openApi            = _openApiCompiler.Compile(functionCompilerMetadata.OpenApiConfiguration, functionCompilerMetadata.FunctionDefinitions, _outputBinaryFolder);

            _jsonCompiler.Compile(functionCompilerMetadata.FunctionDefinitions, openApi, _outputBinaryFolder, newAssemblyNamespace);

            return(_assemblyCompiler.Compile(functionCompilerMetadata.FunctionDefinitions,
                                             configuration?.GetType() ?? functionCompilerMetadata.BacklinkReferenceType,
                                             configuration != null ? null : functionCompilerMetadata.BacklinkPropertyInfo,
                                             newAssemblyNamespace,
                                             externalAssemblies,
                                             _outputBinaryFolder,
                                             $"{newAssemblyNamespace}.dll",
                                             openApi,
                                             _compileTarget, functionCompilerMetadata.OutputAuthoredSourceFolder));
        }
Esempio n. 6
0
        public bool Compile()
        {
            string newAssemblyNamespace = $"{_configurationSourceAssembly.GetName().Name.Replace("-", "_")}.Functions";
            IFunctionCompilerMetadata functionCompilerMetadata = null;

            IFunctionAppConfiguration configuration  = null;
            FunctionAppHostBuilder    appHostBuilder = null;
            IFunctionAppHost          appHost        = ConfigurationLocator.FindFunctionAppHost(_configurationSourceAssembly);

            if (appHost != null)
            {
                appHostBuilder = new FunctionAppHostBuilder();
                appHost.Build(appHostBuilder);
                if (appHostBuilder.FunctionAppConfiguration != null)
                {
                    configuration = (IFunctionAppConfiguration)Activator.CreateInstance(appHostBuilder.FunctionAppConfiguration);
                }
            }

            if (configuration == null)
            {
                configuration = ConfigurationLocator.FindConfiguration(_configurationSourceAssembly);
            }

            if (configuration == null)
            {
                functionCompilerMetadata = ConfigurationLocator.FindCompilerMetadata(_configurationSourceAssembly);
                if (functionCompilerMetadata == null)
                {
                    _compilerLog.Error($"The assembly {_configurationSourceAssembly.GetName().Name} does not contain a public class implementing the IFunctionAppConfiguration interface");
                    return(false);
                }
            }
            else
            {
                FunctionHostBuilder builder = new FunctionHostBuilder(_serviceCollection, _commandRegistry, false);
                if (appHostBuilder != null)
                {
                    builder.Options = appHostBuilder.Options;
                }
                configuration.Build(builder);
                DefaultMediatorSettings.SetDefaultsIfRequired(builder);
                if (!ValidateCommandTypes(builder))
                {
                    return(false);
                }
                IMediatorResultTypeExtractor extractor = CreateMediatorResultTypeExtractor(builder.Options.MediatorResultTypeExtractor);
                if (extractor == null)
                {
                    return(false);
                }
                new PostBuildPatcher(extractor).Patch(builder, newAssemblyNamespace);
                if (!VerifyCommandAndResponseTypes(builder))
                {
                    return(false);
                }

                if (!VerifyOutputBindings(builder))
                {
                    return(false);
                }

                functionCompilerMetadata = new FunctionCompilerMetadata
                {
                    FunctionDefinitions        = builder.FunctionDefinitions,
                    OpenApiConfiguration       = builder.OpenApiConfiguration,
                    OutputAuthoredSourceFolder = builder.Options.OutputSourceTo,
                    CompilerOptions            = builder.Options
                };
            }

            PostBuildPatcher.EnsureFunctionsHaveUniqueNames(functionCompilerMetadata.FunctionDefinitions);

            IReadOnlyCollection <string> externalAssemblies =
                GetExternalAssemblyLocations(functionCompilerMetadata.FunctionDefinitions);

            ITargetCompiler targetCompiler = functionCompilerMetadata.CompilerOptions.HttpTarget == CompileTargetEnum.AzureFunctions
                ? (ITargetCompiler) new AzureFunctionsCompiler(_compilerLog)
                : new AspNetCoreCompiler(_compilerLog);

            return(targetCompiler.CompileAssets(functionCompilerMetadata,
                                                newAssemblyNamespace,
                                                configuration,
                                                externalAssemblies,
                                                _outputBinaryFolder));
        }