/*
Kooboo is a content management system based on ASP.NET MVC framework. Copyright 2009 Yardi Technology Limited.
This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License version 3 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.kooboo.com/gpl3/.
*/
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Security.Principal;
using System.Web;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Web.Mvc;
using System.Web.Security;
using System.Web.UI;
using System.Configuration;
using Everest.Library.Mvc;
using Everest.Library.ExtensionMethod;
using System.IO;
using System.Text.RegularExpressions;
using Everest.CmsServices.Installation;
namespace Everest.CmsServices.Controllers{
public class InstallController : EverestControllerBase
{
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Index()
{
DatabaseList();
return View();
}
private IEnumerable<SelectListItem> GetSupportedDatabase()
{
List<SelectListItem> databaseTypes = new List<SelectListItem>()
{
new SelectListItem(){ Selected=false,Text="MS SQLServer",Value="1"}
};
if (CmsGlobal.RuntimeBitWidth == BitWidth.Bit_32)
{
databaseTypes.Add(new SelectListItem() { Selected = true, Text = "SQLite", Value = "2" });
}
return databaseTypes;
}
private void DatabaseList()
{
ViewData["DatabaseType"] = GetSupportedDatabase();
if (ConfigurationManager.ConnectionStrings["EverestCms"] != null)
{
var builder = new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["EverestCms"].ConnectionString);
ViewData["Server"] = builder.DataSource;
ViewData["DatabaseName"] = builder.InitialCatalog;
ViewData["UserName"] = builder.UserID;
ViewData["Password"] = builder.Password;
}
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(DatabaseInfo databaseInfo)
{
try
{
Installation.Installation.Install(databaseInfo, AppDomain.CurrentDomain.BaseDirectory);
}
catch (Exception e)
{
DatabaseList();
ViewData["ErrorMessage"] = e.Message;
return View("Index");
}
return InstallSuccessful();
}
private ActionResult InstallSuccessful()
{
System.Web.HttpRuntime.UnloadAppDomain();
return Redirect("~/account/login");
}
public ActionResult Finished()
{
return View();
}
}
}
|