protected void DetailsView_ItemInserting(object sender, DetailsViewInsertEventArgs e) { InfoList.Items.Clear(); string name = e.Values["Name"] as string; string csis = e.Values["ConnstringIS"] as string; string cswb = e.Values["ConnstringWeb"] as string; CE.Project newProject = new CE.Project(0, name, mm.DbServer, cswb, csis, 0); BasicValidation(newProject); if (InfoList.Items.Count > 0) { e.Cancel = true; return; } try { mm.SysDriver.InsertProject(newProject); } catch (ConstraintException ce) { InfoList.Items.Add(ce.Message); e.Cancel = true; return; } Response.RedirectToRoute("ProjectsRoute"); }
protected void DetailsView_ItemUpdating(object sender, DetailsViewUpdateEventArgs e) { string name = e.NewValues["Name"] as string; string csis = e.NewValues["ConnstringIS"] as string; string cswb = e.NewValues["ConnstringWeb"] as string; CE.Project updatedProject = new CE.Project(project.Id, name, DbServer.MsSql, cswb, csis, project.Version + 1); BasicValidation(updatedProject); if (InfoList.Items.Count > 0) { e.Cancel = true; return; } try { mm.SysDriver.UpdateProject(updatedProject); } catch (ConstraintException ce) { InfoList.Items.Add(ce.Message); e.Cancel = true; return; } InfoList.Items.Clear(); InfoList.Items.Add("Project was successfully updated."); }
/// <summary> /// Simply runs the constructor of the Project using the provided DataRow data object and returns the result /// </summary> /// <param name="row"></param> /// <returns></returns> private CE.Project ProjectFromDataRow(DataRow row) { CE.Project project = new CE.Project( (Int32)row["id_project"], (string)row["name"], (DbServer)Enum.Parse(typeof(DbServer), (string)row["server_type"]), (string)row["connstring_web"], (string)row["connstring_information_schema"], (Int32)(row["version"]) ); return(project); }
public CE.Project getProject(int projectId) { CE.Project project = new CE.Project(); DataRow row = fetch("SELECT * FROM projects WHERE id_project = ", projectId); project.id = projectId; project.lastChange = (DateTime)row["last_modified"]; project.name = (string)row["name"]; project.serverName = (string)row["server_type"]; project.connstringIS = (string)row["connstring_information_schema"]; project.connstringWeb = (string)row["connstring_web"]; return(project); }
protected void Page_Load(object sender, EventArgs e) { mm = (MinMaster)Master; if (Page.RouteData.Values.ContainsKey("projectId") && Int32.Parse(Page.RouteData.Values["projectId"] as string) > 0) { DeleteButton.Visible = true; DetailsView.DefaultMode = DetailsViewMode.Edit; int idProject = Int32.Parse(Page.RouteData.Values["projectId"] as string); project = mm.SysDriver.GetProject(idProject); if (!Page.IsPostBack) { DetailsView.DataSource = new CE.Project[] { project }; DetailsView.DataBind(); } } }
public void UpdateProject(CE.Project project) { DataTable projectsTable = GetProjects(); DataRow projectRow = projectsTable.Rows.Find(project.Id); try { projectRow["server_type"] = project.ServerType; projectRow["name"] = project.Name; projectRow["connstring_web"] = project.ConnstringWeb; projectRow["connstring_information_schema"] = project.ConnstringIS; } catch (ConstraintException ce) { throw new ConstraintException("The name of the project must be unique.", ce); } SaveProjectsTable(projectsTable); }
private void BasicValidation(CE.Project newProject) { if (newProject.Name == null) { InfoList.Items.Add("Please enter the project name"); } else if (!Regex.IsMatch(newProject.Name, "^[a-zA-Z0-9]+$")) { InfoList.Items.Add("The project name must consist exclusively of letters and digits"); } if (newProject.ConnstringIS == null) { InfoList.Items.Add("Please enter the connection string through which the application can access the corresponding INFORMATION_SCHEMA."); } if (newProject.ConnstringWeb == null) { InfoList.Items.Add("Please enter the connection string through which the application can access the production database."); } }
public int InsertProject(CE.Project project) { DataTable projects = GetProjects(); DataRow newRow = projects.NewRow(); newRow["server_type"] = project.ServerType.ToString(); newRow["name"] = project.Name; newRow["connstring_web"] = project.ConnstringWeb; newRow["connstring_information_schema"] = project.ConnstringIS; newRow["version"] = project.Version; try { projects.Rows.Add(newRow); } catch (ConstraintException ce) { throw new ConstraintException("The name of the project must be unique.", ce); } SaveProjectsTable(projects); return((int)newRow["id_project"]); }
protected void DetailsView_ItemInserting(object sender, DetailsViewInsertEventArgs e) { InfoList.Items.Clear(); string name = e.Values["Name"] as string; string csis = e.Values["ConnstringIS"] as string; string cswb = e.Values["ConnstringWeb"] as string; CE.Project newProject = new CE.Project(0, name, mm.DbServer.ToString(), cswb, csis, 0); BasicValidation(newProject); if (InfoList.Items.Count > 0) { e.Cancel = true; return; } try { mm.SysDriver.InsertProject(newProject); } catch (ConstraintException ce){ InfoList.Items.Add(ce.Message); e.Cancel = true; return; } Response.RedirectToRoute("ProjectsRoute"); }
protected void Page_Load(object sender, EventArgs e) { mm = (MinMaster)Master; if(Page.RouteData.Values.ContainsKey("projectId") && Int32.Parse(Page.RouteData.Values["projectId"] as string) > 0){ DeleteButton.Visible = true; DetailsView.DefaultMode = DetailsViewMode.Edit; int idProject = Int32.Parse(Page.RouteData.Values["projectId"] as string); project = mm.SysDriver.GetProject(idProject); if (!Page.IsPostBack) { DetailsView.DataSource = new CE.Project[] { project }; DetailsView.DataBind(); } } }
protected void DetailsView_ItemUpdating(object sender, DetailsViewUpdateEventArgs e) { string name = e.NewValues["Name"] as string; string csis = e.NewValues["ConnstringIS"] as string; string cswb = e.NewValues["ConnstringWeb"] as string; CE.Project updatedProject = new CE.Project(project.Id, name, "MSSQL", cswb, csis, project.Version + 1); BasicValidation(updatedProject); if (InfoList.Items.Count > 0) { e.Cancel = true; return; } try { mm.SysDriver.UpdateProject(updatedProject); } catch (ConstraintException ce) { InfoList.Items.Add(ce.Message); e.Cancel = true; return; } InfoList.Items.Clear(); InfoList.Items.Add("Project was successfully updated."); }
public CE.Project getProject(int projectId) { CE.Project project = new CE.Project(); DataRow row = fetch("SELECT * FROM projects WHERE id_project = ", projectId); project.id = projectId; project.lastChange = (DateTime)row["last_modified"]; project.name = (string)row["name"]; project.serverName = (string)row["server_type"]; project.connstringIS = (string)row["connstring_information_schema"]; project.connstringWeb = (string)row["connstring_web"]; return project; }
/// <summary> /// Simply runs the constructor of the Project using the provided DataRow data object and returns the result /// </summary> /// <param name="row"></param> /// <returns></returns> private CE.Project ProjectFromDataRow(DataRow row) { CE.Project project = new CE.Project( (Int32)row["id_project"], (string)row["name"], (DbServer)Enum.Parse(typeof(DbServer), (string)row["server_type"]), (string)row["connstring_web"], (string)row["connstring_information_schema"], (Int32)(row["version"]) ); return project; }
/// <summary> /// The main entry point of the application - initializes database drivers, checks access rights, detects the current page type and does more setting accordingly. /// </summary> protected void Page_Init(object sender, EventArgs e) { DbServer = (DbServer)Enum.Parse(typeof(DbServer), System.Configuration.ConfigurationManager.AppSettings["ServerType"] as string); bool isFirstRun = System.Configuration.ConfigurationManager.AppSettings["FirstRun"] as string == "True"; // detect the site type based on the beginning of the URL string lp = Request.Url.LocalPath; if (lp.StartsWith("/architect")) { Common.Environment.GlobalState = GlobalState.Architect; } else if (lp.StartsWith("/admin")) { Common.Environment.GlobalState = GlobalState.Administer; } else if (lp == "/sys/users") { Common.Environment.GlobalState = GlobalState.UsersManagement; } else if (lp == "/sys/projects") { Common.Environment.GlobalState = GlobalState.ProjectsManagement; } else if (lp.StartsWith("/account")) { Common.Environment.GlobalState = GlobalState.Account; } else if (lp.StartsWith("/FirstRun")) { Common.Environment.GlobalState = GlobalState.FirstRun; } else { Common.Environment.GlobalState = GlobalState.Error; } bool firstRunMono = System.Configuration.ConfigurationManager.AppSettings["FirstRunMono"] == "True"; if (isFirstRun && Common.Environment.GlobalState != GlobalState.FirstRun && !firstRunMono) { Response.Redirect("~/FirstRun/FirstRun.aspx"); } if (!isFirstRun && Common.Environment.GlobalState == GlobalState.FirstRun) { Response.RedirectToRoute("DefaultRoute"); } // set the warning only for logged in users System.Configuration.ConfigurationManager.AppSettings["SessionWarning"] = (user is MembershipUser) ? (Session.Timeout - 5).ToString() : "-1"; if (isFirstRun) { return; } user = Membership.GetUser(); // session expiry means logout, even if the provider would keep the user logged in if ((Session.IsNewSession || user == null) && CE.GlobalState != GlobalState.Account && CE.GlobalState != GlobalState.Error) { FormsAuthentication.SignOut(); Response.RedirectToRoute("LockoutRoute", new { message = 7 }); } IBaseDriver systemBaseDriver = null; // initialize the system driver based on the server type read from the configuration switch (DbServer) { case DbServer.MySql: systemBaseDriver = new BaseDriverMySql(ConfigurationManager.ConnectionStrings["MySqlServer"].ConnectionString); break; case DbServer.MsSql: systemBaseDriver = new BaseDriverMsSql(ConfigurationManager.ConnectionStrings["MsSqlServer"].ConnectionString); break; default: break; } SysDriver = new SystemDriver(systemBaseDriver); if (firstRunMono && CE.GlobalState != GlobalState.FirstRun) { Response.Redirect("~/FirstRun/FirstRunMono.aspx"); } if (!firstRunMono && CE.GlobalState == GlobalState.FirstRun) { Response.RedirectToRoute("DefaultRoute"); } if (firstRunMono) { return; } // global service // is there a need for a reload of the project architecture? bool NewProjectLoad = false; // get current project and init drivers and architect if (Page.RouteData.Values.ContainsKey("projectName")) { ProjectName = Page.RouteData.Values["projectName"] as string; CE.Project actProject = SysDriver.GetProject(ProjectName); if (CE.project == null || actProject.Id != CE.project.Id || actProject.Version != CE.project.Version) { Session.Clear(); // may not be neccessary in all cases, but better be safe NewProjectLoad = true; } CE.project = SysDriver.GetProject(ProjectName); IBaseDriver statsBaseDriver = null; IBaseDriver webBaseDriver = null; switch (CE.project.ServerType) { case DbServer.MySql: statsBaseDriver = new BaseDriverMySql(CE.project.ConnstringIS); Stats = new StatsMySql((BaseDriverMySql)statsBaseDriver, CE.project.WebDbName); webBaseDriver = new BaseDriverMySql(CE._project.ConnstringWeb); break; case DbServer.MsSql: statsBaseDriver = new BaseDriverMsSql(CE.project.ConnstringIS); Stats = new StatsMsSql((BaseDriverMsSql)statsBaseDriver); webBaseDriver = new BaseDriverMsSql(CE._project.ConnstringWeb); break; default: break; } WebDriver = new WebDriver(webBaseDriver); Architect = new _min.Models.Architect(SysDriver, Stats); if ((!Page.IsPostBack || NewProjectLoad) && CE.GlobalState != GlobalState.Error) // new version or differnet page ~ othervise access must have remained // at least "allowable", if not allowed { LockingAccess(); // just check } // check whether there is something to load at all if (Page.RouteData.Route != RouteTable.Routes["ArchitectInitRoute"]) { if (!SysDriver.ProposalExists()) { if (CE.GlobalState == GlobalState.Architect) { Response.RedirectToRoute("ArchitectInitRoute", new { projectName = Page.RouteData.Values["projectName"] }); Response.End(); } else { // change to some kind of "Not found" page Response.RedirectToRoute("DefaultRoute", new { projectName = Page.RouteData.Values["projectName"] }); Response.End(); } } // get the current architecture - either extract from Session or directry from the DB, if project version has changed int actVersion = CE.project.Version; if (Session[CC.SESSION_ARCHITECTURE] is _min.Models.Panel && Session[CC.SESSION_ARCHITECTURE_VERSION] is int && (int)Session[CC.SESSION_ARCHITECTURE_VERSION] == actVersion) { SysDriver.SetArchitecture((MPanel)Session[CC.SESSION_ARCHITECTURE]); } else { SysDriver.FullProjectLoad(); Session[CC.SESSION_ARCHITECTURE] = SysDriver.MainPanel; Session[CC.SESSION_ARCHITECTURE_VERSION] = CE.project.Version; } } } // local issues if (!Page.IsPostBack) { if (user != null) { List <string> adminOf; List <string> architectOf; List <CE.Project> allProjects = SysDriver.GetProjectObjects(); List <string> allNames = (from CE.Project p in allProjects select p.Name).ToList <string>(); object userId = user.ProviderUserKey; int globalRights = SysDriver.GetUserRights(userId, null); // by default, fetch only the sites to which the access rights are set explicitly, // if global rights are sufficient, replace them with the complete lists SysDriver.UserMenuOptions(userId, out adminOf, out architectOf); if (globalRights % 100 >= 10) { adminOf = allNames; } if (globalRights % 1000 >= 100) { architectOf = allNames; } // decide on the upper menu content MenuItem administerItem = new MenuItem("Administer", "admin"); foreach (string site in adminOf) { administerItem.ChildItems.Add(new MenuItem(site, site, null, "/admin/" + site)); } if (adminOf.Count > 0) { NavigationMenu.Items.AddAt(0, administerItem); } // architect menu MenuItem architectItem = new MenuItem("Architect", "architect"); foreach (string site in architectOf) { architectItem.ChildItems.Add(new MenuItem(site, site, null, "/architect/show/" + Server.UrlEncode(site))); } if (architectOf.Count > 0) { NavigationMenu.Items.AddAt(1, architectItem); } // user & projects management NavigationMenu.Items.Add(new MenuItem("Manage users", "users", null, "/sys/users")); if (globalRights >= 10000) // this is the one and only project manager for this application instance { NavigationMenu.Items.Add(new MenuItem("Manage projects", "projects", null, "/sys/projects")); } // account settings for logged in users MenuItem accountItem = new MenuItem("Account", "account"); accountItem.ChildItems.Add(new MenuItem("Change password", null, null, "/account/change-password")); accountItem.ChildItems.Add(new MenuItem("Logout", null, null, "/account/logout")); NavigationMenu.Items.Add(accountItem); } else { MenuItem accountItem = new MenuItem("Account", "account"); accountItem.ChildItems.Add(new MenuItem("Login", null, null, "/account/login")); accountItem.ChildItems.Add(new MenuItem("Register", null, null, "/account/register")); NavigationMenu.Items.Add(accountItem); } NavigationMenu.RenderingMode = MenuRenderingMode.Table; } }
/// <summary> /// Simply runs the constructor of the Project using the provided DataRow data object and returns the result /// </summary> /// <param name="row"></param> /// <returns></returns> private CE.Project ProjectFromDataRow(DataRow row) { CE.Project project = new CE.Project( (Int32)row["id_project"], (string)row["name"], //(string)row["server_type"], "OneDay", (string)row["connstring_web"], (string)row["connstring_information_schema"], (Int32)(row["version"]) ); return project; }