Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            DatabaseUpdate du = new DatabaseUpdate();

            if (!string.IsNullOrEmpty(Request.QueryString["signout"])) {
                FormsAuthentication.SignOut();
            }

            List<DatabaseUpdateMessage> lst = new List<DatabaseUpdateMessage>();

            btnLogin.Visible = false;
            btnCreate.Visible = false;

            if (DatabaseUpdate.LastSQLError != null) {
                du.HandleResponse(lst, DatabaseUpdate.LastSQLError);
                DatabaseUpdate.LastSQLError = null;
            } else {
                bool bUpdate = true;

                if (!du.DoCMSTablesExist()) {
                    bUpdate = false;
                }

                bUpdate = du.DatabaseNeedsUpdate();

                if (bUpdate) {
                    DatabaseUpdateStatus status = du.PerformUpdates();
                    lst = du.MergeMessages(lst, status.Messages);
                } else {
                    DataInfo ver = DatabaseUpdate.GetDbSchemaVersion();
                    du.HandleResponse(lst, "Database up-to-date [" + ver.DataValue + "] ");
                }

                bUpdate = du.DatabaseNeedsUpdate();

                if (!bUpdate && DatabaseUpdate.LastSQLError == null) {
                    if (du.UsersExist) {
                        btnLogin.Visible = true;
                    } else {
                        btnCreate.Visible = true;
                    }
                }
            }

            if (DatabaseUpdate.LastSQLError != null) {
                du.HandleResponse(lst, DatabaseUpdate.LastSQLError);
            }

            if (lst.Where(x => !string.IsNullOrEmpty(x.ExceptionText)).Count() > 0) {
                bOK = false;
            } else {
                bOK = true;
            }

            GeneralUtilities.BindRepeater(rpMessages, lst.OrderBy(x => x.Order));

            using (CMSConfigHelper cmsHelper = new CMSConfigHelper()) {
                cmsHelper.ResetConfigs();
            }
        }
		public ActionResult DatabaseSetup(string signout) {
			DatabaseSetupModel model = new DatabaseSetupModel();

			DatabaseUpdate du = new DatabaseUpdate(true);

			if (!String.IsNullOrEmpty(signout)) {
				SignOut();
			}

			List<DatabaseUpdateMessage> lst = new List<DatabaseUpdateMessage>();
			model.Messages = lst;

			if (DatabaseUpdate.LastSQLError != null) {
				du.HandleResponse(lst, DatabaseUpdate.LastSQLError);
				DatabaseUpdate.LastSQLError = null;
			} else {
				bool bUpdate = true;

				if (!du.DoCMSTablesExist()) {
					bUpdate = false;
				}

				bUpdate = du.DatabaseNeedsUpdate();

				try {
					model.CreateUser = !DatabaseUpdate.UsersExist;
				} catch { }

				if (bUpdate) {
					DatabaseUpdateStatus status = du.PerformUpdates();
					lst = du.MergeMessages(lst, status.Messages);
				} else {
					DataInfo ver = DatabaseUpdate.GetDbSchemaVersion();
					du.HandleResponse(lst, "Database up-to-date [" + ver.DataValue + "] ");
				}

				bUpdate = du.DatabaseNeedsUpdate();

				if (!bUpdate && DatabaseUpdate.LastSQLError == null) {
					model.CreateUser = !DatabaseUpdate.UsersExist;
				}
			}

			if (DatabaseUpdate.LastSQLError != null) {
				du.HandleResponse(lst, DatabaseUpdate.LastSQLError);
			}

			model.HasExceptions = lst.Where(x => !String.IsNullOrEmpty(x.ExceptionText)).Any();
			model.Messages = lst;

			using (CMSConfigHelper cmsHelper = new CMSConfigHelper()) {
				cmsHelper.ResetConfigs();
			}

			return View(model);
		}