Esempio n. 1
0
            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(CloudQueueMessage value, ValueBindingContext context)
            {
                if (value == null)
                {
                    throw new ArgumentNullException("value");
                }

                object convertedValue;

                try
                {
                    convertedValue = JsonConvert.DeserializeObject(value.AsString, 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);

                IReadOnlyDictionary <string, object> bindingData = (_bindingDataProvider != null)
                    ? _bindingDataProvider.GetBindingData(convertedValue) : null;

                return(Task.FromResult <ITriggerData>(new TriggerData(provider, bindingData)));
            }