Exemplo n.º 1
0
        public ActionResult Step3()
        {
            if (Session[SessionMailInfoKey] != null)
            {
                ViewData[ViewDataKeys.GlobalMessages.Success] = "Successfully connected to mail server";
            }

            SQLInstallViewModel sqlInfo = Session[SessionSqlInfoKey] as SQLInstallViewModel;

            if (sqlInfo != null)
            {
                Settings.DatabaseServer        = sqlInfo.DatabaseServer;
                Settings.DatabaseName          = sqlInfo.DatabaseName;
                Settings.UseIntegratedSecurity = sqlInfo.UseIntegratedSecurity;
                if (!sqlInfo.UseIntegratedSecurity)
                {
                    Settings.DatabaseLogin    = sqlInfo.DatabaseLogin;
                    Settings.DatabasePassword = sqlInfo.DatabasePassword;
                }

                string connectionString =
                    Settings.ConnectionStringTemplate
                    .Replace("{dbserver}", sqlInfo.DatabaseServer)
                    .Replace("{integratedsecurity}", sqlInfo.UseIntegratedSecurity.ToString())
                    .Replace("{dbname}", sqlInfo.DatabaseName)
                    .Replace("{dblogin}", sqlInfo.DatabaseLogin)
                    .Replace("{dbpassword}", sqlInfo.DatabasePassword);

                string     entityConnectionString = Settings.EntityConnectionStringTemplate.Replace("{CONNECTIONSTRING}", connectionString);
                mbEntities dataContext            = new mbEntities(entityConnectionString);

                Config automatedEmail = dataContext.Configs.First(item => item.Name.Equals("AutomatedFromEmail"));
                automatedEmail.Value = "no-reply@" + Request.Url.Host;

                Config boardUrl = dataContext.Configs.First(item => item.Name.Equals("BoardURL"));
                boardUrl.Value = Request.Url.Host;

                dataContext.SaveChanges();
            }

            MailInstallViewModel mailInfo = Session[SessionMailInfoKey] as MailInstallViewModel;

            if (mailInfo != null)
            {
                Settings.SmtpServer = mailInfo.MailServerAddress;
                Settings.SmtpPort   = mailInfo.PortNumber;
                Settings.SmtpUseDefaultCredentials = mailInfo.MailUseDefaultCredentials;
                if (!mailInfo.MailUseDefaultCredentials)
                {
                    Settings.SmtpLogin    = mailInfo.MailLogin;
                    Settings.SmtpPassword = mailInfo.MailPassword;
                }
            }

            ViewData["StepNumber"] = 3;
            return(View());
        }
Exemplo n.º 2
0
        public ActionResult Step1()
        {
            ViewData["StepNumber"] = 1;
            SQLInstallViewModel model = new SQLInstallViewModel
            {
                DatabaseServer        = "localhost",
                UseIntegratedSecurity = false,
            };

            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult Step1(SQLInstallViewModel info)
        {
            ViewData["StepNumber"] = 1;

            if (info.UseIntegratedSecurity)
            {
                ModelState.Remove("DatabaseLogin");
                ModelState.Remove("DatabasePassword");
            }

            if (!ModelState.IsValid)
            {
                return(View(info));
            }

            SqlConnectionStringBuilder connectionString = new SqlConnectionStringBuilder();

            connectionString.DataSource               = info.DatabaseServer;
            connectionString.InitialCatalog           = info.DatabaseName;
            connectionString.MultipleActiveResultSets = true;
            connectionString.IntegratedSecurity       = info.UseIntegratedSecurity;;

            if (!info.UseIntegratedSecurity)
            {
                connectionString.UserID   = info.DatabaseLogin;
                connectionString.Password = info.DatabasePassword;
            }

            SqlConnection connection = new SqlConnection(connectionString.ToString());

            try
            {
                connection.Open();
                string sql = System.IO.File.ReadAllText(Server.MapPath("~/App_Data/Install/mesoBoard.SqlServer.sql"));

                string[] cmds = sql.Split(new string[] { "GO" }, StringSplitOptions.RemoveEmptyEntries);

                SqlCommand command = new SqlCommand();
                command.Connection = connection;
                foreach (string cmd in cmds)
                {
                    command.CommandText = cmd;
                    command.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                TempData[ViewDataKeys.GlobalMessages.Notice] = "Unable to connect to SQL server, check connection information";
                TempData[ViewDataKeys.GlobalMessages.Error]  = ex.Message;
                return(View(info));
            }
            finally
            {
                connection.Close();
                connection.Dispose();
            }

            Session[SessionSqlInfoKey] = info;

            return(RedirectToAction("Step2"));
        }