예제 #1
0
        public ViewResult RunSqlScript()
        {
            var viewData  = new RunSqlScriptViewData(CurrentFirmaSession);
            var viewModel = new RunSqlScriptViewModel();

            return(RazorView <RunSqlScript, RunSqlScriptViewData, RunSqlScriptViewModel>(viewData, viewModel));
        }
예제 #2
0
        public ActionResult RunSqlScript(RunSqlScriptViewModel viewModel)
        {
            var             outputMessages = new List <string>();
            Action <string> logFunction    = outputMessages.Add;

            string statusString = "Unknown";

            if (ModelState.IsValid)
            {
                var webSiteDir = new DirectoryInfo(HttpContext.Server.MapPath("/").TrimEnd('\\'));

                var dbServerName = HttpRequestStorage.DatabaseEntities.Database.Connection.DataSource;
                var dbName       = HttpRequestStorage.DatabaseEntities.Database.Connection.Database;

                var installer = new WebAppInstallerUtility(webSiteDir, viewModel.PostedFileBase, dbName, dbServerName, logFunction);

                try
                {
                    // Do the complete installation process
                    installer.DoInstallation();
                    // Only mark success here
                    statusString = "Success!";
                }
                catch (Exception e)
                {
                    logFunction(e.ToString());
                    statusString = "Failure";
                }
            }

            var outputMessagesLines = string.Join("\r\n", outputMessages);

            // We have to resort to a super simple, primitive view, otherwise most every deploy will throw a false alarm
            // about a crash only related to changing the views in the middle of a request. These are meaningless, but very disturbing.
            //
            // Add a little html formatting, otherwise this is totally hard to read
            string backButton = SitkaRoute <AdminController> .BuildLinkFromExpression(c => c.RunSqlScript(), "Back to Update Site");

            string htmlWrapper = string.Format(@"
<html>
<body>
<h1>{0}</h1>
{1}
<pre>
{2}
</pre>
</body>
</html>", statusString, backButton, Server.HtmlEncode(outputMessagesLines));

            return(Content(htmlWrapper, "text/html"));
        }