Ejemplo n.º 1
0
        public void reloadModule(string FileName)
        {
            Assembly ModuleAssembly = Assembly.LoadFrom(FileName);
            int      j = 0;

            foreach (Type ModuleType in ModuleAssembly.GetTypes())
            {
                if (ModuleType.IsPublic)
                {
                    if (!ModuleType.IsAbstract)
                    {
                        Type typeInterface = ModuleType.GetInterface("RhoInterface.RhoModule", true);
                        if (typeInterface != null)
                        {
                            Types.AvailableModule newModule = new Types.AvailableModule();
                            newModule.AssemblyPath  = FileName;
                            newModule.Instance      = (RhoModule)Activator.CreateInstance(ModuleAssembly.GetType(ModuleType.ToString()));
                            newModule.Instance.Host = this;
                            newModule.Instance.Initialize();
                            newModule.Instance.user_id      = Global.usr_id;
                            newModule.Instance.role_set_id  = Global.role_set_id;
                            newModule.Instance.org_id       = Global.org_id;
                            newModule.Instance.login_number = Global.login_number;
                            newModule.Instance.loadMyRolesNMsgtyps();

                            this.colAvailableModules.Add(newModule);
                            j        += 1;
                            newModule = null;
                        }
                        typeInterface = null;
                    }
                }
            }
            ModuleAssembly = null;
        }
