using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Caching.Memory; using Shared.Models.SISI.Base; namespace Shared.Models.Module.Entrys { public class SisiModuleEntry { public RootModule mod; // version >= 3 public Func> Invoke = null; public Func>> InvokeAsync = null; // version < 3 public Func> Events = null; public static List sisiModulesCache = null; static readonly object _sisiModulesCacheLock = new object(); public static void EnsureCache(bool forced = false) { if (AppInit.modules == null) return; if (forced == false && sisiModulesCache != null) return; lock (_sisiModulesCacheLock) { if (forced == false && sisiModulesCache != null) return; sisiModulesCache = new List(); try { foreach (var mod in AppInit.modules.Where(i => i.sisi != null && i.enable)) { try { var entry = new SisiModuleEntry() { mod = mod }; var assembly = mod.assembly; if (assembly == null) continue; var type = assembly.GetType(mod.NamespacePath(mod.sisi)); if (type == null) continue; if (mod.version >= 3) { try { var m = type.GetMethod("Invoke"); if (m != null) { entry.Invoke = (Func>)Delegate.CreateDelegate( typeof(Func>), m); } } catch { } try { var m2 = type.GetMethod("InvokeAsync"); if (m2 != null) { entry.InvokeAsync = (Func>>)Delegate.CreateDelegate( typeof(Func>>), m2); } } catch { } } else { try { var m = type.GetMethod("Events"); if (m != null) { entry.Events = (Func>)Delegate.CreateDelegate( typeof(Func>), m); } } catch { } } if (entry.Invoke != null || entry.InvokeAsync != null || entry.Events != null) sisiModulesCache.Add(entry); } catch { } } } catch { } } } } }