コード例 #1
0
        private List <SyntaxTree> CompileSource(IReadOnlyCollection <AbstractFunctionDefinition> functionDefinitions,
                                                OpenApiOutputModel openApiOutputModel,
                                                Type functionAppConfigurationType,
                                                string newAssemblyNamespace,
                                                string outputAuthoredSourceFolder)
        {
            List <SyntaxTree> syntaxTrees   = new List <SyntaxTree>();
            DirectoryInfo     directoryInfo = outputAuthoredSourceFolder != null ? new DirectoryInfo(outputAuthoredSourceFolder) : null;

            if (directoryInfo != null && !directoryInfo.Exists)
            {
                directoryInfo = null;
            }
            foreach (AbstractFunctionDefinition functionDefinition in functionDefinitions)
            {
                string templateSource = _templateProvider.GetCSharpTemplate(functionDefinition);
                AddSyntaxTreeFromHandlebarsTemplate(templateSource, functionDefinition.Name, functionDefinition, directoryInfo, syntaxTrees);
            }

            if (openApiOutputModel != null && openApiOutputModel.IsConfiguredForUserInterface)
            {
                string templateSource = _templateProvider.GetTemplate("swaggerui", "csharp");
                AddSyntaxTreeFromHandlebarsTemplate(templateSource, "SwaggerUi", new
                {
                    Namespace = newAssemblyNamespace
                }, directoryInfo, syntaxTrees);
            }

            // Now we need to create a class that references the assembly with the configuration builder
            // otherwise the reference will be optimised away by Roslyn and it will then never get loaded
            // by the function host - and so at runtime the builder with the runtime info in won't be located
            string linkBackTemplateSource          = _templateProvider.GetCSharpLinkBackTemplate();
            Func <object, string> linkBackTemplate = Handlebars.Compile(linkBackTemplateSource);
            LinkBackModel         linkBackModel    = new LinkBackModel
            {
                ConfigurationTypeName = functionAppConfigurationType.EvaluateType(),
                Namespace             = newAssemblyNamespace
            };
            string outputLinkBackCode = linkBackTemplate(linkBackModel);

            OutputDiagnosticCode(directoryInfo, "ReferenceLinkBack", outputLinkBackCode);
            SyntaxTree linkBackSyntaxTree = CSharpSyntaxTree.ParseText(outputLinkBackCode);

            syntaxTrees.Add(linkBackSyntaxTree);

            return(syntaxTrees);
        }
コード例 #2
0
        private List <SyntaxTree> CompileSource(IReadOnlyCollection <AbstractFunctionDefinition> functionDefinitions,
                                                OpenApiOutputModel openApiOutputModel,
                                                Type backlinkType,
                                                PropertyInfo backlinkPropertyInfo,
                                                string newAssemblyNamespace,
                                                string outputAuthoredSourceFolder)
        {
            List <SyntaxTree> syntaxTrees   = new List <SyntaxTree>();
            DirectoryInfo     directoryInfo = outputAuthoredSourceFolder != null ? new DirectoryInfo(outputAuthoredSourceFolder) : null;

            if (directoryInfo != null && !directoryInfo.Exists)
            {
                directoryInfo = null;
            }
            foreach (AbstractFunctionDefinition functionDefinition in functionDefinitions)
            {
                string templateSource = _templateProvider.GetCSharpTemplate(functionDefinition);
                AddSyntaxTreeFromHandlebarsTemplate(templateSource, functionDefinition.Name, functionDefinition, directoryInfo, syntaxTrees);
            }

            if (openApiOutputModel != null && openApiOutputModel.IsConfiguredForUserInterface)
            {
                string templateSource = _templateProvider.GetTemplate("swaggerui", "csharp");
                AddSyntaxTreeFromHandlebarsTemplate(templateSource, "SwaggerUi", new
                {
                    Namespace = newAssemblyNamespace
                }, directoryInfo, syntaxTrees);
            }

            {
                string templateSource = _templateProvider.GetTemplate("startup", "csharp");
                AddSyntaxTreeFromHandlebarsTemplate(templateSource, "Startup", new
                {
                    Namespace = newAssemblyNamespace
                }, directoryInfo, syntaxTrees);
            }

            CreateLinkBack(functionDefinitions, backlinkType, backlinkPropertyInfo, newAssemblyNamespace, directoryInfo, syntaxTrees);

            return(syntaxTrees);
        }