Пример #1
0
        public bool Convert()
        {
            try
            {
                SqliteConnection conn = new SqliteConnection(m_assetConnectionString);
                conn.Open();

                Assembly assem = GetType().Assembly;
                Migration m = new Migration(conn, assem, "AssetStore");

                if (m.Version == 0)
                {
                    //fetch all assets with mediaurl and construct RexAssetData objects
                    List<RexAssetData> rexAssets = new List<RexAssetData>();

                    using (SqliteCommand cmd = new SqliteCommand(assetSelect, conn))
                    {
                        using (IDataReader reader = cmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                if (((String)reader["MediaURL"]) != "")
                                {
                                    UUID id = new UUID((String) reader["UUID"]);
                                    string mediaUrl = (String)reader["MediaURL"];
                                    byte refreshRate = 0;
                                    object refRate = reader["RefreshRate"];
                                    if (refRate is byte)
                                    {
                                        refreshRate = (byte)refRate;
                                    }
                                    RexAssetData data = new RexAssetData(id, mediaUrl,refreshRate);
                                    rexAssets.Add(data);
                                }
                            }
                        }
                    }
                    conn.Close();

                    //Now add them to ModreX database
                    NHibernateRexAssetData rexAssetManager = new NHibernateRexAssetData();
                    rexAssetManager.Initialise(m_rexConnectionString);
                    foreach (RexAssetData data in rexAssets)
                    {
                        rexAssetManager.StoreObject(data);
                    }

                    //finally remove realXtend properties and update version number
                    conn.Open();
                    //TODO: remove realXtend properties
                    // this is not done yet because SQLite is missing drop column feature
                    m.Version = 1;
                }

                conn.Close();
                return true;
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[AssetStore] Migration failed. Reason: {0}", e);
                return false;
            }
        }
Пример #2
0
        public void Initialise(Scene scene, IConfigSource source)
        {
            m_scenes.Add(scene);

            scene.EventManager.OnNewClient += OnNewClient;

            if (m_db == null)
            {
                m_db = new NHibernateRexAssetData();
            }

            string default_connection_string = "SQLiteDialect;SQLite20Driver;Data Source=RexObjects.db;Version=3";
            try
            {
                m_db_connectionstring = source.Configs["realXtend"].GetString("db_connectionstring", default_connection_string);
            }
            catch (Exception)
            {
                m_db_connectionstring = default_connection_string;
            }
        }