Ejemplo n.º 1
0
        internal DotNetFunctionInvoker(ScriptHost host,
                                       FunctionMetadata functionMetadata,
                                       Collection <FunctionBinding> inputBindings,
                                       Collection <FunctionBinding> outputBindings,
                                       IFunctionEntryPointResolver functionEntryPointResolver,
                                       ICompilationServiceFactory <ICompilationService <IDotNetCompilation>, IFunctionMetadataResolver> compilationServiceFactory,
                                       ILoggerFactory loggerFactory,
                                       IMetricsLogger metricsLogger,
                                       ICollection <IScriptBindingProvider> bindingProviders,
                                       IFunctionMetadataResolver metadataResolver = null)
            : base(host, functionMetadata, loggerFactory)
        {
            _metricsLogger = metricsLogger;
            _functionEntryPointResolver = functionEntryPointResolver;
            _metadataResolver           = metadataResolver ?? CreateMetadataResolver(host, bindingProviders, functionMetadata, FunctionLogger);
            _compilationService         = compilationServiceFactory.CreateService(functionMetadata.Language, _metadataResolver);
            _inputBindings    = inputBindings;
            _outputBindings   = outputBindings;
            _triggerInputName = functionMetadata.Bindings.FirstOrDefault(b => b.IsTrigger).Name;
            _functionMetadata = functionMetadata;

            InitializeFileWatcher();

            _functionLoader = new FunctionLoader <MethodInfo>(CreateFunctionTarget);

            _reloadScript = ReloadScriptAsync;
            _reloadScript = _reloadScript.Debounce();

            _onReferencesChanged = OnReferencesChanged;
            _onReferencesChanged = _onReferencesChanged.Debounce();

            _restorePackages = RestorePackages;
            _restorePackages = _restorePackages.Debounce();
        }
        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();
        }
        public FunctionSignature GetEntryPointSignature(IFunctionEntryPointResolver entryPointResolver, Assembly functionAssembly)
        {
            EnsureAssemblyOption(false);

            // Scrape the compiled assembly for entry points
            IList <MethodReference <MethodInfo> > methods =
                functionAssembly.GetTypes().SelectMany(t =>
                                                       t.GetMethods().Select(m =>
                                                                             new MethodReference <MethodInfo>(m.Name, m.IsPublic, m))).ToList();

            MethodInfo entryPointReference = entryPointResolver.GetFunctionEntryPoint(methods).Value;

            // For F#, this currently creates a malformed signautre with fewer parameter symbols than parameter names.
            // For validation we only need the parameter names. The implementation of DotNetFunctionSignature copes with the
            // lists having different lengths.
            var parameters = entryPointReference.GetParameters().Select(x => new FunctionParameter(x.Name, x.ParameterType.FullName, x.IsOptional, GetParameterRefKind(x)));

            // For F#, we always set this to true for now.
            bool hasLocalTypeReference = true;

            var signature = new FunctionSignature(entryPointReference.DeclaringType.FullName, entryPointReference.Name,
                                                  parameters.ToImmutableArray(), entryPointReference.ReturnType.Name, hasLocalTypeReference);

            return(signature);
        }
        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();
        }
        internal DotNetFunctionInvoker(ScriptHost host, FunctionMetadata functionMetadata,
            Collection<FunctionBinding> inputBindings, Collection<FunctionBinding> outputBindings,
            IFunctionEntryPointResolver functionEntryPointResolver, FunctionAssemblyLoader assemblyLoader,
            ICompilationServiceFactory compilationServiceFactory, ITraceWriterFactory traceWriterFactory = null)
            : base(host, functionMetadata, traceWriterFactory)
        {
            _metricsLogger = Host.ScriptConfig.HostConfig.GetService<IMetricsLogger>();
            _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;

            InitializeFileWatcher();

            _resultProcessor = CreateResultProcessor();

            _functionLoader = new FunctionLoader<MethodInfo>(CreateFunctionTarget);

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

            _restorePackages = RestorePackages;
            _restorePackages = _restorePackages.Debounce();
        }
