Ejemplo n.º 1
0
        /// <summary>
        /// This method is bound to the AppDomain.CurrentDomain.AssemblyResolve event so that when the appDomain
        /// requests to resolve an assembly, the plugin assemblies are resolved from the already loaded plugin cache managed by the PluginManager class.
        /// </summary>
        /// <param name="sender">not used.</param>
        /// <param name="args">contains the assembly named requested and optioanlly the assemby itself.</param>
        /// <returns>The resolved assembly, the cached plugin assembly</returns>
        /// <remarks>Exceptions are managed nby the callaing code.</remarks>
        public static Assembly ResolveCurrentDomainAssembly(object sender, ResolveEventArgs args)
        {
            if (args.RequestingAssembly != null)
            {
                return(args.RequestingAssembly);
            }
            // At this point, the catalog may be checked to see if the requested assembly belongs to a disabled module, the resolution should fail.
            //ModuleBase module = pluginManager.ModuleInfos.
            //    SingleOrDefault(x => (x.EntryType.Assembly.FullName == args.Name) && (x.Manifest.IsEnabled == true)).Plugin;

            string asmName = new AssemblyName(args.Name).Name;

            var moduleInfo = ModuleInfos
                             .Where(x => (x.EntryType.Assembly.GetName().Name.Equals(asmName, StringComparison.InvariantCultureIgnoreCase))
                                    //&& (x.Manifest.IsEnabled == true) // check the catalog
                                    )
                             .FirstOrDefault();

            if (moduleInfo != null && IsActive(moduleInfo.Id) && IsLoaded(moduleInfo.Id))
            {
                return(moduleInfo.EntryType.Assembly);
            }

            // check the module cache for assemblies that are registered by the modules' manifests.
            if (moduleAssemblyCache.ContainsKey(asmName))
            {
                return(moduleAssemblyCache[asmName]);
            }

            string message = string.Format("Unable to resolve assembly '{0}'.", asmName);

            LoggerFactory.GetFileLogger().LogCustom(message);
            //throw new Exception(message);
            return(null);
        }
Ejemplo n.º 2
0
        IEnumerable <ModuleInfo> IPermissionConfig.GetGuildModuleWhitelist(IGuild guild)
        {
            var wl = QueryGuildModules()
                     .Where(g => g.Guild.GuildId == guild.Id)
                     .Select(m => m.Module.ModuleName)
                     .ToList();

            return(ModuleInfos.Where(m => wl.Contains(m.Key)).Select(m => m.Value));
        }
Ejemplo n.º 3
0
        IEnumerable <ModuleInfo> IPermissionConfig.GetChannelModuleWhitelist(ITextChannel channel)
        {
            var wl = QueryChannelModules()
                     .Where(c => c.Channel.ChannelId == channel.Id)
                     .Select(m => m.Module.ModuleName)
                     .ToList();

            return(ModuleInfos.Where(m => wl.Contains(m.Key)).Select(m => m.Value));
        }
Ejemplo n.º 4
0
        IEnumerable <ModuleInfo> IPermissionConfig.GetGuildModuleWhitelist(IGuild guild)
        {
            var wl = QueryGuild(guild).WhiteListedModules;

            return(ModuleInfos.Where(m => wl.Any(w => w.ModuleName == m.Key)).Select(m => m.Value));
        }
Ejemplo n.º 5
0
        IEnumerable <ModuleInfo> IPermissionConfig.GetChannelModuleWhitelist(ITextChannel channel)
        {
            var wl = QueryChannel(channel).WhiteListedModules;

            return(ModuleInfos.Where(m => wl.Any(w => w.ModuleName == m.Key)).Select(m => m.Value));
        }