Beispiel #1
0
        internal static void Initialize(this IHostEnvironment hostingEnvironment, string contentRootPath,
                                        GtkHostOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (string.IsNullOrEmpty(contentRootPath))
            {
                throw new ArgumentException("A valid non-empty content root must be provided.",
                                            nameof(contentRootPath));
            }

            if (!Directory.Exists(contentRootPath))
            {
                throw new ArgumentException($"The content root '{contentRootPath}' does not exist.",
                                            nameof(contentRootPath));
            }

            hostingEnvironment.ApplicationName         = options.ApplicationName;
            hostingEnvironment.ContentRootPath         = contentRootPath;
            hostingEnvironment.ContentRootFileProvider =
                new PhysicalFileProvider(hostingEnvironment.ContentRootPath);

            hostingEnvironment.EnvironmentName =
                options.Environment ??
                hostingEnvironment.EnvironmentName;
        }
Beispiel #2
0
        private void ExecuteHostingStartups()
        {
            var gtkHostOptions =
                new GtkHostOptions(_config, Assembly.GetEntryAssembly()?.GetName().Name ?? string.Empty);

            if (gtkHostOptions.PreventHostingStartup)
            {
                return;
            }

            var exceptions = new List <Exception>();

            _hostingStartupGtkHostBuilder = new HostingStartupGtkHostBuilder(this);

            foreach (var assemblyName in gtkHostOptions.GetFinalHostingStartupAssemblies()
                     .Distinct(StringComparer.OrdinalIgnoreCase))
            {
                try
                {
                    var assembly = Assembly.Load(new AssemblyName(assemblyName));
                    foreach (var attribute in assembly.GetCustomAttributes <HostingStartupAttribute>())
                    {
                        var hostingStartup = (IHostingStartup)Activator.CreateInstance(attribute.HostingStartupType) !;
                        hostingStartup.Configure(_hostingStartupGtkHostBuilder);
                    }
                }
                catch (Exception ex)
                {
                    exceptions.Add(new InvalidOperationException($"启动程序集{assemblyName}无法执行。有关更多详细信息,请参见内部异常。", ex));
                }
            }

            if (exceptions.Count > 0)
            {
                _hostingStartupErrors = new AggregateException(exceptions);
            }
        }
Beispiel #3
0
        private GtkHostBuilderContext GetGtkHostBuilderContext(HostBuilderContext context)
        {
            if (!context.Properties.TryGetValue(typeof(GtkHostBuilderContext), out var contextVal))
            {
                var options = new GtkHostOptions(context.Configuration,
                                                 Assembly.GetEntryAssembly()?.GetName().Name ?? string.Empty);
                var webHostBuilderContext = new GtkHostBuilderContext
                {
                    Configuration      = context.Configuration,
                    HostingEnvironment = new HostingEnvironment(),
                };
                webHostBuilderContext.HostingEnvironment.Initialize(context.HostingEnvironment.ContentRootPath,
                                                                    options);
                context.Properties[typeof(GtkHostBuilderContext)] = webHostBuilderContext;
                context.Properties[typeof(GtkHostOptions)]        = options;
                return(webHostBuilderContext);
            }

            // Refresh config, it's periodically updated/replaced
            var webHostContext = (GtkHostBuilderContext)contextVal;

            webHostContext.Configuration = context.Configuration;
            return(webHostContext);
        }