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); }
private void CreateLinkBack( IReadOnlyCollection <AbstractFunctionDefinition> functionDefinitions, Type backlinkType, PropertyInfo backlinkPropertyInfo, string newAssemblyNamespace, DirectoryInfo directoryInfo, List <SyntaxTree> syntaxTrees) { if (backlinkType == null) { return; // back link referencing has been disabled } // 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 = null; if (backlinkPropertyInfo != null) { linkBackModel = new LinkBackModel { TypeName = backlinkType.EvaluateType(), PropertyName = backlinkPropertyInfo.Name, PropertyTypeName = backlinkPropertyInfo.PropertyType.EvaluateType(), Namespace = newAssemblyNamespace }; } else { linkBackModel = new LinkBackModel { TypeName = backlinkType.EvaluateType(), PropertyName = null, Namespace = newAssemblyNamespace }; } string outputLinkBackCode = linkBackTemplate(linkBackModel); OutputDiagnosticCode(directoryInfo, "ReferenceLinkBack", outputLinkBackCode); SyntaxTree linkBackSyntaxTree = CSharpSyntaxTree.ParseText(outputLinkBackCode); syntaxTrees.Add(linkBackSyntaxTree); }