using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Caching.Memory; namespace Shared.Models.Module.Entrys { public class OnlineModuleEntry { public RootModule mod; // version >= 3 public Func> Invoke = null; public Func>> InvokeAsync = null; public Func> Spider = null; public Func>> SpiderAsync = null; // version < 3 public Func> Events = null; public Func>> EventsAsync = null; public static List onlineModulesCache = null; static readonly object _onlineModulesCacheLock = new object(); public static void EnsureCache(bool forced = false) { if (AppInit.modules == null) return; if (forced == false && onlineModulesCache != null) return; lock (_onlineModulesCacheLock) { if (forced == false && onlineModulesCache != null) return; onlineModulesCache = new List(); try { foreach (var mod in AppInit.modules.Where(i => i.online != null && i.enable)) { try { var entry = new OnlineModuleEntry() { mod = mod }; var assembly = mod.assembly; if (assembly == null) continue; var type = assembly.GetType(mod.NamespacePath(mod.online)); 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 { } try { var m3 = type.GetMethod("Spider"); if (m3 != null) { entry.Spider = (Func>)Delegate.CreateDelegate( typeof(Func>), m3); } } catch { } try { var m4 = type.GetMethod("SpiderAsync"); if (m4 != null) { entry.SpiderAsync = (Func>>)Delegate.CreateDelegate( typeof(Func>>), m4); } } catch { } } else { try { var m = type.GetMethod("Events"); if (m != null) { entry.Events = (Func>)Delegate.CreateDelegate( typeof(Func>), m); } } catch { } try { var m2 = type.GetMethod("EventsAsync"); if (m2 != null) { entry.EventsAsync = (Func>>)Delegate.CreateDelegate( typeof(Func>>), m2); } } catch { } } if (entry.Invoke != null || entry.InvokeAsync != null || entry.Events != null || entry.EventsAsync != null || entry.Spider != null || entry.SpiderAsync != null) onlineModulesCache.Add(entry); } catch { } } } catch { } } } } }