public Task<IValueProvider> BindAsync(object value, ValueBindingContext context) { IAttributeBindingSource binding = value as IAttributeBindingSource; if (binding == null) { throw new InvalidOperationException("Unable to convert value to IAttributeBindingSource."); } return BindAsync(binding, context); }
public Task<IValueProvider> BindAsync(object value, ValueBindingContext context) { if (value is CancellationToken) { throw new InvalidOperationException("Unable to convert value to CancellationToken."); } CancellationToken token = (CancellationToken)value; return BindAsync(token, context); }
public Task<IValueProvider> BindAsync(object value, ValueBindingContext context) { CloudStorageAccount account = null; if (!Converter.TryConvert(value, out account)) { throw new InvalidOperationException("Unable to convert value to CloudStorageAccount."); } return BindAccountAsync(account, context); }
private Task <object> ConvertPocoToMessage(object src, Attribute attribute, ValueBindingContext context) => Task.FromResult <object>(ConvertStringToMessage(JsonConvert.SerializeObject(src)));
private Task<IValueProvider> BindAsync(CancellationToken token, ValueBindingContext context) { IValueProvider provider = new CancellationTokenValueProvider(token); return Task.FromResult(provider); }
public Task <IValueProvider> BindAsync(object value, ValueBindingContext context) => Task.FromResult((IValueProvider) new InjectValueProvider(value));
private Task <IValueProvider> BindAsync(TBindingData bindingDataItem, ValueBindingContext context) { return(_argumentBinding.BindAsync(bindingDataItem, context)); }
private Task <IValueProvider> BindAsync(TValue value, ValueBindingContext context) { IValueProvider provider = new ObjectValueProvider(value, typeof(TValue)); return(Task.FromResult(provider)); }
private Task <IValueProvider> BindBlobAsync(IStorageBlob value, ValueBindingContext context) { return(_argumentBinding.BindAsync(value, context)); }
private static Task <object> ConvertPocoToEventData(object arg, Attribute attrResolved, ValueBindingContext context) { return(Task.FromResult <object>(ConvertStringToEventData(JsonConvert.SerializeObject(arg)))); }
public Task <IValueProvider> BindAsync(object value, ValueBindingContext context) { return(Task.FromResult <IValueProvider>(this)); }
public Task <IValueProvider> BindAsync(CloudTable value, ValueBindingContext context) { throw new NotImplementedException(); }
public async Task <IValueProvider> BindAsync(IStorageBlobContainer container, ValueBindingContext context) { BlobValueBindingContext containerBindingContext = (BlobValueBindingContext)context; // Query the blob container using the blob prefix (if specified) // Note that we're explicitly using useFlatBlobListing=true to collapse // sub directories. If users want to bind to a sub directory, they can // bind to CloudBlobDirectory. string prefix = containerBindingContext.Path.BlobName; IEnumerable <IStorageListBlobItem> blobItems = await container.ListBlobsAsync(prefix, true, context.CancellationToken); // create an IEnumerable<T> of the correct type, performing any // required conversions on the blobs Type elementType = _parameter.ParameterType.GenericTypeArguments[0]; IList list = await ConvertBlobs(elementType, blobItems); string invokeString = containerBindingContext.Path.ToString(); return(new ValueProvider(list, _parameter.ParameterType, invokeString)); }
public Task <IValueProvider> BindAsync(CloudTable value, ValueBindingContext context) { BoundTable = value; return(Task.FromResult <IValueProvider>(new FooBarValueProvider())); }
public Task <IValueProvider> BindAsync(object value, ValueBindingContext context) { var message = (MailMessage)value; return(Task.FromResult <IValueProvider>(new SmtpValueBinder(_smtpClient, message))); }
public static async Task <ICacheAwareReadObject> TryBindCacheAwareAsync(BlobWithContainer <BlobBaseClient> blob, ValueBindingContext context, IFunctionDataCache functionDataCache) { try { // Generate the cache key for this blob FunctionDataCacheKey cacheKey = await GetFunctionDataCacheKey(blob, context.CancellationToken).ConfigureAwait(false); if (cacheKey == null) { return(null); } // Check if it exists in the cache if (functionDataCache.TryGet(cacheKey, isIncrementActiveReference: true, out SharedMemoryMetadata sharedMemoryMeta)) { // CACHE HIT return(new CacheableReadBlob(cacheKey, sharedMemoryMeta, functionDataCache)); } // CACHE MISS // Wrap the blob's stream along with the cache key so it can be inserted in the cache later using the above generated key for this blob Stream innerStream = await TryBindStreamAsync(blob.BlobClient, context.CancellationToken, cacheKey.Version).ConfigureAwait(false); return(new CacheableReadBlob(cacheKey, innerStream, functionDataCache)); } catch (RequestFailedException exception) { // Testing generic error case since specific error codes are not available for FetchAttributes // (HEAD request), including OpenRead. if (!exception.IsNotFound()) { throw; } return(null); } }
public static Task <Stream> TryBindStreamAsync(BlobBaseClient blob, ValueBindingContext context) { return(TryBindStreamAsync(blob, context.CancellationToken)); }
public Task <ITriggerData> BindAsync(object value, ValueBindingContext context) { // ValueProvider is via binding rules. return(_emptyBindingDataTask); }
private Task <IValueProvider> BindAsync(ServiceBusEntity value, ValueBindingContext context) { return(_argumentBinding.BindAsync(value, context)); }
public Task <IValueProvider> BindAsync(object value, ValueBindingContext context) { return(null); }
public Task <IValueProvider> BindAsync(object value, ValueBindingContext context) { return(Task.FromResult <IValueProvider>(new NServiceBusSubscriptionAttributeValueProvider(_parameterInfo))); }
async Task <ITriggerData> ITriggerBinding.BindAsync(object value, ValueBindingContext context) { HttpContext requestContext = (HttpContext)value; Stream inputStream = requestContext.Request.Body; Type destinationType = this.parameter.ParameterType; var bindingData = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase); object convertedValue; if (inputStream == null) { convertedValue = this.parameter.DefaultValue; } else if (destinationType.IsAssignableFrom(inputStream.GetType())) { // Give them the request stream directly - no buffering convertedValue = inputStream; } else if (destinationType.IsAssignableFrom(typeof(byte[]))) { // Copy the stream into a simple byte array with the help of MemoryStream using (var buffer = new MemoryStream((int?)requestContext.Request.ContentLength ?? 4096)) using (inputStream) { await inputStream.CopyToAsync(buffer); convertedValue = buffer.ToArray(); } } else { // Binding to JToken or some derivative like JObject or JArray. // This also works for primitives like int, bool, and string. JToken jsonValue; using (var reader = new JsonTextReader(new StreamReader(inputStream))) { jsonValue = await JToken.ReadFromAsync(reader, context.CancellationToken); } if (destinationType.IsAssignableFrom(jsonValue.GetType())) { convertedValue = jsonValue; } else if (destinationType == typeof(string) && jsonValue.Type != JTokenType.String) { // Special case for out-of-proc workers (like nodejs). The binding type // appears to always be "string" so we need to do a special conversion. convertedValue = jsonValue.ToString(Formatting.None); } else { // At this point, we're probably dealing with a POCO convertedValue = this.ConvertFromJson(jsonValue, destinationType); } } // Support for basic expression binding bindingData[this.parameter.Name] = convertedValue; var valueProvider = new ObjectValueProvider(convertedValue, destinationType); return(new TriggerData(valueProvider, bindingData) { ReturnValueProvider = new HttpContextReturnValueBinder(requestContext, destinationType), }); }
public ServiceBusReceivedMessage[] BindMultiple(ServiceBusTriggerInput value, ValueBindingContext context) { if (value == null) { throw new ArgumentNullException(nameof(value)); } return(value.Messages); }
private Task <IValueProvider> BindAsync(IAttributeBindingSource binding, ValueBindingContext context) { IValueProvider provider = new RuntimeValueProvider(binding); return(Task.FromResult(provider)); }
public Task <ITriggerData> BindAsync(object value, ValueBindingContext context) { var valueProvider = new ValueProvider(value); return(Task.FromResult <ITriggerData>(new TriggerData(valueProvider, _emptyBindingData))); }
public Task <ITriggerData> BindAsync(object value, ValueBindingContext context) { // ValueProvider is via binding rules. return(Task.FromResult <ITriggerData>(new TriggerData(null, _emptyBindingData))); }
public Task <ITriggerData> BindAsync(object value, ValueBindingContext context) { var trigger = new TriggerData(new MessageValueProvider(value), new Dictionary <string, object>()); return(Task.FromResult <ITriggerData>(trigger)); }
/// <summary> /// Perform a bind to the specified value. /// </summary> /// <param name="value">The value to bind to.</param> /// <param name="context">The binding context.</param> /// <returns>A task that returns the <see cref="T:Microsoft.Azure.WebJobs.Host.Bindings.IValueProvider" /> for the binding.</returns> public Task <IValueProvider> BindAsync(object value, ValueBindingContext context) { return(Task.FromResult <IValueProvider>(new InjectAttributeValueProvider(_parameterInfo, _locator))); }
public async Task <ITriggerData> BindAsync(BrokeredMessage value, ValueBindingContext context) { ITriggerData triggerData = await _argumentBinding.BindAsync(value, context); return(triggerData); }
// For describing InvokeStrings. private async Task <ICloudBlob> ConvertFromInvokeString(DirectInvokeString input, Attribute attr, ValueBindingContext context) { var attrResolved = (BlobTriggerAttribute)attr; var account = _accountProvider.Get(attrResolved.Connection); var client = account.CreateCloudBlobClient(); BlobPath path = BlobPath.ParseAndValidate(input.Value); var container = client.GetContainerReference(path.ContainerName); var blob = await container.GetBlobReferenceFromServerAsync(path.BlobName); return(blob); }
public Task <IValueProvider> BindAsync(object value, ValueBindingContext context) { FtpRequestInfo requestInfo = (FtpRequestInfo)value; return(Task.FromResult <IValueProvider>(new FtpValueBinder(_parameter, requestInfo))); }
public async Task <IValueProvider> BindAsync(object value, ValueBindingContext context) { var result = await _inner.BindAsync(value, context); return(await WrapAsync(result, context)); }
private async Task <string> ExecuteWithLoggingAsync(IFunctionInstance instance, FunctionStartedMessage message, IDictionary <string, ParameterLog> parameterLogCollector, TraceLevel functionTraceLevel, CancellationToken cancellationToken) { IFunctionOutputDefinition outputDefinition = null; IFunctionOutput outputLog = null; ITaskSeriesTimer updateOutputLogTimer = null; TextWriter functionOutputTextWriter = null; Func <Task> initializeOutputAsync = async() => { outputDefinition = await _functionOutputLogger.CreateAsync(instance, cancellationToken); outputLog = outputDefinition.CreateOutput(); functionOutputTextWriter = outputLog.Output; updateOutputLogTimer = StartOutputTimer(outputLog.UpdateCommand, _backgroundExceptionDispatcher); }; if (functionTraceLevel >= TraceLevel.Info) { await initializeOutputAsync(); } try { // Create a linked token source that will allow us to signal function cancellation // (e.g. Based on TimeoutAttribute, etc.) CancellationTokenSource functionCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); using (functionCancellationTokenSource) { // We create a new composite trace writer that will also forward // output to the function output log (in addition to console, user TraceWriter, etc.). TraceWriter traceWriter = new CompositeTraceWriter(_trace, functionOutputTextWriter, functionTraceLevel); // Must bind before logging (bound invoke string is included in log message). FunctionBindingContext functionContext = new FunctionBindingContext(instance.Id, functionCancellationTokenSource.Token, traceWriter); var valueBindingContext = new ValueBindingContext(functionContext, cancellationToken); var parameters = await instance.BindingSource.BindAsync(valueBindingContext); Exception invocationException = null; ExceptionDispatchInfo exceptionInfo = null; string startedMessageId = null; using (ValueProviderDisposable.Create(parameters)) { if (functionTraceLevel >= TraceLevel.Info) { startedMessageId = await LogFunctionStartedAsync(message, outputDefinition, parameters, cancellationToken); } try { await ExecuteWithLoggingAsync(instance, parameters, traceWriter, outputDefinition, parameterLogCollector, functionTraceLevel, functionCancellationTokenSource); } catch (Exception ex) { invocationException = ex; } } if (invocationException != null) { if (outputDefinition == null) { // In error cases, even if logging is disabled for this function, we want to force // log errors. So we must delay initialize logging here await initializeOutputAsync(); startedMessageId = await LogFunctionStartedAsync(message, outputDefinition, parameters, cancellationToken); } if (invocationException is OperationCanceledException) { exceptionInfo = ExceptionDispatchInfo.Capture(invocationException); } else { string errorMessage = string.Format("Exception while executing function: {0}", instance.FunctionDescriptor.ShortName); FunctionInvocationException fex = new FunctionInvocationException(errorMessage, instance.Id, instance.FunctionDescriptor.FullName, invocationException); traceWriter.Error(errorMessage, fex, TraceSource.Execution); exceptionInfo = ExceptionDispatchInfo.Capture(fex); } } if (exceptionInfo == null && updateOutputLogTimer != null) { await updateOutputLogTimer.StopAsync(cancellationToken); } // after all execution is complete, flush the TraceWriter traceWriter.Flush(); // We save the exception info above rather than throwing to ensure we always write // console output even if the function fails or was canceled. if (outputLog != null) { await outputLog.SaveAndCloseAsync(cancellationToken); } if (exceptionInfo != null) { // release any held singleton lock immediately SingletonLock singleton = null; if (TryGetSingletonLock(parameters, out singleton) && singleton.IsHeld) { await singleton.ReleaseAsync(cancellationToken); } exceptionInfo.Throw(); } return(startedMessageId); } } finally { if (outputLog != null) { ((IDisposable)outputLog).Dispose(); } if (updateOutputLogTimer != null) { ((IDisposable)updateOutputLogTimer).Dispose(); } } }
public async Task <IValueProvider> BindAsync(IStorageBlob blob, ValueBindingContext context) { WatchableCloudBlobStream watchableStream = await WriteBlobArgumentBinding.BindStreamAsync(blob, context, _blobWrittenWatcherGetter.Value); return(new ByteArrayValueBinder(blob, watchableStream)); }
private Task<IValueProvider> BindAsync(IAttributeBindingSource binding, ValueBindingContext context) { IValueProvider provider = new RuntimeValueProvider(binding, _parameter.ParameterType); return Task.FromResult(provider); }
private Task<IValueProvider> BindAccountAsync(CloudStorageAccount account, ValueBindingContext context) { IValueProvider provider = new CloudStorageAccountValueProvider(account); return Task.FromResult(provider); }