public ScriptContext Init() { if (HasInit) { return(this); } HasInit = true; Args[ScriptConstants.Debug] = DebugMode; Container.AddSingleton(() => this); Container.AddSingleton(() => Pages); var beforePlugins = Plugins.OfType <IScriptPluginBefore>(); foreach (var plugin in beforePlugins) { plugin.BeforePluginsLoaded(this); } foreach (var plugin in Plugins) { plugin.Register(this); } OnAfterPlugins?.Invoke(this); foreach (var type in ScanTypes) { ScanType(type); } foreach (var assembly in ScanAssemblies.Safe()) { foreach (var type in assembly.GetTypes()) { ScanType(type); } } foreach (var method in ScriptMethods) { InitMethod(method); } foreach (var block in ScriptBlocks) { InitBlock(block); blocksMap[block.Name] = block; } var afterPlugins = Plugins.OfType <IScriptPluginAfter>(); foreach (var plugin in afterPlugins) { plugin.AfterPluginsLoaded(this); } return(this); }
public ScriptContext Init() { if (HasInit) { return(this); } HasInit = true; if (InsertScriptMethods.Count > 0) { ScriptMethods.InsertRange(0, InsertScriptMethods); } if (InsertScriptBlocks.Count > 0) { ScriptBlocks.InsertRange(0, InsertScriptBlocks); } if (InsertPlugins.Count > 0) { Plugins.InsertRange(0, InsertPlugins); } foreach (var assembly in ScanAssemblies.Safe()) { foreach (var type in assembly.GetTypes()) { if (typeof(IScriptPlugin).IsAssignableFrom(type)) { if (Plugins.All(x => x.GetType() != type)) { Container.AddSingleton(type); var plugin = (IScriptPlugin)Container.Resolve(type); Plugins.Add(plugin); } } } } Args[ScriptConstants.Debug] = DebugMode; Container.AddSingleton(() => this); Container.AddSingleton(() => Pages); ScriptLanguagesArray = ScriptLanguages.Distinct().ToArray(); foreach (var scriptLanguage in ScriptLanguagesArray) { scriptLanguagesMap[scriptLanguage.Name] = scriptLanguage; if (scriptLanguage is IConfigureScriptContext init) { init.Configure(this); } } var beforePlugins = Plugins.OfType <IScriptPluginBefore>(); foreach (var plugin in beforePlugins) { plugin.BeforePluginsLoaded(this); } foreach (var plugin in Plugins) { plugin.Register(this); } OnAfterPlugins?.Invoke(this); foreach (var type in ScanTypes) { ScanType(type); } foreach (var assembly in ScanAssemblies.Safe()) { foreach (var type in assembly.GetTypes()) { ScanType(type); } } foreach (var method in ScriptMethods) { InitMethod(method); } foreach (var block in ScriptBlocks) { InitBlock(block); blocksMap[block.Name] = block; } ScriptNamespaces = ScriptNamespaces.Distinct().ToList(); var allTypes = new List <Type>(ScriptTypes); foreach (var asm in ScriptAssemblies) { allTypes.AddRange(asm.GetTypes()); } foreach (var type in allTypes) { if (!ScriptTypeNameMap.ContainsKey(type.Name)) { ScriptTypeNameMap[type.Name] = type; } var qualifiedName = ProtectedMethods.typeQualifiedName(type); if (!ScriptTypeQualifiedNameMap.ContainsKey(qualifiedName)) { ScriptTypeQualifiedNameMap[qualifiedName] = type; } } var afterPlugins = Plugins.OfType <IScriptPluginAfter>(); foreach (var plugin in afterPlugins) { plugin.AfterPluginsLoaded(this); } return(this); }
public ScriptContext Init() { if (HasInit) { return(this); } HasInit = true; if (InsertScriptMethods.Count > 0) { ScriptMethods.InsertRange(0, InsertScriptMethods); } if (InsertScriptBlocks.Count > 0) { ScriptBlocks.InsertRange(0, InsertScriptBlocks); } if (InsertPlugins.Count > 0) { Plugins.InsertRange(0, InsertPlugins); } foreach (var assembly in ScanAssemblies.Safe()) { foreach (var type in assembly.GetTypes()) { if (typeof(IScriptPlugin).IsAssignableFrom(type)) { if (Plugins.All(x => x.GetType() != type)) { Container.AddSingleton(type); var plugin = (IScriptPlugin)Container.Resolve(type); Plugins.Add(plugin); } } } } Args[ScriptConstants.Debug] = DebugMode; Container.AddSingleton(() => this); Container.AddSingleton(() => Pages); var beforePlugins = Plugins.OfType <IScriptPluginBefore>(); foreach (var plugin in beforePlugins) { plugin.BeforePluginsLoaded(this); } foreach (var plugin in Plugins) { plugin.Register(this); } OnAfterPlugins?.Invoke(this); foreach (var type in ScanTypes) { ScanType(type); } foreach (var assembly in ScanAssemblies.Safe()) { foreach (var type in assembly.GetTypes()) { ScanType(type); } } foreach (var method in ScriptMethods) { InitMethod(method); } foreach (var block in ScriptBlocks) { InitBlock(block); blocksMap[block.Name] = block; } var afterPlugins = Plugins.OfType <IScriptPluginAfter>(); foreach (var plugin in afterPlugins) { plugin.AfterPluginsLoaded(this); } return(this); }