// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { var moudules = PluginExtensions.GetPluginSources <PluginModule>(); services.AddApplication <HostModule>(o => { o.PlugInSources.AddRange(moudules); }); PluginLoadContext.ShowTips = true; services.AddMvc().ConfigureApplicationPartManager(apm => { foreach (var type in moudules) { foreach (var part in new DefaultApplicationPartFactory().GetApplicationParts(type.Assembly)) { apm.ApplicationParts.Add(part); } } foreach (var pluginRazor in PluginExtensions.GetPluginRazors()) { apm.ApplicationParts.Add(pluginRazor); } }); AddControllers(services); }
/// <summary> /// Appends the Plugin Help Texts to be used in the ReadmeCommandHandler /// </summary> /// <param name="plugins">The plugins used to generate the readme</param> /// <returns>The readme</returns> private List <string> GenerateReadme(List <AbstractPlugin> plugins) { List <string> ret = new List <string>(); foreach (AbstractPlugin abstractPlugin in plugins) { Logger.Log(PPLogType.Log, Verbosity.Level1, "Generating Readme for plugin: {0}", abstractPlugin.GetType().Name); ret.AddRange(PluginExtensions.ToMarkdown(abstractPlugin)); } return(ret); }
/// <summary> /// Adds authentication service /// </summary> /// <param name="services">Collection of service descriptors</param> public static void AddGrandAuthentication(this IServiceCollection services, IConfiguration configuration) { var config = new AppConfig(); configuration.GetSection("Application").Bind(config); //set default authentication schemes var authenticationBuilder = services.AddAuthentication(options => { options.DefaultScheme = GrandCookieAuthenticationDefaults.AuthenticationScheme; options.DefaultSignInScheme = GrandCookieAuthenticationDefaults.ExternalAuthenticationScheme; }); //add main cookie authentication authenticationBuilder.AddCookie(GrandCookieAuthenticationDefaults.AuthenticationScheme, options => { options.Cookie.Name = config.CookiePrefix + GrandCookieAuthenticationDefaults.AuthenticationScheme; options.Cookie.HttpOnly = true; options.LoginPath = GrandCookieAuthenticationDefaults.LoginPath; options.AccessDeniedPath = GrandCookieAuthenticationDefaults.AccessDeniedPath; options.Cookie.SecurePolicy = config.CookieSecurePolicyAlways ? CookieSecurePolicy.Always : CookieSecurePolicy.SameAsRequest; }); //add external authentication authenticationBuilder.AddCookie(GrandCookieAuthenticationDefaults.ExternalAuthenticationScheme, options => { options.Cookie.Name = config.CookiePrefix + GrandCookieAuthenticationDefaults.ExternalAuthenticationScheme; options.Cookie.HttpOnly = true; options.LoginPath = GrandCookieAuthenticationDefaults.LoginPath; options.AccessDeniedPath = GrandCookieAuthenticationDefaults.AccessDeniedPath; options.Cookie.SecurePolicy = config.CookieSecurePolicyAlways ? CookieSecurePolicy.Always : CookieSecurePolicy.SameAsRequest; }); //register external authentication plugins now var typeSearcher = new AppTypeSearcher(); var externalAuthConfigurations = typeSearcher.ClassesOfType <IAuthenticationBuilder>(); var externalAuthInstances = externalAuthConfigurations .Where(x => PluginExtensions.OnlyInstalledPlugins(x)) .Select(x => (IAuthenticationBuilder)Activator.CreateInstance(x)) .OrderBy(x => x.Priority); //add new Authentication foreach (var instance in externalAuthInstances) { instance.AddAuthentication(authenticationBuilder, configuration); } }
/// <summary> /// Configure MVC endpoint /// </summary> /// <param name="application">Builder for configuring an application's request pipeline</param> public static void UseGrandEndpoints(this IApplicationBuilder application) { application.UseEndpoints(endpoints => { var typeSearcher = endpoints.ServiceProvider.GetRequiredService <ITypeSearcher>(); var endpointProviders = typeSearcher.ClassesOfType <IEndpointProvider>(); var instances = endpointProviders .Where(endpointProvider => PluginExtensions.OnlyInstalledPlugins(endpointProvider)) .Select(endpointProvider => (IEndpointProvider)Activator.CreateInstance(endpointProvider)) .OrderByDescending(endpointProvider => endpointProvider.Priority); foreach (var endpointProvider in instances) { endpointProvider.RegisterEndpoint(endpoints); } }); }
/// <summary> /// Configure HTTP request pipeline /// </summary> /// <param name="application">Builder for configuring an application's request pipeline</param> /// <param name="webHostEnvironment">WebHostEnvironment</param> public static void ConfigureRequestPipeline(IApplicationBuilder application, IWebHostEnvironment webHostEnvironment) { //find startup configurations provided by other assemblies var typeSearcher = new AppTypeSearcher(); var startupConfigurations = typeSearcher.ClassesOfType <IStartupApplication>(); //create and sort instances of startup configurations var instances = startupConfigurations .Where(startup => PluginExtensions.OnlyInstalledPlugins(startup)) .Select(startup => (IStartupApplication)Activator.CreateInstance(startup)) .OrderBy(startup => startup.Priority); //configure request pipeline foreach (var instance in instances) { instance.Configure(application, webHostEnvironment); } }
/// <summary> /// Add and configure any of the middleware /// </summary> /// <param name="services">Collection of service descriptors</param> /// <param name="configuration">Configuration root of the application</param> public void ConfigureServices(IServiceCollection services, IConfiguration configuration) { //database is already installed, so start scheduled tasks if (DataSettingsManager.DatabaseIsInstalled()) { var typeSearcher = new AppTypeSearcher(); var scheduleTasks = typeSearcher.ClassesOfType <IScheduleTask>(); var scheduleTasksInstalled = scheduleTasks .Where(t => PluginExtensions.OnlyInstalledPlugins(t)); //ignore not installed plugins foreach (var task in scheduleTasksInstalled) { var assemblyName = task.Assembly.GetName().Name; services.AddSingleton <IHostedService, BackgroundServiceTask>(sp => { return(new BackgroundServiceTask($"{task.FullName}, {assemblyName}", sp)); }); } } }
/// <summary> /// A underlying function to handle the --help and the --help-all command /// </summary> /// <param name="helpParams">Either HelpParams or HelpAllParams</param> /// <param name="extendedDescription">Indicator if the extended description should be used.</param> /// <returns>Returns true if the CLI should exit after this command</returns> private bool Help_Command_Unfied(string[] helpParams, bool extendedDescription) { if (helpParams == null) { return(false); } if (helpParams.Length == 0) { Logger.Log(PPLogType.Log, Verbosity.Silent, "\n{0}", Info.ListAllCommands(new[] { "" }).Unpack("\n")); return(true); } foreach (string file in helpParams) { if (file != "self") { ParseChainSyntax(file, out string path, out string[] names); if (pluginManager.DisplayHelp(path, names, !extendedDescription)) { continue; } List <AbstractPlugin> plugins = CreatePluginChain(new[] { file }, true).ToList(); Logger.Log(PPLogType.Log, Verbosity.Silent, "Listing Plugins: "); foreach (AbstractPlugin plugin in plugins) { Logger.Log(PPLogType.Log, Verbosity.Silent, "\n{0}", PluginExtensions.ListInfo(plugin, true).Unpack("\n")); } } else { Logger.Log(PPLogType.Log, Verbosity.Silent, "\n{0}", Info.ListAllCommands(new[] { "" }).Unpack("\n")); } } return(true); }
public SettingsView(IThemeProvider themeProvider, IMessenger messenger) { InitializeComponent(); this.RegisterHelp(messenger, Topics.Home); themeProvider.GetCurrentTheme().ApplyTo(this.txtCsFolder); themeProvider.GetCurrentTheme().ApplyTo(this.txtJsFolder); themeProvider.GetCurrentTheme().ApplyTo(this.txtCsNamespace); themeProvider.GetCurrentTheme().ApplyTo(this.txtJsNamespace); themeProvider.GetCurrentTheme().ApplyTo(this.txtJsHeaders); themeProvider.GetCurrentTheme().ApplyTo(this.cmbSolutionList); messenger.Register <LoadSolutionsCompleted>(OnLoadSolutionCompleted); messenger.Register <ExportCompleted>(m => this.Enabled = true); this.RefreshView(); this.messenger = messenger; this.Icon = PluginExtensions.GetIcon(); }
/// <summary> /// Register and init AutoMapper /// </summary> /// <param name="typeSearcher">Type finder</param> private static void InitAutoMapper(ITypeSearcher typeSearcher) { //find mapper configurations provided by other assemblies var mapperConfigurations = typeSearcher.ClassesOfType <IAutoMapperProfile>(); //create and sort instances of mapper configurations var instances = mapperConfigurations .Where(mapperConfiguration => PluginExtensions.OnlyInstalledPlugins(mapperConfiguration)) .Select(mapperConfiguration => (IAutoMapperProfile)Activator.CreateInstance(mapperConfiguration)) .OrderBy(mapperConfiguration => mapperConfiguration.Order); //create AutoMapper configuration var config = new MapperConfiguration(cfg => { foreach (var instance in instances) { cfg.AddProfile(instance.GetType()); } }); //register automapper AutoMapperConfig.Init(config); }
/// <summary> /// The command handler that is used for the command --generate-readme /// </summary> /// <returns>Returns true if the CLI should exit after this command</returns> private bool ReadmeCommandHandler() { if (ReadmeArgs.Length == 2) { if (ReadmeArgs[0] == "self") { Logger.Log(PPLogType.Log, Verbosity.Level1, "Generating Readme for self."); List <string> ret = PluginExtensions.ToMarkdown(Info).ToList(); Logger.Log(PPLogType.Log, Verbosity.Level1, "Writing Readme to file: {0}", ReadmeArgs[1]); File.WriteAllLines(ReadmeArgs[1], ret.ToArray()); return(true); } Logger.Log(PPLogType.Log, Verbosity.Level1, "Generating Readme for file: {0}", ReadmeArgs[0]); PluginManager.PluginManager pm = new PluginManager.PluginManager(); List <string> ht = GenerateReadme(pm.FromFile(ReadmeArgs[0])); Logger.Log(PPLogType.Log, Verbosity.Level1, "Writing Readme to file: {0}", ReadmeArgs[1]); File.WriteAllLines(ReadmeArgs[1], ht.ToArray()); return(true); } return(false); }
/// <summary> /// Add and configure services /// </summary> /// <param name="services">Collection of service descriptors</param> /// <param name="configuration">Configuration root of the application</param> public static void ConfigureServices(IServiceCollection services, IConfiguration configuration) { //register application var mvcBuilder = RegisterApplication(services, configuration); //register extensions RegisterExtensions(mvcBuilder, configuration); //find startup configurations provided by other assemblies var typeSearcher = new AppTypeSearcher(); services.AddSingleton <ITypeSearcher>(typeSearcher); var startupConfigurations = typeSearcher.ClassesOfType <IStartupApplication>(); //Register startup var instancesBefore = startupConfigurations .Where(startup => PluginExtensions.OnlyInstalledPlugins(startup)) .Select(startup => (IStartupApplication)Activator.CreateInstance(startup)) .Where(startup => startup.BeforeConfigure) .OrderBy(startup => startup.Priority); //configure services foreach (var instance in instancesBefore) { instance.ConfigureServices(services, configuration); } //register mapper configurations InitAutoMapper(typeSearcher); //add fluenvalidation AddFluentValidation(mvcBuilder, typeSearcher); //Register custom type converters RegisterTypeConverter(typeSearcher); var config = new AppConfig(); configuration.GetSection("Application").Bind(config); //run startup tasks if (!config.IgnoreStartupTasks) { ExecuteStartupTasks(typeSearcher); } //add mediator AddMediator(services, typeSearcher); //Add MassTransit AddMassTransitRabbitMq(services, config, typeSearcher); //Register startup var instancesAfter = startupConfigurations .Where(startup => PluginExtensions.OnlyInstalledPlugins(startup)) .Select(startup => (IStartupApplication)Activator.CreateInstance(startup)) .Where(startup => !startup.BeforeConfigure) .OrderBy(startup => startup.Priority); //configure services foreach (var instance in instancesAfter) { instance.ConfigureServices(services, configuration); } }
public virtual bool ShouldPopulate() { Log.Debug("GenericModButton.ShouldPopulate() called for " + Name, false); return(Tool != null || Widnow != null || PluginExtensions.IsActive(Plugin)); }