示例#1
0
        public bool Equals(AspNetCoreRunnerAttribute other)
        {
            if (other == null)
            {
                return(false);
            }

            if (object.ReferenceEquals(this, other))
            {
                return(true);
            }

            return(string.Equals(this.TaskHub, other.TaskHub, StringComparison.OrdinalIgnoreCase) &&
                   string.Equals(this.ConnectionName, other.ConnectionName, StringComparison.OrdinalIgnoreCase) &&
                   this.Startup == other.Startup);
        }
示例#2
0
        private static void RegisterDurableClient(AspNetCoreRunnerAttribute aspNetCoreRunnerAttribute, IServiceProvider serviceProvider, IServiceCollection services, Type type, Type clientType, Type extensionType)
        {
            services.AddSingleton(clientType, sp =>
            {
                var configurations = serviceProvider.GetServices <IExtensionConfigProvider>();

                var durableTaskExtension = configurations.Where(t => t.GetType() == extensionType).FirstOrDefault();

                var getclient = durableTaskExtension.GetType().GetMethod("GetClient", BindingFlags.NonPublic | BindingFlags.Instance);
                var orchestrationClientAttribute = Activator.CreateInstance(type);
                type.GetProperty("TaskHub").SetValue(orchestrationClientAttribute, aspNetCoreRunnerAttribute.TaskHub);
                type.GetProperty("ConnectionName").SetValue(orchestrationClientAttribute, aspNetCoreRunnerAttribute.ConnectionName);


                var client = getclient.Invoke(durableTaskExtension, new object[] { orchestrationClientAttribute });

                return(client);
            });
        }
示例#3
0
 private Task <IAspNetCoreRunner> Factory(AspNetCoreRunnerAttribute arg1, ValueBindingContext arg2)
 {
     return(Task.FromResult(new AspNetCoreRunner(this.serviceProvider, arg1, arg2) as IAspNetCoreRunner));
 }
示例#4
0
        public AspNetCoreFunctionServer(Microsoft.Azure.WebJobs.ExecutionContext executionContext, AspNetCoreRunnerAttribute aspNetCoreRunnerAttribute, IServiceProvider serviceProvider)
        {
            var logger = serviceProvider.GetRequiredService <ILogger <AspNetCoreFunctionServer> >();

            logger.LogInformation($"Creating {nameof(AspNetCoreFunctionServer)}");

            _applicationSource = new TaskCompletionSource <IHttpApplication <Microsoft.AspNetCore.Hosting.Internal.HostingApplication.Context> >();

            var builder = new WebHostBuilder();


            builder.ConfigureServices(services =>
            {
                var tctype = Type.GetType("Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration, Microsoft.ApplicationInsights");
                if (tctype != null)
                {
                    var tc = serviceProvider.GetService(tctype);
                    if (tc != null)
                    {
                        services.AddSingleton(tctype, tc);
                    }
                }

                services.AddSingleton(executionContext);
                services.AddSingleton <IStartupFilter, HttpContextAccessorStartupFilter>();

                var type = Type.GetType("Microsoft.Azure.WebJobs.OrchestrationClientAttribute, Microsoft.Azure.WebJobs.Extensions.DurableTask") ??
                           Type.GetType("Microsoft.Azure.WebJobs.DurableClientAttribute, Microsoft.Azure.WebJobs.Extensions.DurableTask");
                if (type != null)
                {
                    var clientType               = Type.GetType("Microsoft.Azure.WebJobs.DurableOrchestrationClient, Microsoft.Azure.WebJobs.Extensions.DurableTask");
                    var iClientType              = Type.GetType("Microsoft.Azure.WebJobs.IDurableOrchestrationClient, Microsoft.Azure.WebJobs.Extensions.DurableTask");
                    var extensionType            = Type.GetType("Microsoft.Azure.WebJobs.Extensions.DurableTask.DurableTaskExtension, Microsoft.Azure.WebJobs.Extensions.DurableTask");
                    var IDurableEntityClientType = Type.GetType("Microsoft.Azure.WebJobs.IDurableEntityClient, Microsoft.Azure.WebJobs.Extensions.DurableTask");
                    var IDurableClientType       = Type.GetType("Microsoft.Azure.WebJobs.IDurableClient, Microsoft.Azure.WebJobs.Extensions.DurableTask");
                    services.AddSingleton(type);

                    if (clientType != null)
                    {
                        RegisterDurableClient(aspNetCoreRunnerAttribute, serviceProvider, services, type, clientType, extensionType);
                    }
                    if (iClientType != null)
                    {
                        RegisterDurableClient(aspNetCoreRunnerAttribute, serviceProvider, services, type, iClientType, extensionType);
                    }
                    if (IDurableEntityClientType != null)
                    {
                        RegisterDurableClient(aspNetCoreRunnerAttribute, serviceProvider, services, type, IDurableEntityClientType, extensionType);
                    }

                    if (IDurableClientType != null)
                    {
                        RegisterDurableClient(aspNetCoreRunnerAttribute, serviceProvider, services, type, IDurableClientType, extensionType);
                    }
                }
            });

            builder.UseContentRoot(executionContext.FunctionAppDirectory);
            builder.ConfigureAppConfiguration((c, cbuilder) => { cbuilder
                                                                 .AddInMemoryCollection(new Dictionary <string, string> {
                    ["ExecutionContext:FunctionName"]         = executionContext.FunctionName,
                    ["ExecutionContext:FunctionAppDirectory"] = executionContext.FunctionAppDirectory,
                    ["ExecutionContext:FunctionDirectory"]    = executionContext.FunctionDirectory
                })
                                                                 .AddConfiguration(serviceProvider.GetService <IConfiguration>()); });

            var builderExtension = serviceProvider.GetService(typeof(IWebHostBuilderExtension <>).MakeGenericType(aspNetCoreRunnerAttribute.Startup)) as IBuilderExtension;

            if (builderExtension != null)
            {
                builderExtension.ConfigureWebHostBuilder(executionContext, builder, serviceProvider);
            }


            builder.UseStartup(aspNetCoreRunnerAttribute.Startup);



            var _host = builder.UseServer(this);

            builder.Build().StartAsync().ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    _applicationSource.SetException(task.Exception);
                }
            });
        }
 public AspNetCoreRunner(IServiceProvider serviceProvider, AspNetCoreRunnerAttribute aspNetCoreRunnerAttribute, ValueBindingContext valueBindingContext)
 {
     this.serviceProvider           = serviceProvider;
     this.aspNetCoreRunnerAttribute = aspNetCoreRunnerAttribute;
     this.valueBindingContext       = valueBindingContext;
 }