public Task <ITriggerData> BindAsync(QueueMessage value, ValueBindingContext context) { object converted = _converter.Convert(value); IValueProvider provider = new QueueMessageValueProvider(value, converted, typeof(T)); return(Task.FromResult <ITriggerData>(new TriggerData(provider, null))); }
public Task <ITriggerData> BindAsync(QueueMessage value, ValueBindingContext context) { if (value == null) { throw new ArgumentNullException(nameof(value)); } object convertedValue; try { convertedValue = JsonConvert.DeserializeObject(value.Body.ToValidUTF8String(), ValueType, JsonSerialization.Settings); } catch (JsonException e) { // Easy to have the queue payload not deserialize properly. So give a useful error. string msg = String.Format(CultureInfo.CurrentCulture, @"Binding parameters to complex objects (such as '{0}') uses Json.NET serialization. 1. Bind the parameter type as 'string' instead of '{0}' to get the raw values and avoid JSON deserialization, or 2. Change the queue payload to be valid json. The JSON parser failed: {1} ", _valueType.Name, e.Message); throw new InvalidOperationException(msg); } IValueProvider provider = new QueueMessageValueProvider(value, convertedValue, ValueType, _loggerFactory); IReadOnlyDictionary <string, object> bindingData = (_bindingDataProvider != null) ? _bindingDataProvider.GetBindingData(convertedValue) : null; return(Task.FromResult <ITriggerData>(new TriggerData(provider, bindingData))); }