Ejemplo n.º 6
0
        internal DotNetFunctionInvoker(ScriptHost host,
                                       FunctionMetadata functionMetadata,
                                       Collection <FunctionBinding> inputBindings,
                                       Collection <FunctionBinding> outputBindings,
                                       IFunctionEntryPointResolver functionEntryPointResolver,
                                       FunctionAssemblyLoader assemblyLoader,
                                       ICompilationServiceFactory <ICompilationService <IDotNetCompilation>, IFunctionMetadataResolver> compilationServiceFactory,
                                       IFunctionMetadataResolver metadataResolver = null)
            : base(host, functionMetadata)
        {
            _metricsLogger = Host.ScriptConfig.HostConfig.GetService <IMetricsLogger>();
            _functionEntryPointResolver = functionEntryPointResolver;
            _assemblyLoader             = assemblyLoader;
            _metadataResolver           = metadataResolver ?? CreateMetadataResolver(host, functionMetadata, TraceWriter);
            _compilationService         = compilationServiceFactory.CreateService(functionMetadata.ScriptType, _metadataResolver);
            _inputBindings    = inputBindings;
            _outputBindings   = outputBindings;
            _triggerInputName = functionMetadata.Bindings.FirstOrDefault(b => b.IsTrigger).Name;

            InitializeFileWatcher();

            _resultProcessor = CreateResultProcessor();

            _functionLoader = new FunctionLoader <MethodInfo>(CreateFunctionTarget);

            _reloadScript = ReloadScriptAsync;
            _reloadScript = _reloadScript.Debounce();

            _onReferencesChanged = OnReferencesChanged;
            _onReferencesChanged = _onReferencesChanged.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();
        }
        public FunctionSignature GetEntryPointSignature(IFunctionEntryPointResolver entryPointResolver)
        {
            var entryPointMatch = _entryPointRegex.Match(_entryPointName);

            if (!entryPointMatch.Success)
            {
                throw new InvalidOperationException("Invalid entry point configuration. The function entry point must be defined in the format <fulltypename>.<methodname>");
            }

            string typeName   = entryPointMatch.Groups["typename"].Value;
            string methodName = entryPointMatch.Groups["methodname"].Value;

            Type functionType = FunctionAssembly.GetType(typeName);

            if (functionType == null)
            {
                throw new InvalidOperationException($"The function type name '{typeName}' is invalid.");
            }

            MethodInfo method = functionType.GetMethod(methodName, BindingFlags.Static | BindingFlags.Public);

            if (method == null)
            {
                throw new InvalidOperationException($"The method '{methodName}' cannot be found.");
            }

            var functionParameters = method.GetParameters().Select(p => new FunctionParameter(p.Name, p.ParameterType.FullName, p.IsOptional, GetParameterRefKind(p)));

            return(new FunctionSignature(method.ReflectedType.FullName, method.Name, ImmutableArray.CreateRange(functionParameters.ToArray()), method.ReturnType.Name, hasLocalTypeReference: false));
        }
        public FunctionSignature GetEntryPointSignature(IFunctionEntryPointResolver entryPointResolver)
        {
            var entryPointMatch = _entryPointRegex.Match(_entryPointName);
            if (!entryPointMatch.Success)
            {
                throw new InvalidOperationException("Invalid entry point configuration. The function entry point must be defined in the format <fulltypename>.<methodname>");
            }

            string typeName = entryPointMatch.Groups["typename"].Value;
            string methodName = entryPointMatch.Groups["methodname"].Value;

            Type functionType = FunctionAssembly.GetType(typeName);
            if (functionType == null)
            {
                throw new InvalidOperationException($"The function type name '{typeName}' is invalid.");
            }

            MethodInfo method = functionType.GetMethod(methodName, BindingFlags.Static | BindingFlags.Public);
            if (method == null)
            {
                throw new InvalidOperationException($"The method '{methodName}' cannot be found.");
            }

            var functionParameters = method.GetParameters().Select(p => new FunctionParameter(p.Name, p.ParameterType.FullName, p.IsOptional, GetParameterRefKind(p)));

            return new FunctionSignature(method.ReflectedType.Name, method.Name, ImmutableArray.CreateRange(functionParameters.ToArray()), method.ReturnType.Name, hasLocalTypeReference: false);
        }
        public FunctionSignature GetEntryPointSignature(IFunctionEntryPointResolver entryPointResolver)
        {
            if (!_compilation.SyntaxTrees.Any())
            {
                throw new InvalidOperationException("The current compilation does not have a syntax tree.");
            }

            var methods = _compilation.ScriptClass
                          .GetMembers()
                          .OfType <IMethodSymbol>()
                          .Select(m => new MethodReference <IMethodSymbol>(m.Name, m.DeclaredAccessibility == Accessibility.Public, m));

            IMethodSymbol entryPointReference    = entryPointResolver.GetFunctionEntryPoint(methods).Value;
            bool          hasLocalTypeReferences = entryPointReference.Parameters.Any(p => IsOrUsesAssemblyType(p.Type, entryPointReference.ContainingAssembly));

            return(new FunctionSignature(entryPointReference.ContainingType.Name, entryPointReference.Name, entryPointReference.Parameters, hasLocalTypeReferences));
        }
        public FunctionSignature GetEntryPointSignature(IFunctionEntryPointResolver entryPointResolver)
        {
            if (!_compilation.SyntaxTrees.Any())
            {
                throw new InvalidOperationException("The current compilation does not have a syntax tree.");
            }

            var methods = _compilation.ScriptClass
                          .GetMembers()
                          .OfType <IMethodSymbol>()
                          .Select(m => new MethodReference <IMethodSymbol>(m.Name, m.DeclaredAccessibility == Accessibility.Public, m));

            IMethodSymbol entryPointReference    = entryPointResolver.GetFunctionEntryPoint(methods).Value;
            bool          hasLocalTypeReferences = HasLocalTypeReferences(entryPointReference);
            var           functionParameters     = entryPointReference.Parameters.Select(p => new FunctionParameter(p.Name, GetFullTypeName(p.Type), p.IsOptional, p.RefKind));

            return(new FunctionSignature(entryPointReference.ContainingType.Name, entryPointReference.Name,
                                         ImmutableArray.CreateRange(functionParameters.ToArray()), GetFullTypeName(entryPointReference.ReturnType), hasLocalTypeReferences));
        }
        public FunctionSignature GetEntryPointSignature(IFunctionEntryPointResolver entryPointResolver)
        {
            if (!_compilation.SyntaxTrees.Any())
            {
                throw new InvalidOperationException("The current compilation does not have a syntax tree.");
            }

            var methods = _compilation.ScriptClass
                .GetMembers()
                .OfType<IMethodSymbol>()
                .Select(m => new MethodReference<IMethodSymbol>(m.Name, m.DeclaredAccessibility == Accessibility.Public, m));

            IMethodSymbol entryPointReference = entryPointResolver.GetFunctionEntryPoint(methods).Value;
            bool hasLocalTypeReferences = HasLocalTypeReferences(entryPointReference);
            var functionParameters = entryPointReference.Parameters.Select(p => new FunctionParameter(p.Name, GetFullTypeName(p.Type), p.IsOptional, p.RefKind));

            return new FunctionSignature(entryPointReference.ContainingType.Name, entryPointReference.Name,
                ImmutableArray.CreateRange(functionParameters.ToArray()), GetFullTypeName(entryPointReference.ReturnType), hasLocalTypeReferences);
        }
        public FunctionSignature GetEntryPointSignature(IFunctionEntryPointResolver entryPointResolver)
        {
            EnsureAssemblyOption();

            // Scrape the compiled assembly for entry points
            IList<MethodReference<MethodInfo>> methods =
                            _assemblyOption.Value.GetTypes().SelectMany(t =>
                                t.GetMethods().Select(m =>
                                    new MethodReference<MethodInfo>(m.Name, m.IsPublic, m))).ToList();

            MethodInfo entryPointReference = entryPointResolver.GetFunctionEntryPoint(methods).Value;

            // For F#, this currently creates a malformed signautre with fewer parameter symbols than parameter names.
            // For validation we only need the parameter names. The implementation of DotNetFunctionSignature copes with the 
            // lists having different lengths.
            var parameters = entryPointReference.GetParameters().Select(x => new FunctionParameter(x.Name, x.ParameterType.FullName, x.IsOptional, GetParameterRefKind(x)));
            // For F#, we always set this to true for now.
            bool hasLocalTypeReference = true;

            var signature = new FunctionSignature(entryPointReference.DeclaringType.Name, entryPointReference.Name,
                parameters.ToImmutableArray(), entryPointReference.ReturnType.Name, hasLocalTypeReference);

            return signature;
        }
        public static CSharpFunctionSignature FromCompilation(Compilation compilation, IFunctionEntryPointResolver entryPointResolver)
        {
            if (compilation == null)
            {
                throw new ArgumentNullException("compilation");
            }
            if (entryPointResolver == null)
            {
                throw new ArgumentNullException("entryPointResolver");
            }
            if (!compilation.SyntaxTrees.Any())
            {
                throw new ArgumentException("The provided compilation does not have a syntax tree.", "compilation");
            }

            var methods = compilation.ScriptClass
                          .GetMembers()
                          .OfType <IMethodSymbol>()
                          .Select(m => new MethodReference <IMethodSymbol>(m.Name, m.DeclaredAccessibility == Accessibility.Public, m));

            IMethodSymbol entryPointReference = entryPointResolver.GetFunctionEntryPoint(methods).Value;

            var signature = new CSharpFunctionSignature(entryPointReference.Parameters);

            signature.HasLocalTypeReference = entryPointReference.Parameters.Any(p => IsOrUsesAssemblyType(p.Type, entryPointReference.ContainingAssembly));

            return(signature);
        }