Example #1
0
        async Task <MessageResponse> ProcessModuleLoadedMessage(ModuleLoadedMessage msg)
        {
            await Task.Run(() => {
                try
                {
                    ModuleLoaded?.Invoke(this, msg.ModuleName);
                } catch (Exception e)
                {
                    Log.WriteLine("ModuleLoadedMessageHandler event lambda exception {0}", e.ToString());
                }
            });

            return(MessageResponse.Completed);
        }
        /// <summary>
        /// Load all modules in the Module Directory
        /// </summary>
        public static void LoadAll()
        {
            ModuleLoadOrder = ModuleLoadOrder ?? new Dictionary <int, UserModule>();
            ModuleLoadOrder?.Clear();

            var sysModule = UserModule.FromType(typeof(SystemCommands));

            ModuleLoadOrder.Add(ModuleLoadOrder.Count, sysModule);

            var directories = Directory.GetDirectories(ModuleDirectory, "*", SearchOption.TopDirectoryOnly);

            LoadingStarted?.Invoke(directories.Length);

            // Search through all directories and add user modules
            directories.ToList().ForEach(dir => {
                var um = GetModuleFromDirectory(dir);

                // If a module is detected, add it to the ModuleLoadOrder dictionary
                if (um != null)
                {
                    var index  = ModuleLoadOrder.Count + 1;
                    var canUse = false;
                    do
                    {
                        if (!ModuleLoadOrder.ContainsKey(index))
                        {
                            canUse = true;
                            ModuleLoadOrder.Add(index, um);
                            ModuleLoaded?.Invoke(um);
                        }
                        else
                        {
                            index++;
                        }
                    } while(canUse == false);
                }
            });

            LoadingEnded?.Invoke();
        }
        public static async Task LoadAllAsync()
        {
            ModuleLoadOrder = ModuleLoadOrder ?? new Dictionary <int, UserModule>();
            ModuleLoadOrder?.Clear();

            var sysModule = await UserModule.FromTypeAsync(typeof(SystemCommands));

            ModuleLoadOrder.Add(ModuleLoadOrder.Count, sysModule);

            var directories = Directory.GetDirectories(ModuleDirectory, "*", SearchOption.TopDirectoryOnly);

            LoadingStarted?.Invoke(directories.Length);

            var foundModules = await GetModulesFromDirectoriesAsync(directories);

            foundModules.ForEach(um => {
                var index  = ModuleLoadOrder.Count + 1;
                var canUse = false;

                do
                {
                    if (!ModuleLoadOrder.ContainsKey(index))
                    {
                        canUse = true;
                        ModuleLoadOrder.Add(index, um);
                        ModuleLoaded?.Invoke(um);
                    }
                    else
                    {
                        index++;
                    }
                } while(canUse == false);
            });

            LoadingEnded?.Invoke();
        }
Example #4
0
 /// <summary>
 /// Allows you to perform an action once your module has finished loading (once
 /// <see cref="LoadAsync"/> has completed).  You must call "base.OnModuleLoaded(e)" at the
 /// end for the <see cref="Module.ModuleLoaded"/> event to fire.
 /// </summary>
 protected virtual void OnModuleLoaded(EventArgs e)
 {
     ModuleLoaded?.Invoke(this, e);
 }
 void OnModuleLoaded(ModuleEventArgs e)
 {
     ModuleLoaded?.Invoke(this, e);
 }
 void svc_ModuleLoaded(object sender, GenericEventArgs <IModuleInfo> e)
 {
     ModuleLoaded.Fire(this, e);
 }
Example #7
0
 private void OnModuleLoaded(string moduleName, Assembly assembly)
 {
     ModuleLoaded?.Invoke(this, new ModuleLoadedEventArgs(moduleName, assembly));
 }
        internal ModuleInfo LoadAssembly(Assembly assembly)
        {
            var assemblyName = assembly.GetName();

            Debug.WriteLine(string.Format("IoC: Loading assembly '{0}'", assemblyName), Constants.TraceCategoryName);

            Type imodule = FindIModuleType(assembly);

            if (imodule == null)
            {
                return(null);
            }

            object instance = ObjectFactory.CreateObject(imodule, RootWorkItem.Instance);

            var info = new ModuleInfo
            {
                Assembly     = assembly,
                AssemblyFile = assemblyName.CodeBase,
                Instance     = instance
            };

            lock (m_syncRoot)
            {
                m_loadedModules.Add(info);
            }

#if NETSTANDARD1_3
            var loadMethod = imodule.GetRuntimeMethod("Load", null);
#else
            var loadMethod = imodule.GetMethod("Load", BindingFlags.Public | BindingFlags.Instance);
#endif
            if (loadMethod != null)
            {
                try
                {
                    loadMethod.Invoke(instance, null);
                }
                catch (Exception ex)
                {
                    throw ex.InnerException;
                }
            }

            var addServices = imodule.GetMethod("AddServices", BindingFlags.Public | BindingFlags.Instance);
            if (addServices != null)
            {
                try
                {
                    addServices.Invoke(instance, null);
                }
                catch (Exception ex)
                {
                    throw ex.InnerException;
                }
            }

            ModuleLoaded.Fire(this, new GenericEventArgs <IModuleInfo>(info));

            return(info);
        }
Example #9
0
 protected void OnModuleLoaded(ModuleInfo module, object value)
 {
     ModuleLoaded?.Invoke(this, new ModuleIntanceEventArgs(module, value));
 }
        public virtual int LoadModule(ulong ImageFileHandle, ulong BaseOffset, uint ModuleSize, string ModuleName, string ImageName, uint CheckSum, uint TimeDateStamp)
        {
            ModuleLoaded?.Invoke(this, new ModuleEventArgs(ImageFileHandle, BaseOffset, ModuleSize, ModuleName, ImageName, CheckSum, TimeDateStamp));

            return((int)DEBUG_STATUS.NO_CHANGE);
        }