public void GetBoundScope_Success_ReturnsExceptedResult() { Dictionary <string, object> bindingData = new Dictionary <string, object>(); bindingData.Add("Region", "testregion"); bindingData.Add("Zone", 1); string result = SingletonManager.GetBoundScope(@"{Region}\{Zone}", bindingData); Assert.Equal(@"testregion\1", result); }
public SingletonListener(MethodInfo method, SingletonAttribute attribute, SingletonManager singletonManager, IListener innerListener) { _method = method; _attribute = attribute; _singletonManager = singletonManager; _singletonConfig = _singletonManager.Config; _innerListener = innerListener; string boundScope = _singletonManager.GetBoundScope(_attribute.Scope); _lockId = SingletonManager.FormatLockId(_method, boundScope); _lockId += ".Listener"; }
public async Task <IReadOnlyDictionary <string, IValueProvider> > BindAsync(ValueBindingContext context, IDictionary <string, object> parameters) { Dictionary <string, IValueProvider> results = new Dictionary <string, IValueProvider>(); BindingContext bindingContext = new BindingContext(context, null); // bind Singleton if specified SingletonAttribute singletonAttribute = SingletonManager.GetFunctionSingletonOrNull(_descriptor.Method, isTriggered: false); if (singletonAttribute != null) { string boundScope = _singletonManager.GetBoundScope(singletonAttribute.Scope); IValueProvider singletonValueProvider = new SingletonValueProvider(_descriptor.Method, boundScope, 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 = new BindingContext(context, bindingData); // Bind Singleton if specified SingletonAttribute singletonAttribute = _descriptor.Method.GetCustomAttribute <SingletonAttribute>(); if (singletonAttribute != null) { string boundScope = SingletonManager.GetBoundScope(singletonAttribute.Scope, bindingData); IValueProvider singletonValueProvider = new SingletonValueProvider(_descriptor.Method, boundScope, 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); }
public void GetBoundScope_BindingError_Throws() { // Missing binding data for "Zone" Dictionary <string, object> bindingData = new Dictionary <string, object>(); bindingData.Add("Region", "testregion"); InvalidOperationException exception = Assert.Throws <InvalidOperationException>(() => SingletonManager.GetBoundScope(@"{Region}\{Zone}", bindingData)); Assert.Equal("No value for named parameter 'Zone'.", exception.Message); }