/// <summary>
        /// 自动注册所有 Area
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="env"></param>
        /// <param name="eachRegsiterAction">遍历到每一个 Register 额外的操作</param>
        /// <returns></returns>
        public static IMvcBuilder AddNcfAreas(this IMvcBuilder builder, Microsoft.Extensions.Hosting.IHostEnvironment /*IWebHostEnvironment*/ env, Action <IAreaRegister> eachRegsiterAction = null)
        {
            AssembleScanHelper.AddAssembleScanItem(assembly =>
            {
                try
                {
                    var areaRegisterTypes = assembly.GetTypes()
                                            .Where(z => z.GetInterface(nameof(IAreaRegister)) != null)
                                            .ToArray();

                    foreach (var registerType in areaRegisterTypes)
                    {
                        var register = Activator.CreateInstance(registerType, true) as IAreaRegister;
                        if (register != null)
                        {
                            register.AuthorizeConfig(builder, env); //进行注册
                            eachRegsiterAction?.Invoke(register);   //执行额外的操作
                        }
                        else
                        {
                            SenparcTrace.BaseExceptionLog(new BaseException($"{registerType.Name} 类型没有实现接口 IAreaRegister!"));
                        }
                    }
                }
                catch (Exception ex)
                {
                    SenparcTrace.SendCustomLog("AddNcfAreas() 自动扫描程序集报告(非程序异常):" + assembly.FullName, ex.ToString());
                }
            }, false);
            return(builder);
        }
 public static IServiceCollection AddDefaultJsonConfiguration(this IServiceCollection services)
 {
     return(services.AddSingleton(provider =>
     {
         IHostEnvironment env = provider.GetRequiredService <IHostEnvironment>();
         IConfiguration config = new ConfigurationBuilder()
                                 .AddDefaultJsonConfiguration(env)
                                 .Build();
         return config;
     }));
 }
        public DatabaseSeeder(IServiceProvider serviceProvider)
        {
            _provider = serviceProvider;

            var scope = serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope();

            _faker       = new Faker("en");
            _environment = serviceProvider.GetRequiredService <IHostEnvironment>();
            _context     = scope.ServiceProvider.GetService <BooksDbContext>();
            _userManager = scope.ServiceProvider.GetRequiredService <UserManager <IdentityUser <Guid> > >();
            _roleManager = scope.ServiceProvider.GetService <RoleManager <IdentityRole <Guid> > >();
        }
Exemple #4
0
        internal PluginOptions(Microsoft.Extensions.Hosting.IHostEnvironment environment, string pluginsDirectoryName = null)
        {
            if (environment == null)
            {
                throw new ArgumentNullException(nameof(environment));
            }

            this.EnvironmentName      = environment.EnvironmentName;
            this.ApplicationDirectory = environment.ContentRootPath;
            this.PluginsPath          = Path.Combine(this.ApplicationDirectory, string.IsNullOrWhiteSpace(pluginsDirectoryName) ? "plugins" : pluginsDirectoryName);
            this.Properties           = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);
        }
Exemple #5
0
        public TemplateService(
            ILogger <TemplateService> logger,
            IRazorViewEngine viewEngine,
            IServiceProvider serviceProvider,
            ITempDataProvider tempDataProvider,
            Microsoft.Extensions.Hosting.IHostEnvironment hostingEnvironment
            )
#endif
        {
            _logger             = logger;
            _viewEngine         = viewEngine;
            _serviceProvider    = serviceProvider;
            _tempDataProvider   = tempDataProvider;
            _hostingEnvironment = hostingEnvironment;
        }
Exemple #6
0
 public SyncSitesJob(ILogger <SyncSitesJob> logger,
                     IFtpManager ftpManager,
                     IOptions <Dictionary <string, SiteSetting> > options,
                     IPowerShellScriptRunner powerShellScriptRunner,
                     Microsoft.Extensions.Hosting.IHostEnvironment hostingEnvironment,
                     INotificationManager notificationManager,
                     IConfiguration configuration,
                     CheckRunner checkRunner)
 {
     _logger                 = logger;
     _ftpManager             = ftpManager;
     _powerShellScriptRunner = powerShellScriptRunner;
     _hostingEnvironment     = hostingEnvironment;
     _notificationManager    = notificationManager;
     _checkRunner            = checkRunner;
     _webConfigsPath         = configuration["WebConfigs"];
     _basePath               = configuration["BasePath"];
     _replaceWebConfigs      = bool.Parse(configuration["ReplaceWebConfigs"]);
     _webDeployTimeout       = configuration.GetValue <int>("WebDeployTimeout");
     _sites = options.Value;
 }
 public WindowsServiceLifetime(Microsoft.Extensions.Hosting.IHostEnvironment environment, Microsoft.Extensions.Hosting.IHostApplicationLifetime applicationLifetime, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, Microsoft.Extensions.Options.IOptions <Microsoft.Extensions.Hosting.HostOptions> optionsAccessor)
 {
 }
