protected void BindModules()
        {
            // Retrieve the available modules that are installed.
            IList<ModuleType> availableModules = this._moduleTypeService.GetAllModuleTypes();

            // Retrieve the available modules from the filesystem.
            string moduleRootDir = HttpContext.Current.Server.MapPath("~/Modules");
            DirectoryInfo[] moduleDirectories = new DirectoryInfo(moduleRootDir).GetDirectories();

            // Go through the directories and check if there are missing ones. Those have to be added
            // as new ModuleType candidates.
            foreach (DirectoryInfo di in moduleDirectories)
            {
                // Skip hidden directories (and obj folders)
                bool shouldAdd = (di.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden &&
                                    di.Name != "obj";
                foreach (ModuleType moduleType in availableModules)
                {
                    if (moduleType.Name == di.Name)
                    {
                        shouldAdd = false;
                        break;
                    }
                }
                if (shouldAdd)
                {
                    ModuleType newModuleType = new ModuleType();
                    newModuleType.Name = di.Name;
                    availableModules.Add(newModuleType);
                }
            }
            rptModules.DataSource = availableModules;//.OrderBy(x => x.Name);
            rptModules.DataBind();
        }
Example #2
0
        public void ActivateModule(ModuleType moduleType)
        {
            //only one thread at a time
            System.Threading.Monitor.Enter(lockObject);

            string assemblyQualifiedName = moduleType.ClassName + ", " + moduleType.AssemblyName;
            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Loading module {0}.", assemblyQualifiedName);
            }
            // First, try to get the CLR module type
            Type moduleTypeType = Type.GetType(assemblyQualifiedName);
            if (moduleTypeType == null)
            {
                throw new Exception("Could not find module: " + assemblyQualifiedName);
            }
            try
            {
                // double check, if we should continue
                if (this._kernel.HasComponent(moduleTypeType))
                {
                    // Module is already registered
                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("The module with type {0} is already registered in the container.", moduleTypeType.ToString());
                    }
                    return;
                }

                // First, register optional module services that the module might depend on.
                foreach (ModuleService moduleService in moduleType.ModuleServices)
                {
                    Type serviceType = Type.GetType(moduleService.ServiceType);
                    Type classType = Type.GetType(moduleService.ClassType);
                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("Loading module service {0}, (1).", moduleService.ServiceKey, moduleService.ClassType);
                    }
                    LifestyleType lifestyle = LifestyleType.Singleton;
                    if (moduleService.Lifestyle != null)
                    {
                        try
                        {
                            lifestyle = (LifestyleType)Enum.Parse(typeof(LifestyleType), moduleService.Lifestyle);
                        }
                        catch (ArgumentException ex)
                        {
                            throw new Exception(String.Format("Unable to load module service {0} with invalid lifestyle {1}."
                                                              , moduleService.ServiceKey, moduleService.Lifestyle), ex);
                        }
                    }
                    this._kernel.AddComponent(moduleService.ServiceKey, serviceType, classType, lifestyle);
                }

                //Register the module
                this._kernel.AddComponent("module." + moduleTypeType.FullName, moduleTypeType);

                //Configure NHibernate mappings and make sure we haven't already added this assembly to the NHibernate config
                if (typeof(INHibernateModule).IsAssignableFrom(moduleTypeType) && ((HttpContext.Current.Application[moduleType.AssemblyName]) == null))
                {
                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("Adding module assembly {0} to the NHibernate mappings.", moduleTypeType.Assembly.ToString());
                    }
                    this._sessionFactoryHelper.AddAssembly(moduleTypeType.Assembly);
                    //set application variable to remember the configurated assemblies
                    HttpContext.Current.Application.Lock();
                    HttpContext.Current.Application[moduleType.AssemblyName] = moduleType.AssemblyName;
                    HttpContext.Current.Application.UnLock();
                }
            }
            finally
            {
                System.Threading.Monitor.Exit(lockObject);
            }
        }
Example #3
0
 /// <summary>
 /// Checks if the module is represent in IoC Container configuration
 /// </summary>
 /// <param name="moduleTypeType"></param>
 /// <returns></returns>
 public bool IsModuleActive(ModuleType moduleTypeType)
 {
     return this._kernel.HasComponent(string.Concat("module.", moduleTypeType.ClassName));
 }
Example #4
0
 /// <summary>
 /// Get the module instance by its type
 /// </summary>
 /// <param name="moduleType"></param>
 public ModuleBase GetModuleFromType(ModuleType moduleType)
 {
     string modulekey = string.Concat("module.", moduleType.ClassName);
     if (this._kernel.HasComponent(modulekey))
     {
         return (ModuleBase)this._kernel[modulekey];
     }
     else
     {
         if (log.IsDebugEnabled)
         {
             log.DebugFormat("Unable to find module with key '{0}' in the container.", modulekey);
         }
         return null;
     }
 }
