internal DotNetFunctionInvoker(ScriptHost host, FunctionMetadata functionMetadata,
                                       Collection <FunctionBinding> inputBindings, Collection <FunctionBinding> outputBindings,
                                       IFunctionEntryPointResolver functionEntryPointResolver, FunctionAssemblyLoader assemblyLoader,
                                       ICompilationServiceFactory compilationServiceFactory)
            : base(host, functionMetadata)
        {
            _functionEntryPointResolver = functionEntryPointResolver;
            _assemblyLoader             = assemblyLoader;
            _metadataResolver           = new FunctionMetadataResolver(functionMetadata, host.ScriptConfig.BindingProviders, TraceWriter);
            _compilationService         = compilationServiceFactory.CreateService(functionMetadata.ScriptType, _metadataResolver);
            _inputBindings    = inputBindings;
            _outputBindings   = outputBindings;
            _triggerInputName = functionMetadata.Bindings.FirstOrDefault(b => b.IsTrigger).Name;
            _metrics          = host.ScriptConfig.HostConfig.GetService <IMetricsLogger>();

            InitializeFileWatcher();

            _resultProcessor = CreateResultProcessor();

            _functionValueLoader = FunctionValueLoader.Create(CreateFunctionTarget);

            _reloadScript = ReloadScript;
            _reloadScript = _reloadScript.Debounce();

            _restorePackages = RestorePackages;
            _restorePackages = _restorePackages.Debounce();
        }
        internal CSharpFunctionInvoker(ScriptHost host, FunctionMetadata functionMetadata,
                                       Collection <FunctionBinding> inputBindings, Collection <FunctionBinding> outputBindings,
                                       IFunctionEntryPointResolver functionEntryPointResolver, FunctionAssemblyLoader assemblyLoader)
            : base(host, functionMetadata)
        {
            _host = host;
            _functionEntryPointResolver = functionEntryPointResolver;
            _assemblyLoader             = assemblyLoader;
            _metadataResolver           = new FunctionMetadataResolver(functionMetadata, TraceWriter);
            _inputBindings    = inputBindings;
            _outputBindings   = outputBindings;
            _triggerInputName = GetTriggerInputName(functionMetadata);
            _metrics          = host.ScriptConfig.HostConfig.GetService <IMetricsLogger>();

            InitializeFileWatcherIfEnabled();
            _resultProcessor = CreateResultProcessor();

            _functionValueLoader = FunctionValueLoader.Create(CreateFunctionTarget);

            _reloadScript = ReloadScript;
            _reloadScript = _reloadScript.Debounce();

            _restorePackages = RestorePackages;
            _restorePackages = _restorePackages.Debounce();
        }
Example #3
0
        public void Reset()
        {
            _functionValueLoaderLock.EnterWriteLock();
            try
            {
                _functionValueLoader?.Dispose();

                _functionValueLoader = new FunctionValueLoader <T>(_valueFactory, new CancellationTokenSource());
            }
            finally
            {
                _functionValueLoaderLock.ExitWriteLock();
            }
        }
        private void ResetFunctionValue()
        {
            _functionValueLoaderLock.EnterWriteLock();
            try
            {
                if (_functionValueLoader != null)
                {
                    _functionValueLoader.Dispose();
                }

                _functionValueLoader = FunctionValueLoader.Create(CreateFunctionTarget);
            }
            finally
            {
                _functionValueLoaderLock.ExitWriteLock();
            }
        }
Example #5
0
        public async Task <T> GetFunctionTargetAsync(int attemptCount = 0)
        {
            FunctionValueLoader <T> currentValueLoader = _functionValueLoader;

            try
            {
                return(await currentValueLoader);
            }
            catch (OperationCanceledException)
            {
                // If the current task we were awaiting on was cancelled due to a
                // cache refresh, retry, which will use the new loader
                if (attemptCount > 2)
                {
                    throw;
                }
            }

            return(await GetFunctionTargetAsync(++attemptCount));
        }
Example #6
0
 public FunctionLoader(Func <CancellationToken, Task <T> > valueFactory)
 {
     _valueFactory        = valueFactory;
     _functionValueLoader = new FunctionValueLoader <T>(valueFactory, new CancellationTokenSource());
 }