init lserp cs 5.0
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
|
||||
using Zhaizj.Framework.Reflection;
|
||||
using Zhaizj.Framework.Web;
|
||||
using Zhaizj.Framework.Web.Mvc;
|
||||
|
||||
namespace Zhaizj.Framework.Data {
|
||||
|
||||
|
||||
internal class DatabaseBuilder {
|
||||
|
||||
public static String ConnectionStringPrefix = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";
|
||||
private static readonly ILog logger = LogManager.GetLogger( typeof( DatabaseBuilder ) );
|
||||
|
||||
public static String BuildAccessDb4o() {
|
||||
String dbPath = getDbPath();
|
||||
BuildAccessDb4o( dbPath );
|
||||
return dbPath;
|
||||
}
|
||||
|
||||
public static void BuildAccessDb4o( String dbPath ) {
|
||||
String str = ConnectionStringPrefix + dbPath;
|
||||
logger.Info( "creating database : " + str );
|
||||
Object instanceFromProgId = ReflectionUtil.GetInstanceFromProgId( "ADOX.Catalog" );
|
||||
try {
|
||||
ReflectionUtil.CallMethod( instanceFromProgId, "Create", new object[] { str } );
|
||||
}
|
||||
catch (Exception exception) {
|
||||
logger.Info( "creating database error : " + exception.Message );
|
||||
LogManager.Flush();
|
||||
throw exception;
|
||||
}
|
||||
logger.Info( "create database ok" );
|
||||
}
|
||||
|
||||
//public static void Compact( String dbPath ) {
|
||||
// if (!File.Exists( dbPath )) {
|
||||
// throw new Exception( "database not found" );
|
||||
// }
|
||||
// IDbConnection connection = DbContext.getConnection();
|
||||
// if ((connection != null) && (connection.State == ConnectionState.Open)) {
|
||||
// connection.Close();
|
||||
// }
|
||||
// String sourceFileName = dbPath + ".bak";
|
||||
// ReflectionUtil.CallMethod( ReflectionUtil.GetInstanceFromProgId( "JRO.JetEngine" ), "CompactDatabase", new object[] { ConnectionStringPrefix + dbPath, ConnectionStringPrefix + sourceFileName } );
|
||||
// File.Copy( sourceFileName, dbPath, true );
|
||||
// File.Delete( sourceFileName );
|
||||
//}
|
||||
|
||||
private static String getDbPath() {
|
||||
DateTime now = DateTime.Now;
|
||||
String path = "Zhaizj.FrameworkDB_" + Guid.NewGuid().ToString().Replace( "-", "" ) + ".mdb";
|
||||
path = PathHelper.Map( path );
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user