private static void CheckInstaller() { if (!HttpContext.Current.Request.RawUrl.Contains("Install")) { // Check version and redirect to install pages if neccessary. DatabaseInstaller dbInstaller = new DatabaseInstaller(HttpContext.Current.Server.MapPath("~/Install/Core"), Assembly.Load("Cuyahoga.Core")); if (dbInstaller.TestDatabaseConnection()) { if (dbInstaller.CanUpgrade) { HttpContext.Current.Application.Lock(); HttpContext.Current.Application["IsUpgrading"] = true; HttpContext.Current.Application.UnLock(); HttpContext.Current.Response.Redirect("~/Install/Upgrade.aspx"); } else if (dbInstaller.CanInstall) { HttpContext.Current.Application.Lock(); HttpContext.Current.Application["IsInstalling"] = true; HttpContext.Current.Application.UnLock(); HttpContext.Current.Response.Redirect("~/Install/Install.aspx"); } } else { throw new Exception("Cuyahoga can't connect to the database. Please check your application settings."); } } }
private void btnUpgradeDatabase_Click(object sender, EventArgs e) { DatabaseInstaller dbInstaller = new DatabaseInstaller(Server.MapPath("~/Install/Core"), Assembly.Load("Cuyahoga.Core")); DatabaseInstaller modulesDbInstaller = new DatabaseInstaller(Server.MapPath("~/Install/Modules"), Assembly.Load("Cuyahoga.Modules")); try { dbInstaller.Upgrade(); if (modulesDbInstaller.CanUpgrade) { modulesDbInstaller.Upgrade(); } this.pnlIntro.Visible = false; this.pnlFinished.Visible = true; // Remove the IsUpgrading flag, so users can view the pages again. HttpContext.Current.Application.Lock(); HttpContext.Current.Application["IsUpgrading"] = false; HttpContext.Current.Application.UnLock(); } catch (Exception ex) { ShowError("An error occured while installing the database tables: <br/>" + ex.ToString()); } }
public ActionResult Install(string moduleName) { try { string moduleInstallDirectory = GetPhysicalModuleInstallDirectory(moduleName); DatabaseInstaller dbInstaller = new DatabaseInstaller(moduleInstallDirectory, null); dbInstaller.Install(); ModuleType moduleType = this._moduleTypeService.GetModuleByName(moduleName); moduleType.AutoActivate = true; this._moduleTypeService.SaveOrUpdateModuleType(moduleType); this._moduleLoader.ActivateModule(moduleType); Messages.AddFlashMessageWithParams("ModuleInstalledAndActivatedMessage", moduleName); } catch (Exception ex) { Messages.AddFlashException(ex); } return RedirectToAction("Index"); }
private void Page_Load(object sender, EventArgs e) { this.pnlErrors.Visible = false; // Check security first User cuyahogaUser = (User) this.User.Identity; if (! cuyahogaUser.HasPermission(AccessLevel.Administrator)) { throw new AccessForbiddenException("Upgrade not allowed for the current user"); } if (! this.IsPostBack) { try { // Check upgradable state. Check both Cuyahoga.Core and Cuyahoga.Modules. bool canUpgrade = false; // Core DatabaseInstaller dbInstaller = new DatabaseInstaller(Server.MapPath("~/Install/Core"), Assembly.Load("Cuyahoga.Core")); if (dbInstaller.CanUpgrade) { canUpgrade = true; lblCoreAssemblyCurrent.Text = "Cuyahoga Core " + dbInstaller.CurrentVersionInDatabase.ToString(3); lblCoreAssemblyNew.Text = "Cuyahoga Core " + dbInstaller.NewAssemblyVersion.ToString(3); // Core modules DatabaseInstaller moduleDbInstaller = new DatabaseInstaller(Server.MapPath("~/Install/Modules"), Assembly.Load("Cuyahoga.Modules")); lblModulesAssemblyCurrent.Text = "Cuyahoga Core Modules " + moduleDbInstaller.CurrentVersionInDatabase.ToString(3); if (moduleDbInstaller.CanUpgrade) { lblModulesAssemblyNew.Text = "Cuyahoga Core Modules " + moduleDbInstaller.NewAssemblyVersion.ToString(3); } else { lblModulesAssemblyNew.Text = "Cuyahoga Core Modules - no upgrade available"; } } if (canUpgrade) { this.pnlIntro.Visible = true; } else { ShowError("Nothing to upgrade."); } } catch (Exception ex) { ShowError("An error occured: <br/><br/>" + ex.ToString()); } } }
private void rptModules_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { ModuleType moduleType = e.Item.DataItem as ModuleType; string physicalModuleInstallDirectory = Path.Combine(Server.MapPath("~/Modules/" + moduleType.Name), "Install"); Assembly moduleAssembly = null; if (moduleType.AssemblyName != null) { moduleAssembly = Assembly.Load(moduleType.AssemblyName); } DatabaseInstaller dbInstaller = new DatabaseInstaller(physicalModuleInstallDirectory, moduleAssembly); bool canInstall = dbInstaller.CanInstall; bool canUpgrade = dbInstaller.CanUpgrade; bool canUninstall = dbInstaller.CanUninstall; LinkButton lbtInstall = e.Item.FindControl("lbtInstall") as LinkButton; lbtInstall.Visible = canInstall; lbtInstall.Attributes.Add("onclick", "return confirm('Install this module?')"); LinkButton lbtUpgrade = e.Item.FindControl("lbtUpgrade") as LinkButton; lbtUpgrade.Visible = canUpgrade; lbtUpgrade.Attributes.Add("onclick", "return confirm('Upgrade this module?')"); LinkButton lbtUninstall = e.Item.FindControl("lbtUninstall") as LinkButton; lbtUninstall.Visible = canUninstall; lbtUninstall.Attributes.Add("onclick", "return confirm('Uninstall this module?')"); CheckBox chkBox = e.Item.FindControl("chkBoxActivation") as CheckBox; if (canInstall) { chkBox.Enabled = false; chkBox.Checked = moduleType.AutoActivate; } else { chkBox.Enabled = true; chkBox.Checked = moduleType.AutoActivate; if (moduleType.Name != null) chkBox.InputAttributes.Add("moduleTypeId", moduleType.ModuleTypeId.ToString()); } Literal litActivationStatus = e.Item.FindControl("litActivationStatus") as Literal; if (this.ModuleLoader.IsModuleActive(moduleType)) { litActivationStatus.Text = "<span style=\"color:green;\">Active</span>"; } else { litActivationStatus.Text = "<span style=\"color:red;\">Not Active</span>"; } Literal litStatus = e.Item.FindControl("litStatus") as Literal; if (dbInstaller.CurrentVersionInDatabase != null) { litStatus.Text = String.Format("Installed ({0}.{1}.{2})" , dbInstaller.CurrentVersionInDatabase.Major , dbInstaller.CurrentVersionInDatabase.Minor , dbInstaller.CurrentVersionInDatabase.Build); if (dbInstaller.CanUpgrade) { litStatus.Text += " (upgrade available) "; } } else { litStatus.Text = "Uninstalled"; } } }
private void rptModules_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e) { string[] commandArguments = e.CommandArgument.ToString().Split(':'); string moduleName = commandArguments[0]; string assemblyName = commandArguments[1]; Assembly assembly = null; if (assemblyName.Length > 0) { assembly = Assembly.Load(assemblyName); } string moduleInstallDirectory = Path.Combine(Server.MapPath("~/Modules/" + moduleName), "Install"); DatabaseInstaller dbInstaller = new DatabaseInstaller(moduleInstallDirectory, assembly); try { switch (e.CommandName.ToLower()) { case "install": dbInstaller.Install(); break; case "upgrade": dbInstaller.Upgrade(); break; case "uninstall": dbInstaller.Uninstall(); break; } // Rebind modules BindModules(); ShowMessage(e.CommandName + ": operation succeeded for " + moduleName + "."); } catch (Exception ex) { ShowError(e.CommandName + ": operation failed for " + moduleName + ".<br/>" + ex.Message); } }
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; }
private void Page_Load(object sender, EventArgs e) { this.pnlErrors.Visible = false; if (! this.IsPostBack) { try { // Check installable state. Check both Cuyahoga.Core and Cuyahoga.Modules. bool canInstall = false; // Core DatabaseInstaller dbInstaller = new DatabaseInstaller(Server.MapPath("~/Install/Core"), Assembly.Load("Cuyahoga.Core")); if (dbInstaller.CanInstall) { lblCoreAssembly.Text = "Cuyahoga Core " + dbInstaller.NewAssemblyVersion.ToString(3); // Core modules DatabaseInstaller moduleDbInstaller = new DatabaseInstaller(Server.MapPath("~/Install/Modules"), Assembly.Load("Cuyahoga.Modules")); if (moduleDbInstaller.CanInstall) { canInstall = true; lblModulesAssembly.Text = "Cuyahoga Core Modules " + moduleDbInstaller.NewAssemblyVersion.ToString(3); } } if (canInstall) { this.pnlIntro.Visible = true; } else { // Check if we perhaps need to add an admin if (this._commonDao.GetAll(typeof(User)).Count == 0) { this.pnlAdmin.Visible = true; } else { ShowError("Can't install Cuyahoga. Check if the install.sql file exists in the /Install/Core|Modules/Database/DATABASE_TYPE/ directory and that there isn't already a version installed."); } } } catch (Exception ex) { ShowError("An error occured: <br/><br/>" + ex.ToString()); } } }
private void InstallOptionalModules() { foreach (RepeaterItem ri in this.rptModules.Items) { CheckBox chkInstall = ri.FindControl("chkInstall") as CheckBox; if (chkInstall != null && chkInstall.Checked) { Literal litModuleName = (Literal) ri.FindControl("litModuleName"); string moduleName = litModuleName.Text; DatabaseInstaller moduleInstaller = new DatabaseInstaller(Path.Combine(Server.MapPath("~/Modules/" + moduleName), "Install"), null); moduleInstaller.Install(); } } }
private void btnInstallDatabase_Click(object sender, EventArgs e) { DatabaseInstaller dbInstaller = new DatabaseInstaller(Server.MapPath("~/Install/Core"), Assembly.Load("Cuyahoga.Core")); DatabaseInstaller modulesDbInstaller = new DatabaseInstaller(Server.MapPath("~/Install/Modules"), Assembly.Load("Cuyahoga.Modules")); try { dbInstaller.Install(); modulesDbInstaller.Install(); this.pnlIntro.Visible = false; this.pnlModules.Visible = true; BindOptionalModules(); ShowMessage("Database tables successfully created."); } catch (Exception ex) { ShowError("An error occured while installing the database tables: <br/>" + ex.ToString()); } }
private void BindOptionalModules() { // Retrieve the modules that are already installed. IList availableModules = this._commonDao.GetAll(typeof(ModuleType), "Name"); // 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 add the modules that can be installed ArrayList installableModules = new ArrayList(); foreach (DirectoryInfo di in moduleDirectories) { // Skip hidden directories. bool shouldAdd = (di.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden; foreach (ModuleType moduleType in availableModules) { if (moduleType.Name == di.Name) { shouldAdd = false; break; } } if (shouldAdd) { // Check if the module can be installed DatabaseInstaller moduleInstaller = new DatabaseInstaller(Path.Combine(Server.MapPath("~/Modules/" + di.Name), "Install"), null); if (moduleInstaller.CanInstall) { installableModules.Add(di.Name); } } } this.rptModules.DataSource = installableModules; this.rptModules.DataBind(); }
protected void rptModules_ItemCommand(object source, RepeaterCommandEventArgs e) { string[] commandArguments = e.CommandArgument.ToString().Split(':'); string moduleName = commandArguments[0]; string assemblyName = commandArguments[1]; Assembly assembly = null; if (assemblyName.Length > 0) { assembly = Assembly.Load(assemblyName); } string moduleInstallDirectory = Path.Combine(Server.MapPath("~/Modules/" + moduleName), "Install"); DatabaseInstaller dbInstaller = new DatabaseInstaller(moduleInstallDirectory, assembly); try { switch (e.CommandName.ToLower()) { case "install": dbInstaller.Install(); break; case "upgrade": dbInstaller.Upgrade(); break; case "uninstall": dbInstaller.Uninstall(); break; case "delete": string moduleFolder = Server.MapPath("~/Modules/" + moduleName); string dllFile = string.Format("{0}Cuyahoga.Modules.{1}.dll", Server.MapPath("~/bin/"), moduleName); // Maybe add to a service and use a transaction if (Directory.Exists(moduleFolder)) _fileService.DeleteDirectory(moduleFolder); if (File.Exists(dllFile)) _fileService.DeleteFile(dllFile); break; } // Rebind modules BindModules(); ShowMessage(e.CommandName + ": operation succeeded for " + moduleName + "."); } catch (Exception ex) { ShowError(e.CommandName + ": operation failed for " + moduleName + ".<br/>" + ex.Message); } }