private static string BuildExtensionsJson(CallbackFunctionAppArgs args) { return(JsonConvert.SerializeObject(new { extensions = args.Functions.SelectMany(GetExtensionsUsedInFunction) .Distinct() .Where(t => t != typeof(HttpWebJobsStartup)) .Select(e => new { name = e.Name.Replace("WebJobsStartup", ""), typeName = e.AssemblyQualifiedName }) .ToArray() })); }
private static ArchiveFunctionAppArgs Map(CallbackFunctionAppArgs args) { var mapped = new ArchiveFunctionAppArgs { StorageAccount = args.StorageAccount, StorageContainer = args.StorageContainer, SiteConfig = args.SiteConfig, ResourceGroupName = args.ResourceGroupName, OsType = args.OsType, Name = args.Name, Location = args.Location, Tags = args.Tags, Identity = args.Identity, Enabled = args.Enabled, EnableBuiltinLogging = args.EnableBuiltinLogging, DailyMemoryTimeQuota = args.DailyMemoryTimeQuota, ConnectionStrings = args.ConnectionStrings, ClientAffinityEnabled = args.ClientAffinityEnabled, AuthSettings = args.AuthSettings, AppSettings = args.AppSettings, AppServicePlanId = args.AppServicePlanId, HttpsOnly = args.HttpsOnly, Version = args.Version ?? "~3" }; var archive = new Dictionary <string, AssetOrArchive> { { "host.json", new StringAsset( args.HostJson != null ? JsonConvert.SerializeObject(args.HostJson) : "{\"version\": \"2.0\", \"logging\": { \"applicationInsights\": { \"samplingExcludedTypes\": \"Request\", \"samplingSettings\": { \"isEnabled\": true } } } }") }, }; foreach (var function in args.Functions) { archive.Add(function.Name + "/function.json", new StringAsset(BuildFunctionJson(function))); // TODO: find better way to identify all required assemblies foreach (var assembly in Directory.GetFiles(new FileInfo(function.Callback.DeclaringType.Assembly.Location).DirectoryName, "*.dll")) { var key = "bin/" + new FileInfo(assembly).Name; if (!archive.ContainsKey(key)) { archive.Add(key, new FileAsset(assembly)); } } } archive.Add("bin/extensions.json", new StringAsset(BuildExtensionsJson(args))); mapped.Archive = new AssetArchive(archive); if (mapped.AppSettings == null) { mapped.AppSettings = new InputMap <string>(); } mapped.AppSettings.Add("FUNCTIONS_EXTENSION_VERSION", "~3"); mapped.AppSettings.Add("FUNCTIONS_WORKER_RUNTIME", "dotnet"); return(mapped); }
public CallbackFunctionApp(string name, CallbackFunctionAppArgs args, CustomResourceOptions options = null) : base(name, Map(args), options) { }