protected void InstallWizard_NextButtonClick(object sender, WizardNavigationEventArgs e) { bool IsOK = false; if (e.CurrentStepIndex == 4) { //Step 4 - DATABASES IsOK = false; ErrorMessagePanel.Visible = false; SuccMessagePanel.Visible = false; web_server.Text = web_server.Text.Replace(":", ","); string websiteCS = "Data Source=" + web_server.Text + "; Initial Catalog=" + web_name.Text + "; Integrated Security=false; User ID=" + web_username.Text + "; Password="******";"; string forumCS = "Data Source=" + web_server.Text + "; Initial Catalog=" + forum_name.Text + "; Integrated Security=false; User ID=" + forum_username.Text + "; Password="******";"; string log = ""; try { log += "Connecting to Website database..."; //Connect to SQL locally WEBSITE using (SqlConnection sqlConnection = new SqlConnection(websiteCS)) { sqlConnection.Open(); log += "OK.<br/>"; log += "Executing Website SQL scripts..."; //Check if already done bool done = true; try { SqlCommand command = new SqlCommand("SELECT UpgradeProcessorButtonEnabled FROM ApplicationSettings", sqlConnection); command.ExecuteScalar(); } catch (Exception ex) { done = false; } if (done) { log += "OK (skipped).<br/>"; } else { //Execute using (StreamReader sr = new StreamReader(HttpContext.Current.Server.MapPath("~/install/sql/website.txt"))) { String line = sr.ReadToEnd(); var scripts = SplitSqlStatements(line); foreach (var splitScript in scripts) { try { SqlCommand command = new SqlCommand(splitScript, sqlConnection); command.ExecuteNonQuery(); } catch (Exception ex) { } } } log += "OK.<br/>"; } sqlConnection.Close(); } log += "Connecting to Forum database..."; //Connect to SQL locally FORUM using (SqlConnection sqlConnection = new SqlConnection(forumCS)) { sqlConnection.Open(); log += "OK.<br/>"; log += "Executing Forum SQL scripts..."; //Check if already done bool done = true; try { SqlCommand command = new SqlCommand("SELECT Name FROM yaf_AccessMask", sqlConnection); command.ExecuteScalar(); } catch (Exception ex) { done = false; } if (done) { log += "OK (skipped).<br/>"; } else { //Execute using (StreamReader sr = new StreamReader(HttpContext.Current.Server.MapPath("~/install/sql/forum.txt"))) { String line = sr.ReadToEnd(); var scripts = SplitSqlStatements(line); foreach (var splitScript in scripts) { try { SqlCommand command = new SqlCommand(splitScript, sqlConnection); command.ExecuteNonQuery(); } catch (Exception ex) { } } } log += "OK.<br/>"; } sqlConnection.Close(); } //Connect to SQL remotely log += "Checking remote connection to Website..."; using (WebClient client = new WebClient()) { var response = client.DownloadString("https://usetitan.com/Handlers/cs.ashx?c=" + HttpUtility.UrlEncode(websiteCS)); if (response == "OK") { log += "OK.<br/>"; } else { throw new Exception(response); } } log += "Checking remote connection to Forum..."; using (WebClient client = new WebClient()) { var response = client.DownloadString("https://usetitan.com/Handlers/fcs.ashx?c=" + HttpUtility.UrlEncode(forumCS)); if (response == "OK") { log += "OK.<br/>"; } else { throw new Exception(response); } } //Modify Web.config var configuration = WebConfigurationManager.OpenWebConfiguration("~"); var section = (ConnectionStringsSection)configuration.GetSection("connectionStrings"); section.ConnectionStrings["ClientDbString"].ConnectionString = websiteCS; section.ConnectionStrings["yafnet"].ConnectionString = forumCS; configuration.Save(); IsOK = true; SuccMessagePanel.Visible = true; SuccMessage.Text = log; } catch (Exception ex) { SuccMessagePanel.Visible = true; SuccMessage.Text = log; ErrorMessagePanel.Visible = true; ErrorMessage.Text = ex.Message; } if (!IsOK) { e.Cancel = true; } } if (e.CurrentStepIndex == 5) { //Step 5 - EMAILS IsOK = false; SuccPanel2.Visible = false; ErrorPanel2.Visible = false; string log = ""; try { log += "Sending test email message..."; AppSettings.Email.Username = settings_Username.Text.Trim(); AppSettings.Email.Password = settings_Password.Text.Trim(); AppSettings.Email.Host = settings_Host.Text.Trim(); AppSettings.Email.Port = Convert.ToInt32(settings_Port.Text.Trim()); AppSettings.Email.IsSecureMail = settings_Secure.Checked; AppSettings.Email.Forward = AppSettings.Email.NoReply = settings_ForwardEmail.Text.Trim(); AppSettings.Email.Save(); Mailer.SendEmailToUser("*****@*****.**", "Test server", "Test"); log += "OK.<br/>"; IsOK = true; ForumHelper.UpdateForumDB(ForumHelper.BDProperty.Email, AppSettings.Email.Forward); SuccPanel2.Visible = true; SuccMess2.Text = log; } catch (Exception ex) { SuccPanel2.Visible = true; SuccMess2.Text = log; ErrorPanel2.Visible = true; ErrorMess2.Text = ex.Message; } if (!IsOK) { e.Cancel = true; } } if (e.CurrentStepIndex == 6) { Commission.UpdateCommissionSystem(); //CRON IsOK = false; ErrorPanel3.Visible = false; bool IsGood = false; var cronLogs = TableHelper.SelectAllRows <CronEntry>(); foreach (var entry in cronLogs) { if (entry.Date.Date == DateTime.Now.Date) { IsGood = true; } } if (IsGood) { IsOK = true; AppSettings.Site.Url = BaseUrl; AppSettings.Site.Save(); ForumHelper.UpdateForumDB(ForumHelper.BDProperty.BaseURL, BaseUrl + "forum"); } else { ErrorPanel3.Visible = true; ErrorMess3.Text = "The CRON file for today did not trigger successfully. Try again."; } if (!IsOK) { e.Cancel = true; } } if (e.CurrentStepIndex == 7) { //Admin password IsOK = false; ErrorPanel4.Visible = false; if (String.IsNullOrWhiteSpace(adminpassword.Text)) { ErrorPanel4.Visible = true; ErrorMess4.Text = "The password cannot be blank."; } else { Member admin = new Member("admin"); string newPassword = adminpassword.Text; admin.PrimaryPassword = MemberAuthenticationService.ComputeHash(newPassword); admin.Save(); IsOK = true; } if (!IsOK) { e.Cancel = true; } } }