コード例 #1
0
        public static void Implement(string entryAssemblyPath, IReadOnlyCollection <PluginMetadata> plugins)
        {
            using (var assemblyFile = File.Open(entryAssemblyPath, FileMode.Open, FileAccess.ReadWrite))
            {
                var assembly = AssemblyDefinition.ReadAssembly(assemblyFile, new ReaderParameters
                {
                    AssemblyResolver = new DirectoryAssemblyResolver(entryAssemblyPath)
                });
                var implementor = new FunctionImplementor(assembly, plugins);

                foreach (var type in implementor._module.Types.ToList())
                {
                    if (type.Name == "FunctionImpl")
                    {
                        implementor._module.Types.Remove(type);
                    }
                }

                if (plugins.Any(x => x.ServiceType == ServiceType.MessageHandler))
                {
                    var functionType = implementor.CreateServiceFunctionType();
                    implementor.ImplementCtor(functionType);
                    implementor.ImplementServiceCreateHandler(functionType);
                }
                else
                {
                    var functionType = implementor.CreateHttpFunctionType();
                    implementor.ImplementCtor(functionType);
                    implementor.ImplementHttpGetServiceKey(functionType);
                    implementor.ImplementHttpGetServiceType(functionType);
                }

                assembly.Write();
            }
        }
コード例 #2
0
        public void Build(BuildContext context)
        {
            DirectoryCopy(Path.GetDirectoryName(context.PathToFunctionAssembly), context.PathToTargetFolder, true, true);
            DirectoryCopy(Path.GetDirectoryName(context.PathToFunctionEntryAssembly), context.PathToTargetFolder, true, false);

            var pathToFunctionAssembly      = Path.Combine(context.PathToTargetFolder, Path.GetFileName(context.PathToFunctionAssembly));
            var pathToFunctionEntryAssembly = Path.Combine(context.PathToTargetFolder, Path.GetFileName(context.PathToFunctionEntryAssembly));

            var pluginLoaders = Bootstrapper.LoadPlugins(new[] { pathToFunctionAssembly });
            var plugins       = PluginDiscoverer.Discover(pluginLoaders.Assemblies);

            FunctionDependencyMerger.Merge(pathToFunctionEntryAssembly, pathToFunctionAssembly);
            FunctionImplementor.Implement(pathToFunctionEntryAssembly, plugins);
        }