public static void Init() { if( s_world != null && s_db != null ) return; // Load up all the strings of interest from the web.config file. var strings = System.Configuration.ConfigurationManager.ConnectionStrings; string dbString = strings["climoo_dbcConnectionString"].ConnectionString; string dbClass = strings["climoo_dbcConnectionString"].ProviderName; //string xmlString = strings["climoo_xmlImportPathString"].ConnectionString; // We'll use this in multiple places below. var ti = new TableInfo(); // Break up the pieces of the connection class to figure out what to load. string[] classPieces = dbClass.Split( ',' ).Select( x => x.Trim() ).ToArray(); if( classPieces.Length < 2 ) throw new ArgumentException( "Too few comma-delimited strings in the database connection class string", dbClass ); string className = classPieces[0]; string asmName = classPieces[1]; // This assembly we want is possibly already loaded, but this gets us a handle to it. Assembly dbAsm = Assembly.Load( asmName ); Type dbType = dbAsm.GetType( className ); // Create the actual database class. IDatabase db = (IDatabase)(Activator.CreateInstance( dbType )); db.setup( dbString, ti ); if (s_world == null) { // s_world = MooCore.World.FromXml( xmlString ); var coredb = new CoreDatabase( db ); var wdb = new WorldDatabase( coredb ); s_world = CanonWorld.FromWorldDatabase( wdb, true, false ); s_world.attributeUrlGenerator = (mob, attr) => { return string.Format( "/Game/ServeAttribute?objectId={0}&attributeName={1}", mob.id, attr ); }; } if (s_db == null) { s_db = db; // s_db = new MemoryDatabase(); // Models.XmlModelPersistence.Import(System.IO.Path.Combine(basePath, "web.xml"), s_db); } }
public static void Shutdown() { if( s_world == null ) return; s_world.Dispose(); s_world = null; }