Exemple #8
0
 public static bool IsStaging(this Microsoft.Extensions.Hosting.IHostEnvironment hostEnvironment)
 {
     throw null;
 }
Exemple #9
0
 public static bool IsEnvironment(this Microsoft.Extensions.Hosting.IHostEnvironment hostEnvironment, string environmentName)
 {
     throw null;
 }
Exemple #10
0
 public SystemdLifetime(Microsoft.Extensions.Hosting.IHostEnvironment environment, Microsoft.Extensions.Hosting.IHostApplicationLifetime applicationLifetime, Microsoft.Extensions.Hosting.Systemd.ISystemdNotifier systemdNotifier, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory)
 {
 }
 /// <summary>
 /// Instantiates a new <see cref="RestrictToDevelopmentMetricFilter"/>.
 /// </summary>
 /// <param name="hostEnvironment">The <see cref="Microsoft.Extensions.Hosting.IHostEnvironment"/> used to determine the hosting environment an application is running in.</param>
 public RestrictToDevelopmentMetricFilter(Microsoft.Extensions.Hosting.IHostEnvironment hostEnvironment) : base(hostEnvironment)
 {
 }
 /// <summary>
 /// Adds <see cref="IServerTimingMetricFilter"/> which will remove the descriptions from all metrics unless an application is running in development environment.
 /// </summary>
 /// <param name="options">The <see cref="ServerTimingOptions"/> to modify.</param>
 /// <param name="hostEnvironment">The <see cref="Microsoft.Extensions.Hosting.IHostEnvironment"/> used to determine the hosting environment an application is running in.</param>
 public static void RestrictDescriptionsToDevelopment(this ServerTimingOptions options, Microsoft.Extensions.Hosting.IHostEnvironment hostEnvironment)
 {
     options.Filters.Add(new RestrictDescriptionsToDevelopmentMetricFilter(hostEnvironment));
 }
 public static bool IsTestOrDevelopment(this IHostEnvironment env)
 {
     return(env.IsAnyEnvironment(Development, Test, Sqlite));
 }
 public static bool IsEnvironment(this IHostEnvironment env, string name)
 {
     return(String.Equals(env.EnvironmentName, name, StringComparison.CurrentCultureIgnoreCase));
 }
Exemple #15
0
 public ConsoleLifetime(Microsoft.Extensions.Options.IOptions <Microsoft.Extensions.Hosting.ConsoleLifetimeOptions> options, Microsoft.Extensions.Hosting.IHostEnvironment environment, Microsoft.Extensions.Hosting.IHostApplicationLifetime applicationLifetime, Microsoft.Extensions.Options.IOptions <Microsoft.Extensions.Hosting.HostOptions> hostOptions, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory)
 {
 }
 public ConsoleLifetime(Microsoft.Extensions.Options.IOptions <Microsoft.Extensions.Hosting.ConsoleLifetimeOptions> options, Microsoft.Extensions.Hosting.IHostEnvironment environment, Microsoft.Extensions.Hosting.IHostApplicationLifetime applicationLifetime)
 {
 }
 public static bool IsSqlite(this IHostEnvironment env)
 {
     return(env.IsEnvironment(Sqlite));
 }
 public DeleteModel(ddfgroup.Data.ApplicationDbContext context, Microsoft.Extensions.Hosting.IHostEnvironment hostEnvironment)
 {
     _context         = context;
     _hostEnvironment = hostEnvironment;
 }
