public void GetFunctionSingletonOrNull_ListenerSingletonOnNonTriggeredFunction_Throws() { MethodInfo method = this.GetType().GetMethod("TestJob_ListenerSingleton", BindingFlags.Static | BindingFlags.NonPublic); NotSupportedException exception = Assert.Throws <NotSupportedException>(() => { SingletonManager.GetFunctionSingletonOrNull(method, isTriggered: false); }); Assert.Equal("SingletonAttribute using mode 'Listener' cannot be applied to non-triggered functions.", exception.Message); }
public void GetFunctionSingletonOrNull_ThrowsOnMultiple() { MethodInfo method = this.GetType().GetMethod("TestJob_MultipleFunctionSingletons", BindingFlags.Static | BindingFlags.NonPublic); NotSupportedException exception = Assert.Throws <NotSupportedException>(() => { SingletonManager.GetFunctionSingletonOrNull(method, isTriggered: true); }); Assert.Equal("Only one SingletonAttribute using mode 'Function' is allowed.", exception.Message); }
public async Task <IReadOnlyDictionary <string, IValueProvider> > BindAsync(ValueBindingContext context, IDictionary <string, object> parameters) { Dictionary <string, IValueProvider> results = new Dictionary <string, IValueProvider>(); // Supplied bindings can be direct parameters or route parameters. BindingContext bindingContext = NewBindingContext(context, null, parameters); // bind Singleton if specified SingletonAttribute singletonAttribute = SingletonManager.GetFunctionSingletonOrNull(_descriptor.Method, isTriggered: false); if (singletonAttribute != null) { string boundScopeId = _singletonManager.GetBoundScopeId(singletonAttribute.ScopeId); IValueProvider singletonValueProvider = new SingletonValueProvider(_descriptor.Method, boundScopeId, context.FunctionInstanceId.ToString(), singletonAttribute, _singletonManager); results.Add(SingletonValueProvider.SingletonParameterName, singletonValueProvider); } foreach (KeyValuePair <string, IBinding> item in _bindings) { string name = item.Key; IBinding binding = item.Value; IValueProvider valueProvider; try { if (parameters != null && parameters.ContainsKey(name)) { valueProvider = await binding.BindAsync(parameters[name], context); } else { valueProvider = await binding.BindAsync(bindingContext); } } catch (OperationCanceledException) { throw; } catch (Exception exception) { valueProvider = new BindingExceptionValueProvider(name, exception); } results.Add(name, valueProvider); } return(results); }
private async Task <IReadOnlyDictionary <string, IValueProvider> > BindCoreAsync(ValueBindingContext context, object value, IDictionary <string, object> parameters) { Dictionary <string, IValueProvider> valueProviders = new Dictionary <string, IValueProvider>(); IValueProvider triggerProvider; IReadOnlyDictionary <string, object> bindingData; try { ITriggerData triggerData = await _triggerBinding.BindAsync(value, context); triggerProvider = triggerData.ValueProvider; bindingData = triggerData.BindingData; } catch (OperationCanceledException) { throw; } catch (Exception exception) { triggerProvider = new BindingExceptionValueProvider(_triggerParameterName, exception); bindingData = null; } valueProviders.Add(_triggerParameterName, triggerProvider); BindingContext bindingContext = FunctionBinding.NewBindingContext(context, bindingData, parameters); // Bind Singleton if specified SingletonAttribute singletonAttribute = SingletonManager.GetFunctionSingletonOrNull(_descriptor.Method, isTriggered: true); if (singletonAttribute != null) { string boundScopeId = _singletonManager.GetBoundScopeId(singletonAttribute.ScopeId, bindingData); IValueProvider singletonValueProvider = new SingletonValueProvider(_descriptor.Method, boundScopeId, context.FunctionInstanceId.ToString(), singletonAttribute, _singletonManager); valueProviders.Add(SingletonValueProvider.SingletonParameterName, singletonValueProvider); } foreach (KeyValuePair <string, IBinding> item in _nonTriggerBindings) { string name = item.Key; IBinding binding = item.Value; IValueProvider valueProvider; try { if (parameters != null && parameters.ContainsKey(name)) { valueProvider = await binding.BindAsync(parameters[name], context); } else { valueProvider = await binding.BindAsync(bindingContext); } } catch (OperationCanceledException) { throw; } catch (Exception exception) { valueProvider = new BindingExceptionValueProvider(name, exception); } valueProviders.Add(name, valueProvider); } return(valueProviders); }
private async Task <IReadOnlyDictionary <string, IValueProvider> > BindCoreAsync(ValueBindingContext context, object value, IDictionary <string, object> parameters) { Dictionary <string, IValueProvider> valueProviders = new Dictionary <string, IValueProvider>(); IValueProvider triggerProvider; IReadOnlyDictionary <string, object> bindingData; IValueBinder triggerReturnValueProvider = null; try { ITriggerData triggerData = await _triggerBinding.BindAsync(value, context); triggerProvider = triggerData.ValueProvider; bindingData = triggerData.BindingData; triggerReturnValueProvider = (triggerData as TriggerData)?.ReturnValueProvider; } catch (OperationCanceledException) { throw; } catch (Exception exception) { triggerProvider = new BindingExceptionValueProvider(_triggerParameterName, exception); bindingData = null; } valueProviders.Add(_triggerParameterName, triggerProvider); // Bind Singleton if specified SingletonAttribute singletonAttribute = SingletonManager.GetFunctionSingletonOrNull(_descriptor, isTriggered: true); if (singletonAttribute != null) { string boundScopeId = _singletonManager.GetBoundScopeId(singletonAttribute.ScopeId, bindingData); IValueProvider singletonValueProvider = new SingletonValueProvider(_descriptor, boundScopeId, context.FunctionInstanceId.ToString(), singletonAttribute, _singletonManager); valueProviders.Add(SingletonValueProvider.SingletonParameterName, singletonValueProvider); } BindingContext bindingContext = FunctionBinding.NewBindingContext(context, bindingData, parameters); foreach (KeyValuePair <string, IBinding> item in _nonTriggerBindings) { string name = item.Key; IBinding binding = item.Value; IValueProvider valueProvider; try { if (parameters != null && parameters.ContainsKey(name)) { valueProvider = await binding.BindAsync(parameters[name], context); } else { valueProvider = await binding.BindAsync(bindingContext); } } catch (OperationCanceledException) { throw; } catch (Exception exception) { valueProvider = new BindingExceptionValueProvider(name, exception); } valueProviders.Add(name, valueProvider); } // Triggers can optionally process the return values of functions. They do so by declaring // a "$return" key in their binding data dictionary and mapping it to an IValueBinder. // An explicit return binding takes precedence over an implicit trigger binding. if (!valueProviders.ContainsKey(FunctionIndexer.ReturnParamName)) { if (triggerReturnValueProvider != null) { valueProviders.Add(FunctionIndexer.ReturnParamName, triggerReturnValueProvider); } } return(valueProviders); }