// Specify the "builtin binding types". These are types that are directly accesible without needing an explicit load gesture. // This is the set of bindings we shipped prior to binding extensibility. // Map from BindingType to the Assembly Qualified Type name for its IExtensionConfigProvider object. public ScriptHost(IOptions <JobHostOptions> options, IOptions <LanguageWorkerOptions> languageWorkerOptions, IEnvironment environment, IJobHostContextFactory jobHostContextFactory, IConfiguration configuration, IDistributedLockManager distributedLockManager, IScriptEventManager eventManager, ILoggerFactory loggerFactory, IFunctionMetadataManager functionMetadataManager, IProxyMetadataManager proxyMetadataManager, IMetricsLogger metricsLogger, IOptions <ScriptJobHostOptions> scriptHostOptions, ITypeLocator typeLocator, IScriptJobHostEnvironment scriptHostEnvironment, IDebugStateProvider debugManager, IEnumerable <IScriptBindingProvider> bindingProviders, IPrimaryHostStateProvider primaryHostStateProvider, IJobHostMetadataProvider metadataProvider, IHostIdProvider hostIdProvider, ScriptSettingsManager settingsManager = null) : base(options, jobHostContextFactory) { _environment = environment; _typeLocator = typeLocator as ScriptTypeLocator ?? throw new ArgumentException(nameof(typeLocator), $"A {nameof(ScriptTypeLocator)} instance is required."); _instanceId = Guid.NewGuid().ToString(); _hostOptions = options; _configuration = configuration; _storageConnectionString = configuration.GetWebJobsConnectionString(ConnectionStringNames.Storage); _distributedLockManager = distributedLockManager; _functionMetadataManager = functionMetadataManager; _hostIdProvider = hostIdProvider; _proxyMetadataManager = proxyMetadataManager; _workerConfigs = languageWorkerOptions.Value.WorkerConfigs; ScriptOptions = scriptHostOptions.Value; _scriptHostEnvironment = scriptHostEnvironment; FunctionErrors = new Dictionary <string, ICollection <string> >(StringComparer.OrdinalIgnoreCase); EventManager = eventManager; _settingsManager = settingsManager ?? ScriptSettingsManager.Instance; _metricsLogger = metricsLogger; _hostLogPath = Path.Combine(ScriptOptions.RootLogPath, "Host"); _currentRuntimelanguage = _environment.GetEnvironmentVariable(LanguageWorkerConstants.FunctionWorkerRuntimeSettingName); _loggerFactory = loggerFactory; _logger = loggerFactory.CreateLogger(LogCategories.Startup); Logger = _logger; _debugManager = debugManager; _primaryHostStateProvider = primaryHostStateProvider; _bindingProviders = new List <IScriptBindingProvider>(bindingProviders); _metadataProvider = metadataProvider; }
private MethodInfo _applyReturn; // Action<object,object> public GeneralScriptBinding(IJobHostMetadataProvider metadataProvider, Attribute attribute, ScriptBindingContext context) : base(context) { _metadataProvider = metadataProvider; _attribute = attribute; _applyReturn = attribute.GetType().GetMethod("ApplyReturn", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); }
public void Test() { MyProg prog = new MyProg(); var activator = new FakeActivator(); activator.Add(prog); JobHostConfiguration config = TestHelpers.NewConfig <MyProg>(activator); var ext = new TestExtension(); config.AddExtension(ext); var host = new TestJobHost <MyProg>(config); IJobHostMetadataProvider metadataProvider = host.CreateMetadataProvider(); Assert.Equal(1, ext._counter); // Callable host.Call("Test"); Assert.Equal(1, ext._counter); // Fact that we registered a Widget converter is enough to add the assembly Assembly asm; bool resolved; resolved = metadataProvider.TryResolveAssembly(typeof(Widget).Assembly.GetName().Name, out asm); Assert.True(resolved); Assert.Same(asm, typeof(Widget).Assembly); // check with full name resolved = metadataProvider.TryResolveAssembly(typeof(Widget).Assembly.GetName().FullName, out asm); Assert.True(resolved); Assert.Same(asm, typeof(Widget).Assembly); // This requires the target attribute to be unique within the assembly. var attrType = metadataProvider.GetAttributeTypeFromName("Test9"); Assert.Equal(typeof(Test9Attribute), attrType); // JObject --> Attribute var attr = GetAttr <Test9Attribute>(metadataProvider, new { Flag = "xyz" }); Assert.Equal("xyz", attr.Flag); // Getting default type. var defaultType = metadataProvider.GetDefaultType(attr, FileAccess.Read, null); Assert.Equal(typeof(JObject), defaultType); // If we have no match for output, we'll try IAsyncCollector<string> Assert.Equal(typeof(IAsyncCollector <string>), metadataProvider.GetDefaultType(attr, FileAccess.Write, typeof(object))); }
// Instantiate a binding attribute public static Attribute MakeAttr(IJobHostMetadataProvider tooling, SemanticModel semantics, AttributeSyntax attrSyntax) { IMethodSymbol symAttributeCtor = (IMethodSymbol)semantics.GetSymbolInfo(attrSyntax).Symbol; var syntaxParams = symAttributeCtor.Parameters; INamedTypeSymbol attrType = symAttributeCtor.ContainingType; if (!IsBindingAttribute(attrType)) { return(null); } Type typeReflection = GetAttributeType(attrType); JObject args = new JObject(); int idx = 0; if (attrSyntax.ArgumentList != null) { foreach (var arg in attrSyntax.ArgumentList.Arguments) { var val = semantics.GetConstantValue(arg.Expression); if (!val.HasValue) { return(null); } var v2 = val.Value; string argName = null; if (arg.NameColon != null) { argName = arg.NameColon.Name.ToString(); } else if (arg.NameEquals != null) { argName = arg.NameEquals.Name.ToString(); } else { argName = syntaxParams[idx].Name; // Positional } args[argName] = JToken.FromObject(v2); idx++; } } var attr = tooling.GetAttribute(typeReflection, args); return(attr); }
public void Test() { MyProg prog = new MyProg(); var activator = new FakeActivator(); activator.Add(prog); JobHostConfiguration config = TestHelpers.NewConfig <MyProg>(activator); var ext = new TestExtension(); config.AddExtension(ext); IJobHostMetadataProvider tooling = config.CreateMetadataProvider(); Assert.Equal(1, ext._counter); // Callable var host = new TestJobHost <MyProg>(config); host.Call("Test"); Assert.Equal(1, ext._counter); // Fact that we registered a Widget converter is enough to add the assembly Assembly asm; bool resolved; resolved = tooling.TryResolveAssembly(typeof(Widget).Assembly.GetName().Name, out asm); Assert.True(resolved); Assert.Same(asm, typeof(Widget).Assembly); // check with full name resolved = tooling.TryResolveAssembly(typeof(Widget).Assembly.GetName().FullName, out asm); Assert.True(resolved); Assert.Same(asm, typeof(Widget).Assembly); var attrType = tooling.GetAttributeTypeFromName("Test"); Assert.Equal(typeof(TestAttribute), attrType); // JObject --> Attribute var attr = GetAttr <TestAttribute>(tooling, new { Flag = "xyz" }); Assert.Equal("xyz", attr.Flag); // Getting default type. var defaultType = tooling.GetDefaultType(attr, FileAccess.Read, null); Assert.Equal(typeof(JObject), defaultType); Assert.Throws <InvalidOperationException>(() => tooling.GetDefaultType(attr, FileAccess.Write, typeof(object))); }
public void DefaultTypeForTrigger() { var ext = new JArrayTriggerExtension(); var prog = new FakeTypeLocator(); JobHostConfiguration config = TestHelpers.NewConfig(prog, ext); var host = new JobHost(config); IJobHostMetadataProvider metadataProvider = host.CreateMetadataProvider(); var attr = new Test9Attribute(null); var type = metadataProvider.GetDefaultType(attr, FileAccess.Read, null); Assert.Equal(typeof(JArray), type); }
public void DefaultTypeForOpenTypeTrigger() { var ext = new OpenTypeTriggerExtension(); var prog = new FakeTypeLocator(); JobHostConfiguration config = TestHelpers.NewConfig(prog, ext); var host = new JobHost(config); IJobHostMetadataProvider metadataProvider = host.CreateMetadataProvider(); var attr = new Test9Attribute(null); var type = metadataProvider.GetDefaultType(attr, FileAccess.Write, null); // The trigger handles Open type, which means it will first pull byte[]. Assert.Equal(typeof(byte[]), type); }
public void DefaultTypeForJObjectCollector() { var ext = new TestExtension3(); var prog = new FakeTypeLocator(); JobHostConfiguration config = TestHelpers.NewConfig(prog, ext); var host = new JobHost(config); IJobHostMetadataProvider metadataProvider = host.CreateMetadataProvider(); var attr = new Test9Attribute(null); var type = metadataProvider.GetDefaultType(attr, FileAccess.Write, null); // Explicitly should be Jobject since that's all the collector is registered as. Assert.Equal(typeof(IAsyncCollector <JObject>), type); }
public void DefaultTypeForTrigger() { var ext = new JArrayTriggerExtension(); var host = new HostBuilder() .ConfigureDefaultTestHost(b => { b.AddExtension(ext); }) .ConfigureTypeLocator() // empty .Build(); IJobHostMetadataProvider metadataProvider = host.CreateMetadataProvider(); var attr = new Test9Attribute(null); var type = metadataProvider.GetDefaultType(attr, FileAccess.Read, null); Assert.Equal(typeof(JArray), type); }
public void DefaultTypeForOpenTypeCollector() { var ext = new TestExtension2(); var host = new HostBuilder() .ConfigureDefaultTestHost(b => { b.AddExtension(ext); }) .Build(); IJobHostMetadataProvider metadataProvider = host.CreateMetadataProvider(); var attr = new Test9Attribute(null); var type = metadataProvider.GetDefaultType(attr, FileAccess.Write, null); // The collector handles Open type, which means it will first pull byte[]. Assert.Equal(typeof(IAsyncCollector <byte[]>), type); }
public void DefaultTypeForOpenTypeTrigger() { var ext = new OpenTypeTriggerExtension(); var host = new HostBuilder() .ConfigureDefaultTestHost(b => { b.AddExtension(ext); }) .ConfigureTypeLocator() // empty .Build(); IJobHostMetadataProvider metadataProvider = host.CreateMetadataProvider(); var attr = new Test9Attribute(null); var type = metadataProvider.GetDefaultType(attr, FileAccess.Write, null); // The trigger handles Open type, which means it will first pull byte[]. Assert.Equal(typeof(byte[]), type); }
public void DefaultTypeForJObjectCollector() { var ext = new TestExtension3(); var host = new HostBuilder() .ConfigureDefaultTestHost(b => { b.AddExtension(ext); }) .Build(); IJobHostMetadataProvider metadataProvider = host.CreateMetadataProvider(); var attr = new Test9Attribute(null); var type = metadataProvider.GetDefaultType(attr, FileAccess.Write, null); // Explicitly should be Jobject since that's all the collector is registered as. Assert.Equal(typeof(IAsyncCollector <JObject>), type); }
public void DefaultType() { var config = TestHelpers.NewConfig <ConfigNullOutParam>(); config.AddExtension(new ConfigNullOutParam()); // Registers a BindToInput rule var host = new JobHost(config); IJobHostMetadataProvider metadataProvider = host.CreateMetadataProvider(); // Getting default type. var attr = new TestStreamAttribute("x", FileAccess.Read); { var defaultType = metadataProvider.GetDefaultType(attr, FileAccess.Read, null); Assert.Equal(typeof(Stream), defaultType); } { var defaultType = metadataProvider.GetDefaultType(attr, FileAccess.Write, null); Assert.Equal(typeof(Stream), defaultType); } }
public void DefaultType() { var host = new HostBuilder() .ConfigureDefaultTestHost <ConfigNullOutParam>(b => { b.AddExtension <ConfigNullOutParam>(); }) .Build(); IJobHostMetadataProvider metadataProvider = host.CreateMetadataProvider(); // Getting default type. var attr = new TestStreamAttribute("x", FileAccess.Read); { var defaultType = metadataProvider.GetDefaultType(attr, FileAccess.Read, null); Assert.Equal(typeof(Stream), defaultType); } { var defaultType = metadataProvider.GetDefaultType(attr, FileAccess.Write, null); Assert.Equal(typeof(Stream), defaultType); } }
// Specify the "builtin binding types". These are types that are directly accesible without needing an explicit load gesture. // This is the set of bindings we shipped prior to binding extensibility. // Map from BindingType to the Assembly Qualified Type name for its IExtensionConfigProvider object. public ScriptHost(IOptions <JobHostOptions> options, IOptions <HttpWorkerOptions> httpWorkerOptions, IEnvironment environment, IJobHostContextFactory jobHostContextFactory, IConfiguration configuration, IDistributedLockManager distributedLockManager, IScriptEventManager eventManager, ILoggerFactory loggerFactory, IFunctionInvocationDispatcherFactory functionDispatcherFactory, IFunctionMetadataManager functionMetadataManager, IFileLoggingStatusManager fileLoggingStatusManager, IMetricsLogger metricsLogger, IOptions <ScriptJobHostOptions> scriptHostOptions, ITypeLocator typeLocator, IScriptHostManager scriptHostManager, IDebugStateProvider debugManager, IEnumerable <IScriptBindingProvider> bindingProviders, IPrimaryHostStateProvider primaryHostStateProvider, IJobHostMetadataProvider metadataProvider, IHostIdProvider hostIdProvider, IHttpRoutesManager httpRoutesManager, IApplicationLifetime applicationLifetime, IExtensionBundleManager extensionBundleManager, ScriptSettingsManager settingsManager = null) : base(options, jobHostContextFactory) { _environment = environment; _typeLocator = typeLocator as ScriptTypeLocator ?? throw new ArgumentException(nameof(typeLocator), $"A {nameof(ScriptTypeLocator)} instance is required."); _instanceId = Guid.NewGuid().ToString(); _hostOptions = options; _configuration = configuration; _storageConnectionString = configuration.GetWebJobsConnectionString(ConnectionStringNames.Storage); _distributedLockManager = distributedLockManager; _functionMetadataManager = functionMetadataManager; _fileLoggingStatusManager = fileLoggingStatusManager; _applicationLifetime = applicationLifetime; _hostIdProvider = hostIdProvider; _httpRoutesManager = httpRoutesManager; _isHttpWorker = httpWorkerOptions.Value.Description != null; ScriptOptions = scriptHostOptions.Value; _scriptHostManager = scriptHostManager; FunctionErrors = new Dictionary <string, ICollection <string> >(StringComparer.OrdinalIgnoreCase); EventManager = eventManager; _functionDispatcher = functionDispatcherFactory.GetFunctionDispatcher(); _settingsManager = settingsManager ?? ScriptSettingsManager.Instance; ExtensionBundleManager = extensionBundleManager; _metricsLogger = metricsLogger; _hostLogPath = Path.Combine(ScriptOptions.RootLogPath, "Host"); _workerRuntime = _environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName); _loggerFactory = loggerFactory; _logger = loggerFactory.CreateLogger(LogCategories.Startup); Logger = _logger; _debugManager = debugManager; _primaryHostStateProvider = primaryHostStateProvider; _bindingProviders = new List <IScriptBindingProvider>(bindingProviders); _metadataProvider = metadataProvider; _eventSubscriptions.Add(EventManager.OfType <FunctionIndexingEvent>() .Subscribe(evt => { HandleHostError(evt.Exception); })); }
static T GetAttr <T>(IJobHostMetadataProvider metadataProvider, object obj) where T : Attribute { var attribute = metadataProvider.GetAttribute(typeof(T), JObject.FromObject(obj)); return((T)attribute); }
// The constructor is fixed and ScriptBindingProvider are instantated for us by the Script runtime. // Extensions may get registered after this class is instantiated. // So we need a final call that lets us get the tooling snapshot of the graph after all extensions are set. public void CompleteInitialization() { this._metadataProvider = this.Config.CreateMetadataProvider(); }
// The constructor is fixed and ScriptBindingProvider are instantated for us by the Script runtime. // Extensions may get registered after this class is instantiated. // So we need a final call that lets us get the tooling snapshot of the graph after all extensions are set. public void CompleteInitialization(IJobHostMetadataProvider metadataProvider) { _metadataProvider = metadataProvider; }
public GeneralScriptBinding(IJobHostMetadataProvider metadataProvider, Attribute attribute, ScriptBindingContext context) : base(context) { _metadataProvider = metadataProvider; _attribute = attribute; }
public GeneralScriptBindingProvider(ILogger <GeneralScriptBindingProvider> logger, IJobHostMetadataProvider metadataProvider) : base(logger) { _metadataProvider = metadataProvider; }