/*
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.Linq;
using System.Text;
using System.Configuration;
using Everest.Library.ExtensionMethod;
using System.IO;
namespace Everest.CmsServices.Installation{
public class KoobooInstance
{
public KoobooInstance(string path)
{
this.KoobooPath = path;
ParseKooboo();
}
private void ParseKooboo()
{
var koobooServiceDll = Path.Combine(this.KoobooPath, "Bin\\Everest.CmsServices.dll");
EnsureFileExists(koobooServiceDll);
Version = AssemblyExtesions.GetAssemblyVersion(koobooServiceDll);
var webConfig = Path.Combine(this.KoobooPath, "web.config");
var configuration = LoadWebConfig(webConfig);
var everestCmsConn = configuration.ConnectionStrings.ConnectionStrings["EverestCms"];
if (everestCmsConn == null)
{
ThrowInvalidKooboo();
}
ConnectionString = everestCmsConn.ConnectionString;
if (everestCmsConn.ProviderName.Equals("System.Data.SqlClient", StringComparison.InvariantCultureIgnoreCase))
{
DatabaseType = KoobooDatabaseType.MSSQL;
}
if (everestCmsConn.ProviderName.Equals("System.Data.SQLite", StringComparison.InvariantCultureIgnoreCase))
{
DatabaseType = KoobooDatabaseType.SQLite;
}
}
private Configuration LoadWebConfig(string filePath)
{
EnsureFileExists(filePath);
var map = new ExeConfigurationFileMap();
map.ExeConfigFilename = filePath;
Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
return configuration;
}
private void EnsureFileExists(string filePath)
{
if (!File.Exists(filePath))
{
ThrowInvalidKooboo();
}
}
private static void ThrowInvalidKooboo()
{
throw new Exception(Resources.InvalidKoobooInstance);
}
public string KoobooPath { get; private set; }
public Version Version { get; private set; }
public string ConnectionString { get; private set; }
public KoobooDatabaseType DatabaseType { get; private set; }
}
}
|