public void ResolveModuleDependencies() { foreach (var module in _KraftModulesCollection) { KraftModule kraftModule = module.Value as KraftModule; kraftModule.ConstructDependencies(); } _KraftModulesCollection = _KraftModulesCollection.SortByDependencies(); int k = 0; foreach (var module in _KraftModulesCollection) { KraftModule kraftModule = module.Value as KraftModule; //Check the version foreach (KeyValuePair <string, IDependable <KraftModule> > dependency in kraftModule.Dependencies) { string requiredVersion = kraftModule.KraftModuleRootConf.Dependencies.First(item => item.Key == dependency.Key).Value; KraftModule actualModule = (_KraftModulesCollection.Values.First(m => m.Key == dependency.Key) as KraftModule); string moduleVersion = actualModule.KraftModuleRootConf.Version; KraftModuleVersion versionChecker = new KraftModuleVersion(moduleVersion, requiredVersion); if (!versionChecker.IsEqualOrHigher()) { throw new Exception($"The required version: {requiredVersion} defined in module: {kraftModule.Key} is not complient with actual version: {moduleVersion} of module: {actualModule.Key}"); } } kraftModule.DependencyOrderIndex = k; k++; //call sorting for the modules kraftModule.Dependencies = kraftModule.Dependencies.SortByDependencyOrderIndex(); } }
static void Dive(KraftModule kmodule, HashSet <KraftModule> deps) { foreach (var dep in kmodule.Dependencies) { Dive(dep.Value as KraftModule, deps); } deps.Add(kmodule); }
//Called from the Razor-Views or master page public static Scripts KraftScripts(this Profile profile, string moduleDepStartFile = RESOURCEDEPENDENCY_FILE_NAME, string rootVirtualPath = "/modules") { if (!profile.HasScriptBundle(profile.Key + "-scripts")) { ScriptBundle scriptBundle = new ScriptBundle(profile.Key + "-scripts", new PhysicalFileProvider(_ModulesCollection.KraftGlobalConfigurationSettings.EnvironmentSettings.ContentRootPath), null, new List <IBundleTransform>(), false); StringBuilder contentTemplates = new StringBuilder(10000); bool appendDiv = false; //try to get the target module KraftModule profileTargetModule = _ModulesCollection.GetModule(profile.Key); if (profileTargetModule == null) { throw new Exception($"No CoreKraft module found for bundle target \"{profile.Key}\"!"); } HashSet <KraftModule> targetDeps = new HashSet <KraftModule>(); Dive(profileTargetModule, targetDeps); List <KraftModule> targetDepsSorted = targetDeps.OrderBy(x => x.DependencyOrderIndex).ToList <KraftModule>(); foreach (KraftModule kraftDepModule in targetDepsSorted) { kraftDepModule.ConstructResources(_CachingService, kraftDepModule.DirectoryName, moduleDepStartFile, true); if (kraftDepModule.ScriptKraftBundle != null) { using (KraftProfiler.Current.Step($"Time loading {kraftDepModule.Key}: ")) { scriptBundle.Include(new KraftRequireTransformation().Process(kraftDepModule.ScriptKraftBundle, kraftDepModule.ModulePath, kraftDepModule.Key, rootVirtualPath, _Logger)); scriptBundle.Transforms.Add(new JsCleanupTransformation()); } } if (kraftDepModule.TemplateKraftBundle != null && kraftDepModule.TemplateKraftBundle.TemplateFiles.Count > 0) { if (appendDiv) { contentTemplates.Append(","); } else { appendDiv = true; } HtmlTransformation htmlTransformation = new HtmlTransformation(); Func <StringBuilder, ILogger, StringBuilder> minifyHtml = htmlTransformation.Process; contentTemplates.Append(new KraftHtml2JsAssocArrayTransformation().Process(kraftDepModule.TemplateKraftBundle, minifyHtml, _Logger)); } } scriptBundle.IncludeContent("Registers.addRegister(new TemplateRegister(\"module_templates\")); Registers.getRegister(\"module_templates\").$collection= {" + contentTemplates.Append("}")); profile.Add(scriptBundle); return(profile.Scripts); } else { return(profile.Scripts); } }
public virtual KraftModule RegisterModule(string directoryName, ICachingService cachingService) { KraftModule module = new KraftModule(directoryName, _DependencyInjectionContainer, this, cachingService, KraftGlobalConfigurationSettings, _Logger); if (module != null && !_KraftModulesCollection.ContainsKey(module.Key)) { _KraftModulesCollection.Add(module.Key, module); } return(module); }
public List <KraftModule> GetSortedModules() { List <KraftModule> sortedModules = new List <KraftModule>(); foreach (KeyValuePair <string, IDependable <KraftModule> > module in _KraftModulesCollection) { KraftModule kraftModule = module.Value as KraftModule; sortedModules.Add(kraftModule); } return(sortedModules); }
//Called from the Razor-Views or master page public static Scripts KraftScripts(this Profile profile, string moduleDepStartFile = RESOURCEDEPENDENCY_FILE_NAME) { if (!profile.HasScriptBundle(profile.Key + "-scripts")) { ScriptBundle scriptBundle = new ScriptBundle(profile.Key + "-scripts", new PhysicalFileProvider(_ModulesCollection.KraftGlobalConfigurationSettings.EnvironmentSettings.ContentRootPath), null, new List <IBundleTransform>(), false); StringBuilder contentTemplates = new StringBuilder(10000); bool appendDiv = false; //try to get the target module KraftModule profileTargetModule = _ModulesCollection.GetModule(profile.Key); if (profileTargetModule == null) { throw new Exception($"No CoreKraft module found for bundle target \"{profile.Key}\"!"); }
//Called from the Razor-Views or master page public static Styles KraftStyles(this Profile profile, string moduleDepStartFile = RESOURCEDEPENDENCY_FILE_NAME) { if (!profile.HasStyleBundle(profile.Key + "-css")) { StyleBundle styleBundle = new StyleBundle(profile.Key + "-css", new PhysicalFileProvider(_ModulesCollection.KraftGlobalConfigurationSettings.EnvironmentSettings.ContentRootPath)); styleBundle.RemoveTransformationType(typeof(LessTransformation)); StringBuilder contentTemplates = new StringBuilder(10000); //try to get the target module KraftModule profileTargetModule = _ModulesCollection.GetModule(profile.Key); if (profileTargetModule == null) { throw new Exception($"No CoreKraft module found for bundle target \"{profile.Key}\"!"); } void Dive(KraftModule kmodule, HashSet <KraftModule> deps) { foreach (var dep in kmodule.Dependencies) { Dive(dep.Value as KraftModule, deps); } deps.Add(kmodule); } HashSet <KraftModule> targetDeps = new HashSet <KraftModule>(); Dive(profileTargetModule, targetDeps); List <KraftModule> targetDepsSorted = targetDeps.OrderBy(x => x.DependencyOrderIndex).ToList <KraftModule>(); foreach (KraftModule kraftDepModule in targetDepsSorted) { kraftDepModule.ConstructResources(_CachingService, _KraftGlobalConfigurationSettings, moduleDepStartFile, false); if (kraftDepModule.StyleKraftBundle != null) { styleBundle.Include(new KraftRequireTransformation().Process(kraftDepModule.StyleKraftBundle, _Logger)); } } profile.Add(styleBundle); return(profile.Styles); } else { return(profile.Styles); } }
private Dictionary <string, string> Collect(List <string> modulesRootFolders) { Dictionary <string, string> allReferencedModules = new Dictionary <string, string>(); foreach (string dir in modulesRootFolders) { string[] moduleDirectories = Directory.GetDirectories(dir); foreach (string subdirectory in moduleDirectories) { DirectoryInfo moduleDirectory = new DirectoryInfo(subdirectory); if (moduleDirectory.Exists && KraftModule.IsValidKraftModule(moduleDirectory.FullName)) { if (!allReferencedModules.ContainsKey(moduleDirectory.Name.ToLower())) { allReferencedModules.Add(moduleDirectory.Name.ToLower(), moduleDirectory.FullName); } } } } return(allReferencedModules); }
//Called from the Razor-Views or master page public static Scripts KraftScripts(this Profile profile) { if (!profile.HasScriptBundle(profile.Key + "-scripts")) { KraftModuleCollection modulesCollection = _Builder.ApplicationServices.GetService <KraftModuleCollection>(); ScriptBundle scriptBundle = new ScriptBundle(profile.Key + "-scripts", new PhysicalFileProvider(modulesCollection.KraftGlobalConfigurationSettings.EnvironmentSettings.ContentRootPath)); StringBuilder contentTemplates = new StringBuilder(10000); bool appendDiv = false; //try to get the target module KraftModule profileTargetModule = modulesCollection.GetModule(profile.Key); if (profileTargetModule == null) { throw new Exception($"No CoreKraft module found for bundle target \"{profile.Key}\"!"); } void Dive(KraftModule kmodule, HashSet <KraftModule> deps) { foreach (var dep in kmodule.Dependencies) { Dive(dep.Value as KraftModule, deps); } deps.Add(kmodule); } HashSet <KraftModule> targetDeps = new HashSet <KraftModule>(); Dive(profileTargetModule, targetDeps); List <KraftModule> targetDepsSorted = targetDeps.OrderBy(x => x.DependencyOrderIndex).ToList <KraftModule>(); foreach (KraftModule kraftDepModule in targetDepsSorted) { if (kraftDepModule.ScriptKraftBundle != null) { using (KraftProfiler.Current.Step($"Time loading {kraftDepModule.Key}: ")) { scriptBundle.Include(new KraftRequireTransformation().Process(kraftDepModule.ScriptKraftBundle, _Logger)); } } if (kraftDepModule.TemplateKraftBundle != null && kraftDepModule.TemplateKraftBundle.TemplateFiles.Count > 0) { if (appendDiv) { contentTemplates.Append(","); } else { appendDiv = true; } HtmlTransformation htmlTransformation = new HtmlTransformation(); Func <StringBuilder, ILogger, StringBuilder> minifyHtml = htmlTransformation.Process; contentTemplates.Append(new KraftHtml2JsAssocArrayTransformation().Process(kraftDepModule.TemplateKraftBundle, minifyHtml, _Logger)); } } scriptBundle.IncludeContent("Registers.addRegister(new TemplateRegister(\"module_templates\")); Registers.getRegister(\"module_templates\").$collection= {" + contentTemplates.Append("}")); profile.Add(scriptBundle); return(profile.Scripts); } else { return(profile.Scripts); } }