Ejemplo n.º 2
0
            /// <summary>
            /// Finds a Module in the available Modules
            /// </summary>
            /// <param name="ModuleNameOrPath">The name or File path of the Module to find</param>
            /// <returns>Available Module, or null if the Module is not found</returns>
            public Types.AvailableModule Find(string ModuleNameOrPath)
            {
                Types.AvailableModule toReturn = null;

                //Loop through all the Modules
                foreach (Types.AvailableModule ModuleOn in this.List)
                {
                    //Find the one with the matching name or filename
                    if ((ModuleOn.Instance.name.Equals(ModuleNameOrPath)) || ModuleOn.AssemblyPath.Equals(ModuleNameOrPath))
                    {
                        toReturn = ModuleOn;
                        break;
                    }
                }
                return(toReturn);
            }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads a module into memory and does some verification that it is of valid format
        /// </summary>
        /// <param name="FileName"></param>
        private void AddModule(string FileName)
        {
            /* Create a new assembly from the plugin file we're adding.. */
            Assembly moduleAssembly = Assembly.LoadFrom(FileName);

            /* Loop through types in the assembly */
            foreach (Type moduleType in moduleAssembly.GetTypes())
            {
                /* Only concern ourselves with the module's public problems... */
                if (moduleType.IsPublic)
                {
                    /* Non-abstract please...kthx */
                    if (!moduleType.IsAbstract)
                    {
                        /* Needs to match IModule */
                        Type typeInterface = moduleType.GetInterface("SharpServer.ModuleInterface.IModule", true);

                        /* Does this interface exist in the assembly? */
                        if (typeInterface != null)
                        {
                            /* Create a new available module since the type implements the IModule interface */
                            Types.AvailableModule newModule = new Types.AvailableModule();

                            newModule.AssemblyPath = FileName;

                            //Create a new instance and store the instance in the collection for later use
                            //We could change this later on to not load an instance.. we have 2 options
                            //1- Make one instance, and use it whenever we need it.. it's always there
                            //2- Don't make an instance, and instead make an instance whenever we use it, then close it
                            //For now we'll just make an instance of all the modules
                            // TODO: Lazy loading...
                            newModule.Instance = (IModule)Activator.CreateInstance(moduleAssembly.GetType(moduleType.ToString()));

                            /* Set the module's host to this class which inherited IModuleHost */
                            newModule.Instance.Host = this;

                            /* Add it to the collection */
                            this.colAvailableModules.Add(newModule);

                            /* Initialize the module */
                            newModule.Instance.Initialize();

                            /* Squeakin clean memory! */
                            newModule = null;
                        }

                        typeInterface = null; //Mr. Clean - had to keep this from tutorial code
                    }
                }
            }

            moduleAssembly = null;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Remove a Module to the collection of Available Modules
 /// </summary>
 /// <param name="ModuleToRemove">The Module to Remove</param>
 public void Remove(Types.AvailableModule ModuleToRemove)
 {
     this.List.Remove(ModuleToRemove);
 }
Ejemplo n.º 5
0
            //A Simple Home-brew class to hold some info about our Available Modules

            /// <summary>
            /// Add a Module to the collection of Available Modules
            /// </summary>
            /// <param name="ModuleToAdd">The Module to Add</param>
            public void Add(Types.AvailableModule ModuleToAdd)
            {
                this.List.Add(ModuleToAdd);
            }
Ejemplo n.º 6
0
        //public void CreateModulePrvldgs()
        //{
        //  foreach (Types.AvailableModule ModuleOn in colAvailableModules)
        //  {
        //    if (ModuleOn.Instance != null)
        //    {
        //      ModuleOn.Instance.loadMyRolesNMsgtyps();
        //    }
        //  }
        //}

        //private void AddAllModules(string FileName)
        //{
        //  Assembly ModuleAssembly = Assembly.LoadFrom(FileName);
        //  int j = 0;
        //  foreach (Type ModuleType in ModuleAssembly.GetTypes())
        //  {
        //    if (ModuleType.IsPublic)
        //    {
        //      if (!ModuleType.IsAbstract)
        //      {
        //        Type typeInterface = ModuleType.GetInterface("RhoInterface.RhoModule", true);
        //        if (typeInterface != null)
        //        {
        //          Types.AvailableModule newModule = new Types.AvailableModule();
        //          newModule.AssemblyPath = FileName;
        //          newModule.Instance = (RhoModule)Activator.CreateInstance(ModuleAssembly.GetType(ModuleType.ToString()));
        //          newModule.Instance.Initialize();
        //          newModule.Instance.Host = this;
        //          newModule.Instance.user_id = Global.usr_id;
        //          newModule.Instance.role_set_id = Global.role_set_id;
        //          newModule.Instance.org_id = Global.org_id;
        //          newModule.Instance.login_number = Global.login_number;
        //          newModule.Instance.loadMyRolesNMsgtyps();

        //          //string vwPrivName = newModule.Instance.vwPrmssnName;
        //          //string appName = newModule.Instance.name;

        //          this.colAvailableModules.Add(newModule);

        //          newModule = null;
        //        }
        //        typeInterface = null;
        //      }
        //    }
        //  }
        //  ModuleAssembly = null;
        //}

        public void AddModule(string FileName)
        {
            Assembly ModuleAssembly = Assembly.LoadFrom(FileName);
            int      j = 0;

            foreach (Type ModuleType in ModuleAssembly.GetTypes())
            {
                if (ModuleType.IsPublic)
                {
                    if (!ModuleType.IsAbstract)
                    {
                        Type typeInterface = ModuleType.GetInterface("RhoInterface.RhoModule", true);
                        if (typeInterface != null)
                        {
                            Types.AvailableModule newModule = new Types.AvailableModule();
                            newModule.AssemblyPath = FileName;
                            newModule.Instance     = (RhoModule)Activator.CreateInstance(ModuleAssembly.GetType(ModuleType.ToString()));
                            newModule.Instance.Initialize();
                            newModule.Instance.Host         = this;
                            newModule.Instance.user_id      = Global.usr_id;
                            newModule.Instance.role_set_id  = Global.role_set_id;
                            newModule.Instance.org_id       = Global.org_id;
                            newModule.Instance.login_number = Global.login_number;
                            newModule.Instance.loadMyRolesNMsgtyps();

                            string vwPrivName = newModule.Instance.vwPrmssnName;
                            string appName    = newModule.Instance.name;

                            this.colAvailableModules.Add(newModule);
                            j += 1;
                            System.Windows.Forms.ToolStripMenuItem item1 = new ToolStripMenuItem();
                            item1.Name   = "mnuItem" + j;
                            item1.Text   = newModule.Instance.name;
                            item1.Image  = System.Drawing.Image.FromHbitmap(newModule.Instance.mainInterface.Icon.ToBitmap().GetHbitmap());
                            item1.Click += new System.EventHandler(Global.myNwMainFrm.loadClickedModule);
                            item1.Tag    = newModule.Instance.whereToPut.ToString() + "|" + newModule.Instance.vwPrmssnName;
                            if (newModule.Instance.whereToPut == 1)
                            {
                                Global.myNwMainFrm.customModulesToolStripMenuItem.DropDownItems.Add(item1);
                            }
                            else if (newModule.Instance.whereToPut == 2)
                            {
                                Global.myNwMainFrm.customModulesToolStripMenuItem.DropDownItems.Add(item1);
                            }
                            else
                            {
                                Global.myNwMainFrm.customModulesToolStripMenuItem.DropDownItems.Add(item1);
                            }
                            bool shdEnbl = false;
                            Global.myNwMainFrm.cmnCdMn.ModuleName = appName;
                            for (int i = 0; i < Global.role_set_id.Length; i++)
                            {
                                if (Global.myNwMainFrm.cmnCdMn.doesRoleHvThisPrvldg(Global.role_set_id[i],
                                                                                    Global.myNwMainFrm.cmnCdMn.getPrvldgID(vwPrivName)) == true)
                                {
                                    shdEnbl = true;
                                }
                            }
                            Global.myNwMainFrm.cmnCdMn.ModuleName = null;
                            if (shdEnbl == true)
                            {
                                item1.Enabled = true;
                                item1.Visible = true;
                            }
                            else
                            {
                                item1.Enabled = false;
                                item1.Visible = false;
                            }
                            newModule = null;
                        }
                        typeInterface = null;
                    }
                }
            }
            ModuleAssembly = null;
        }