Exemple #19
0
 /// <summary>
 /// 注入服务
 /// </summary>
 /// <param name="services"></param>
 /// <param name="env"></param>
 static void ConfigureServices(IServiceCollection services, IHostEnvironment env)
 {
     services.AddSingleton <IAreaCrawlingHandler, AreaCrawlingHandler>();
 }
 public static bool IsTest(this IHostEnvironment env)
 {
     return(env.IsEnvironment(Test));
 }
Exemple #21
0
 /// <summary>
 /// Instantiates a new <see cref="HostingEnvironmentServerTimingMetricFilter"/>.
 /// </summary>
 /// <param name="hostEnvironment">The <see cref="Microsoft.Extensions.Hosting.IHostEnvironment"/> used to determine the hosting environment an application is running in.</param>
 public HostingEnvironmentServerTimingMetricFilter(Microsoft.Extensions.Hosting.IHostEnvironment hostEnvironment)
 {
     IsDevelopment = hostEnvironment.EnvironmentName == Microsoft.Extensions.Hosting.Environments.Development;
     IsStaging     = hostEnvironment.EnvironmentName == Microsoft.Extensions.Hosting.Environments.Staging;
     IsProduction  = hostEnvironment.EnvironmentName == Microsoft.Extensions.Hosting.Environments.Production;
 }
 public static bool IsAnyEnvironment(this IHostEnvironment env, params string[] envs)
 {
     return(envs.ToList().Any(_env => env.IsEnvironment(_env)));
 }
Exemple #23
0
 public WindowsServiceLifetime(Microsoft.Extensions.Hosting.IHostEnvironment environment, Microsoft.Extensions.Hosting.IHostApplicationLifetime applicationLifetime, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory)
 {
 }
        /// <summary>
        ///   Adds the "Default" json file configuration to the <see cref="IConfigurationBuilder"/>.
        ///   This loads the files '.config/settings.json' and '.config/settings.&lt;Environment&gt;.json', and maps Key Vault secrets and Azure App Configuration keys into the configuration.
        ///   Key Vault:
        ///     Key Vault secrets are read from the Key Vault referenced by the '<see cref="ConfigurationConstants.KeyVaultUriConfigurationKey"/>' configuration value and used to replace any references of the form '[vault(my_special_secret_name)]' with the corresponding secret value
        ///   App Configuration:
        ///     App Configuration keys are retrieved from the '<see cref="ConfigurationConstants.AppConfigurationUriConfigurationKey"/>' configuration value and replace references matching '[config(my_app_config_key)]' with the key value
        ///
        ///   Authentication is handled by either MSI (optionally using the '<see cref="ConfigurationConstants.ManagedIdentityIdConfigurationKey"/>' configuration value for a user-assigned managed identity), or VS/az cli authentication.
        ///   Values will be refreshed every '<see cref="ConfigurationConstants.ReloadTimeSecondsConfigurationKey"/>' seconds.
        /// </summary>
        public static IConfigurationBuilder AddDefaultJsonConfiguration(this IConfigurationBuilder builder, IHostEnvironment hostEnvironment, string configPathFormat = ".config/settings{0}.json")
        {
            string rootConfigFile = string.Format(configPathFormat, "");
            string envConfigFile  = string.Format(configPathFormat, "." + hostEnvironment.EnvironmentName);

            IConfiguration bootstrapConfig = new ConfigurationBuilder()
                                             .SetBasePath(hostEnvironment.ContentRootPath)
                                             .AddJsonFile(rootConfigFile)
                                             .AddJsonFile(envConfigFile, optional: true)
                                             .Build();

            string reloadTimeString = bootstrapConfig[ConfigurationConstants.ReloadTimeSecondsConfigurationKey];

            if (!int.TryParse(reloadTimeString, out int reloadTimeSeconds))
            {
                reloadTimeSeconds = 5 * 60;
            }

            var reloadTime = TimeSpan.FromSeconds(reloadTimeSeconds);

            Func <string, string> keyVault         = KeyVaultConfigMapper.Create(bootstrapConfig);
            Func <string, string> appConfiguration = AppConfigurationConfigMapper.Create(bootstrapConfig);

            string Mapper(string v) => keyVault(appConfiguration(v));

            return(builder
                   .AddMappedJsonFile(rootConfigFile, reloadTime, Mapper)
                   .AddMappedJsonFile(envConfigFile, reloadTime, Mapper, optional: true));
        }