public void Initialise(string connectionString)
        {
            m_connectionString = connectionString;

            using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
            {
                dbcon.Open();

                // Apply new Migrations
                //
                Assembly assem = GetType().Assembly;
                LegacyMigration m = new LegacyMigration (dbcon, assem, "RegionStore");
                m.Update();
            }
        }
        /// <summary>
        /// See IRegionDataStore
        /// <list type="bullet">
        /// <item>Initialises RegionData Interface</item>
        /// <item>Loads and initialises a new SQLite connection and maintains it.</item>
        /// </list>
        /// </summary>
        /// <param name="connectionString">the connection string</param>
        public void Initialise(string connectionString)
        {
            try
            {
                ds = new DataSet("Region");

                connectionString = connectionString.Replace("URI=file:", "URI=file:" + Util.BasePathCombine("") + "/");
                m_conn = new SqliteConnection(connectionString);
                m_conn.Open();

                // SqliteCommandBuilder shapeCb = new SqliteCommandBuilder(shapeDa);

                SqliteCommand terrainSelectCmd = new SqliteCommand(terrainSelect, m_conn);
                terrainDa = new SqliteDataAdapter(terrainSelectCmd);

                SqliteCommand landSelectCmd = new SqliteCommand(landSelect, m_conn);
                landDa = new SqliteDataAdapter(landSelectCmd);

                SqliteCommand landAccessListSelectCmd = new SqliteCommand(landAccessListSelect, m_conn);
                landAccessListDa = new SqliteDataAdapter(landAccessListSelectCmd);

                SqliteCommand regionSettingsSelectCmd = new SqliteCommand(regionSettingsSelect, m_conn);
                regionSettingsDa = new SqliteDataAdapter(regionSettingsSelectCmd);

                // This actually does the roll forward assembly stuff
                LegacyMigration m = new LegacyMigration (m_conn, GetType ().Assembly, "RegionStore");
                m.Update();

                lock (ds)
                {
                    ds.Tables.Add(createTerrainTable());
                    setupTerrainCommands(terrainDa, m_conn);

                    ds.Tables.Add(createLandTable());
                    setupLandCommands(landDa, m_conn);

                    ds.Tables.Add(createLandAccessListTable());
                    setupLandAccessCommands(landAccessListDa, m_conn);

                    ds.Tables.Add(createRegionSettingsTable());
                    setupRegionSettingsCommands(regionSettingsDa, m_conn);

                    try
                    {
                        terrainDa.Fill(ds.Tables["terrain"]);
                    }
                    catch (Exception)
                    {
                        m_log.Info("[SQLITE REGION DB]: Caught fill error on terrain table");
                    }

                    try
                    {
                        landDa.Fill(ds.Tables["land"]);
                    }
                    catch (Exception)
                    {
                        m_log.Info("[SQLITE REGION DB]: Caught fill error on land table");
                    }

                    try
                    {
                        landAccessListDa.Fill(ds.Tables["landaccesslist"]);
                    }
                    catch (Exception)
                    {
                        m_log.Info("[SQLITE REGION DB]: Caught fill error on landaccesslist table");
                    }

                    try
                    {
                        regionSettingsDa.Fill(ds.Tables["regionsettings"]);
                    }
                    catch (Exception)
                    {
                        m_log.Info("[SQLITE REGION DB]: Caught fill error on regionsettings table");
                    }

                    // We have to create a data set mapping for every table, otherwise the IDataAdaptor.Update() will not populate rows with values!
                    // Not sure exactly why this is - this kind of thing was not necessary before - justincc 20100409
                    // Possibly because we manually set up our own DataTables before connecting to the database
                    CreateDataSetMapping(terrainDa, "terrain");
                    CreateDataSetMapping(landDa, "land");
                    CreateDataSetMapping(landAccessListDa, "landaccesslist");
                    CreateDataSetMapping(regionSettingsDa, "regionsettings");
                }
            }
            catch (Exception e)
            {
                m_log.Error(e);
                //TODO: better error for users!
                System.Threading.Thread.Sleep(10000); //Sleep so the user can see the error
                Environment.Exit(23);
            }

            return;
        }
Beispiel #3
0
        /// <summary>
        /// <list type="bullet">
        /// <item>Initialises AssetData interface</item>
        /// <item>Loads and initialises a new SQLite connection and maintains it.</item>
        /// <item>use default URI if connect string is empty.</item>
        /// </list>
        /// </summary>
        /// <param name="dbconnect">connect string</param>
        public void Initialise(string dbconnect)
        {
            if (dbconnect == string.Empty)
            {
                dbconnect = "URI=file:Asset.db,version=3";
            }
            dbconnect = dbconnect.Replace("URI=file:", "URI=file:" + Util.BasePathCombine("") + "/");
            m_conn = new SqliteConnection(dbconnect);
            m_conn.Open();

            Assembly assem = GetType().Assembly;
            LegacyMigration m = new LegacyMigration (m_conn, assem, "AssetStore");
            m.Update();

            return;
        }