Example #5
0
        private IEnumerable<ModuleViewData> GetModuleViewData()
        {
            // Retrieve the available modules that are installed.
            IList<ModuleType> availableModules = this._moduleTypeService.GetAllModuleTypes();
            // Retrieve the available modules from the filesystem.
            string moduleRootDir = Server.MapPath("~/Modules");
            DirectoryInfo[] moduleDirectories = new DirectoryInfo(moduleRootDir).GetDirectories();
            // Go through the directories and check if there are missing ones. Those have to be added
            // as new ModuleType candidates.
            foreach (DirectoryInfo di in moduleDirectories)
            {
                // Skip hidden directories and shared directory.
                bool shouldAdd = (di.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden && di.Name.ToLowerInvariant() != "shared";

                foreach (ModuleType moduleType in availableModules)
                {
                    if (moduleType.Name == di.Name)
                    {
                        shouldAdd = false;
                        break;
                    }
                }
                if (shouldAdd)
                {
                    ModuleType newModuleType = new ModuleType();
                    newModuleType.Name = di.Name;
                    availableModules.Add(newModuleType);
                }
            }

            IList<ModuleViewData> moduleViewDataList = new List<ModuleViewData>();
            foreach (var availableModule in availableModules)
            {
                var moduleViewData = new ModuleViewData(availableModule);

                string physicalModuleInstallDirectory = GetPhysicalModuleInstallDirectory(availableModule.Name);
                Assembly moduleAssembly = null;
                if (availableModule.AssemblyName != null)
                {
                    moduleAssembly = Assembly.Load(availableModule.AssemblyName);
                }
                DatabaseInstaller dbInstaller = new DatabaseInstaller(physicalModuleInstallDirectory, moduleAssembly);
                moduleViewData.CanInstall = dbInstaller.CanInstall;
                moduleViewData.CanUpgrade = dbInstaller.CanUpgrade;
                moduleViewData.CanUninstall = dbInstaller.CanUninstall;

                moduleViewData.ActivationStatus = this._moduleLoader.IsModuleActive(availableModule)
                                                  	? GetText("ActiveStatus")
                                                  	: GetText("InactiveStatus");
                if (dbInstaller.CurrentVersionInDatabase != null)
                {
                    moduleViewData.ModuleVersion = dbInstaller.CurrentVersionInDatabase.ToString(3);
                    if (dbInstaller.CanUpgrade)
                    {
                        moduleViewData.InstallationStatus = GetText("InstalledUpgradeStatus");
                    }
                    else
                    {
                        moduleViewData.InstallationStatus = GetText("InstalledStatus");
                    }
                }
                else
                {
                    moduleViewData.InstallationStatus = GetText("UninstalledStatus");
                }
                moduleViewDataList.Add(moduleViewData);
            }
            return moduleViewDataList;
        }
Example #6
0
 private DatabaseInstaller GetDbInstallerForModuleType(ModuleType moduleType)
 {
     Assembly moduleAssembly = Assembly.Load(moduleType.AssemblyName);
     string moduleInstallDirectory = GetPhysicalModuleInstallDirectory(moduleType.Name);
     return new DatabaseInstaller(moduleInstallDirectory, moduleAssembly);
 }
 public IList<Section> GetSectionsByModuleTypeAndSite(ModuleType moduleType, Site site)
 {
     ISession session = this._sessionManager.OpenSession();
     string hql = "from Section s where s.ModuleType = :moduleType and s.Site = :site";
     IQuery query = session.CreateQuery(hql);
     query.SetParameter("moduleType", moduleType);
     query.SetParameter("site", site);
     return query.List<Section>();
 }
 public IList<Section> GetSectionsByModuleType(ModuleType moduleType)
 {
     return this._siteStructureDao.GetSectionsByModuleType(moduleType);
 }
Example #9
0
 public void Setup()
 {
     this._moduleType = new ModuleType() { ModuleTypeId = 1, Name = "TestModule", AutoActivate = true, AssemblyName = "Cuyahoga.Tests", ClassName = "TestModule" };
 }
 public void SaveOrUpdateModuleType(ModuleType moduleType)
 {
     this._commonDao.SaveOrUpdateObject(moduleType);
 }
 public void DeleteModuleType(ModuleType moduleType)
 {
     this._commonDao.DeleteObject(moduleType);
 }
Example #12
0
 public ModuleViewData(ModuleType moduleType)
 {
     _moduleType = moduleType;
 }