public CassetteNancyPluginRegistrations() { AppDomainAssemblyTypeScanner.AddAssembliesToScan(new string[] { "Cassette.CoffeeScript.dll" , "Cassette.Hogan.dll" , "Cassette.JQueryTmpl.dll" , "Cassette.KnockoutJQueryTmpl.dll" , "Cassette.Less.dll" , "Cassette.Sass.dll" }); }
/// <summary> /// Locates all the default conventions and calls them in /// turn to build up the default conventions. /// </summary> private void BuildDefaultConventions() { this.conventions = AppDomainAssemblyTypeScanner .TypesOf <IConvention>() .Select(t => (IConvention)Activator.CreateInstance(t)); foreach (var convention in this.conventions) { convention.Initialise(this); } }
private void ConfigureNamespaces(IEnumerable <PluginConfiguration> plugins) { foreach (var plugin in plugins) { ResourceViewLocationProvider.RootNamespaces.Add(plugin.GetType().Assembly, plugin.ViewLocation); } ResourceViewLocationProvider.RootNamespaces.Add(typeof(KolaNancyBootstrapper).Assembly, "Kola.Nancy"); ResourceViewLocationProvider.Ignore.Add(typeof(RazorViewEngine).Assembly); ResourceViewLocationProvider.Ignore.Add(Assembly.Load("System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")); AppDomainAssemblyTypeScanner.AddAssembliesToScan(AppDomainAssemblyTypeScanner.DefaultAssembliesToScan.ToArray()); }
/// <summary> /// 启动 /// </summary> /// <param name="args"></param> public void Run(string[] args) { if (this.EnableBanner) { Console.WriteLine(this.banner); Console.WriteLine(); } if (serviceRunning) { throw new Exception($"服务[{serviceName}]已运行,不能重复运行!"); } this.registedModules = from t in AppDomainAssemblyTypeScanner .TypesOf <INancyModule>(ScanMode.ExcludeNancyNamespace) select new ModuleRegistration(t); if (args.Contains("--console")) { WriteToLog($"服务[{serviceName}]正在使用控制台模式启动"); //run in console this.InternalRun(); this.ServiceRunningMode = RunningMode.Console; this.OnServiceStarted?.Invoke(this); WriteToLog($"服务[{serviceName}]使用控制台模式启动成功,按 ENTER 退出控制台程序!"); Console.ReadLine(); this.Stop(); } else if (args.Contains("--install")) { serviceManager.Install(); serviceManager.Start(); } else if (args.Contains("--uninstall")) { serviceManager.Stop(); serviceManager.UnInstall(); } else { //window service main entry var servicesToRun = new ServiceBase[] { new InternalService(this) }; WriteToLog($"服务[{serviceName}]正在使用Window服务模式启动"); ServiceBase.Run(servicesToRun); this.ServiceRunningMode = RunningMode.WindowsService; this.OnServiceStarted?.Invoke(this); WriteToLog($"服务[{serviceName}]使用Window服务模式启动成功"); } }
public void Should_ingore_assemblies_specified_in_AppDomainAssemblyTypeScanner() { // Given // When AppDomainAssemblyTypeScanner.IgnoredAssemblies = new Func <Assembly, bool>[] { asm => asm.FullName.StartsWith("mscorlib") }; // Then AppDomainAssemblyTypeScanner.TypesOf <IEnumerable>().Where(t => t.Assembly.FullName.StartsWith("mscorlib")).Count().ShouldEqual(0); }
/// <summary> /// Locates all the default conventions and calls them in /// turn to build up the default conventions. /// </summary> private void BuildDefaultConventions() { var defaultConventions = AppDomainAssemblyTypeScanner.TypesOf <IConvention>(ScanMode.OnlyNancy); this.conventions = defaultConventions .Union(AppDomainAssemblyTypeScanner.TypesOf <IConvention>(ScanMode.ExcludeNancy)) .Select(t => (IConvention)Activator.CreateInstance(t)); foreach (var convention in this.conventions) { convention.Initialise(this); } }
private static bool GetDebugMode() { try { var assembliesInDebug = AppDomainAssemblyTypeScanner .TypesOf <INancyModule>(ScanMode.ExcludeNancy) .Select(x => x.Assembly.GetCustomAttributes(typeof(DebuggableAttribute), true)) .Where(x => x.Length != 0); return(assembliesInDebug.Any(d => ((DebuggableAttribute)d[0]).IsJITTrackingEnabled)); } catch { return(false); } }
static void Main(string[] args) { AppDomainAssemblyTypeScanner.LoadAssemblies(new RelativePathProvider().GetRootPath(), "*.dll"); var options = new StartOptions { ServerFactory = "Nowin", Port = 8080, }; using (WebApp.Start <HigginsStartupSelfHost>(options)) { Console.WriteLine("Running a http server on port 8080"); Console.ReadKey(); } }
public static RestExceptionRepackagingRegistrar Configure(Action <RestExceptionConfiguration> config) { var configurer = new RestExceptionConfiguration(); var repackagers = AppDomainAssemblyTypeScanner.TypesOf <IExceptionRepackager>(ScanMode.ExcludeNancy); repackagers.ToList().ForEach( x => configurer.WithRepackager((IExceptionRepackager)Activator.CreateInstance(x))); configurer.WithDefault(new InternalServerExceptionRepackager()); config(configurer); return(new RestExceptionRepackagingRegistrar(configurer)); }
// public void Load() void RecursivelyLoad(string path) { // 20150826 // if (!Directory.Exists(_path)) return; if (!Directory.Exists(path)) { return; } try { // 20150826 // var dir = new DirectoryInfo(_path); var dir = new DirectoryInfo(path); // var files = dir.GetFiles(@"Nancy.ViewEngines*.dll"); var files = dir.GetFiles(_fileNameTemplate); // 20150317 // if (null == files || !files.Any()) return; if (!files.Any()) { return; } foreach (var probablyAssembly in files) { try { var assembly = Assembly.LoadFrom(probablyAssembly.FullName); AppDomainAssemblyTypeScanner.AddAssembliesToScan(assembly.FullName); } catch {} } // 20150617 if (_recurse) { var subDirs = dir.GetDirectories(); // if (!subDirs.Any()) return; if (subDirs.Any()) { foreach (var subDir in subDirs) { RecursivelyLoad(subDir.FullName); } } } // AppDomainAssemblyTypeScanner.UpdateTypes(); } catch {} }
private static bool GetDebugMode() { try { //Get all non-nancy assemblies, and select the custom attributes var assembliesInDebug = AppDomainAssemblyTypeScanner.TypesOf <INancyModule>(ScanMode.ExcludeNancy) .Select(x => x.Assembly.GetCustomAttributes(typeof(DebuggableAttribute), true)) .Where(x => x.Length != 0); //if there are any, then return the IsJITTrackingEnabled //else if the collection is empty it returns false return(assembliesInDebug.Any(d => ((DebuggableAttribute)d[0]).IsJITTrackingEnabled)); } catch (Exception) { // Evil catch all - don't want to blow up trying to detect debug mode! return(false); } }
protected override void ConfigureApplicationContainer(global::Nancy.TinyIoc.TinyIoCContainer container) { // TODO: support multiple doc-stores var docStore = new DocumentStore { ConnectionStringName = "RavenDB" }; var conventions = docStore.Conventions; conventions.FindFullDocumentKeyFromNonStringIdentifier = (o, type, arg3) => { var ret = conventions.DefaultFindFullDocumentKeyFromNonStringIdentifier(o, type, arg3); var areaConfigs = HttpContext.Current.Items["AreaConfigs"] as AreaConfigs; if (areaConfigs != null) { ret = areaConfigs.DocumentsPrefix + ret; } return(ret); }; conventions.TransformTypeTagNameToDocumentKeyPrefix = s => { var ret = DocumentConvention.DefaultTransformTypeTagNameToDocumentKeyPrefix(s); var areaConfigs = HttpContext.Current.Items["AreaConfigs"] as AreaConfigs; if (areaConfigs != null) { ret = areaConfigs.DocumentsPrefix + ret; } return(ret); }; AppDomainAssemblyTypeScanner.LoadAssembliesWithNancyReferences(); docStore.Initialize(); container.Register <IDocumentStore>(docStore, "DocStore"); base.ConfigureApplicationContainer(container); }
private static bool GetDebugMode() { try { var assembly = AppDomainAssemblyTypeScanner.TypesOf <NancyModule>(true).FirstOrDefault().Assembly; var attributes = assembly.GetCustomAttributes(typeof(DebuggableAttribute), true); if (attributes.Length == 0) { return(false); } var d = (DebuggableAttribute)attributes[0]; return(d.IsJITTrackingEnabled); } catch (Exception) { // Evil catch all - don't want to blow up trying to detect debug mode! return(false); } }
public void Load() { RecursivelyLoad(_path); AppDomainAssemblyTypeScanner.UpdateTypes(); }
public GlimpseRegistrations() { AppDomainAssemblyTypeScanner.AddAssembliesToScan(typeof(Glimpse.Core.Tab.Timeline).Assembly); }
// The bootstrapper enables you to reconfigure the composition of the framework, // by overriding the various methods and properties. // For more information https://github.com/NancyFx/Nancy/wiki/Bootstrapper public Bootstrapper() { AppDomainAssemblyTypeScanner.AddAssembliesToScan("photoCore.dll"); }
static TestBootstrapper() { var assemblyPath = Extension.ResolvePath(TestRootPathProvider.RootPath, "bin"); AppDomainAssemblyTypeScanner.LoadAssemblies(assemblyPath, "Nancy.ViewEngines.React.*dll"); }
private string[] GetViewEngines() { var engines = AppDomainAssemblyTypeScanner.TypesOf <IViewEngine>(); return(engines.Select(engine => engine.Name.Split(new [] { "ViewEngine" }, StringSplitOptions.None)[0]).ToArray()); }