示例#1
0
        public void Initialise(IConfigSource source, IRegistryCore simBase, List <Type> types)
        {
            IConfig m_config = source.Configs["AuroraData"];

            if (m_config != null)
            {
                StorageProvider  = m_config.GetString("StorageProvider", StorageProvider);
                ConnectionString = m_config.GetString("ConnectionString", ConnectionString);
            }

            IGenericData DataConnector = null;

            if (StorageProvider == "MySQL")
            //Allow for fallback when AuroraData isn't set
            {
                MySQLDataLoader GenericData = new MySQLDataLoader();

                DataConnector = GenericData;
            }

            /*else if (StorageProvider == "MSSQL2008")
             * {
             * MSSQLDataLoader GenericData = new MSSQLDataLoader();
             *
             * DataConnector = GenericData;
             * }
             * else if (StorageProvider == "MSSQL7")
             * {
             * MSSQLDataLoader GenericData = new MSSQLDataLoader();
             *
             * DataConnector = GenericData;
             * }*/
            else if (StorageProvider == "SQLite")
            //Allow for fallback when AuroraData isn't set
            {
                SQLiteLoader GenericData = new SQLiteLoader();

                DataConnector = GenericData;
            }

            foreach (Type t in types)
            {
                List <dynamic> Plugins = AuroraModuleLoader.PickupModules(t);
                foreach (dynamic plugin in Plugins)
                {
                    try
                    {
                        plugin.Initialize(DataConnector.Copy(), source, simBase, ConnectionString);
                    }
                    catch (Exception ex)
                    {
                        if (MainConsole.Instance != null)
                        {
                            MainConsole.Instance.Warn("[DataService]: Exeception occured starting data plugin " +
                                                      plugin.Name + ", " + ex.ToString());
                        }
                    }
                }
            }
        }
示例#2
0
        public void Initialise(IConfigSource config, IRegistryCore registry)
        {
            IConfig m_config = config.Configs ["WhiteCoreData"];

            if (m_config != null)
            {
                storageProvider  = m_config.GetString("StorageProvider", storageProvider);
                connectionString = m_config.GetString("ConnectionString", connectionString);
            }

            IGenericData dataConnector = null;

            if (storageProvider == "MySQL")
            // Allow for fallback when WhiteCoreData isn't set
            {
                MySQLDataLoader genericData = new MySQLDataLoader();

                dataConnector = genericData;
            }

            /*else if (StorageProvider == "MSSQL2008")
             * {
             *  MSSQLDataLoader GenericData = new MSSQLDataLoader();
             *
             *  DataConnector = GenericData;
             * }
             * else if (StorageProvider == "MSSQL7")
             * {
             *  MSSQLDataLoader GenericData = new MSSQLDataLoader();
             *
             *  DataConnector = GenericData;
             * }*/
            else if (storageProvider == "SQLite")
            // Allow for fallback when WhiteCoreData isn't set
            {
                SQLiteLoader genericData = new SQLiteLoader();

                // set default data directory in case it is needed
                var simBase = registry.RequestModuleInterface <ISimulationBase> ();
                genericData.DefaultDataPath = simBase.DefaultDataPath;

                dataConnector = genericData;
            }

            List <IWhiteCoreDataPlugin> Plugins = WhiteCoreModuleLoader.PickupModules <IWhiteCoreDataPlugin> ();

            foreach (IWhiteCoreDataPlugin plugin in Plugins)
            {
                try {
                    plugin.Initialize(dataConnector == null ? null : dataConnector.Copy(), config, registry,
                                      connectionString);
                } catch (Exception ex) {
                    if (MainConsole.Instance != null)
                    {
                        MainConsole.Instance.Warn("[DataService]: Exception occurred starting data plugin " +
                                                  plugin.Name + ", " + ex);
                    }
                }
            }
        }
示例#3
0
        public void Initialise(IConfigSource source, IRegistryCore simBase)
        {
            //
            // Try reading the [DatabaseService] section, if it exists
            //
            IConfig dbConfig = source.Configs["DatabaseService"];

            if (dbConfig != null)
            {
                StorageProvider  = dbConfig.GetString("StorageProvider", String.Empty);
                ConnectionString = dbConfig.GetString("ConnectionString", String.Empty);
            }

            //
            // [AuroraData] section overrides [DatabaseService], if it exists
            //
            IConfig m_config = source.Configs["AuroraData"];

            if (m_config != null)
            {
                StorageProvider  = m_config.GetString("StorageProvider", StorageProvider);
                ConnectionString = m_config.GetString("ConnectionString", ConnectionString);
            }

            IGenericData DataConnector = null;

            if (StorageProvider == "MySQL" || StorageProvider == "OpenSim.Data.MySQL.dll") //Allow for fallback when AuroraData isn't set
            {
                MySQLDataLoader GenericData = new MySQLDataLoader();

                DataConnector = GenericData;
            }
            else if (StorageProvider == "MSSQL2008")
            {
                MSSQLDataLoader GenericData = new MSSQLDataLoader();

                DataConnector = GenericData;
            }
            else if (StorageProvider == "MSSQL7")
            {
                MSSQLDataLoader GenericData = new MSSQLDataLoader();

                DataConnector = GenericData;
            }
            else if (StorageProvider == "SQLite" || StorageProvider == "OpenSim.Data.SQLite.dll") //Allow for fallback when AuroraData isn't set
            {
                SQLiteLoader GenericData = new SQLiteLoader();

                DataConnector = GenericData;
            }

            List <IAuroraDataPlugin> Plugins = AuroraModuleLoader.PickupModules <IAuroraDataPlugin>();

            foreach (IAuroraDataPlugin plugin in Plugins)
            {
                plugin.Initialize(DataConnector.Copy(), source, simBase, ConnectionString);
            }
        }
示例#4
0
        // must specify database file on creation
        // will throw an error if database not found or invalid format
        public Database(string dbPath)
        {
            logger.Trace(nameof(Database));
            this.dbPath = dbPath;

            // check if the database exists
            ValidateDbFileExists();

            if (InitDll)
            {
                InitDll = false;

                // add support for loading correct native DLLs under both Win32 (x86) and Win64 (amd64)
                try
                {
                    SQLiteLoader.SetNativeDllDirectory();

                    // force loading of DLL (should throw an error if failed to load DLL) and log version
                    var sqliteVersion = SQLite3.LibVersionNumber();
                    logger.Info($"SQLite3 DLL version is {sqliteVersion}");
                }
                catch (Exception e)
                {
                    logger.Error(e, $"Critical error initializing dynamic libraries!  ABORTING! - {e.Message}");
                    throw;
                }

                // setup logging SQLite errors, must be done before Initialize()
                if (SQLite3.Config(SQLite3.ConfigOption.Log, SQLiteErrorLogCallbackDelegate, IntPtr.Zero) != SQLite3.Result.OK)
                {
                    logger.Error("Failed to register SQlite error log callback!");
                }

                // ensure initialized (future versions and some embedded versions may not automatically call this)
                // [may be automatically invoked by Open() call when creating the SQLiteConnection]
                if (SQLite3.Initialize() != SQLite3.Result.OK)
                {
                    logger.Warn("Failed to Initialize() SQLite!");
                }
            }

            // attempt to open our connection to db
            dbConnection = new SQLiteConnection(dbPath, storeDateTimeAsTicks: true);

#if DEBUG
            // enable debug output of SQL statements executed
            dbConnection.Trace = true;
#endif

            // confirm it is of expected format
            ValidateSchema();
        }
        public void Initialise(IConfigSource source, IRegistryCore simBase)
        {
            IConfig m_config = source.Configs["UniverseData"];

            if (m_config != null)
            {
                StorageProvider  = m_config.GetString("StorageProvider", StorageProvider);
                ConnectionString = m_config.GetString("ConnectionString", ConnectionString);
            }

            IGenericData DataConnector = null;

            if (StorageProvider == "MySQL")
            //Allow for fallback when UniverseData isn't set
            {
                MySQLDataLoader GenericData = new MySQLDataLoader();

                DataConnector = GenericData;
            }
            else if (StorageProvider == "SQLite")
            //Allow for fallback when UniverseData isn't set
            {
                SQLiteLoader GenericData = new SQLiteLoader();

                DataConnector = GenericData;
            }

            List <IUniverseDataPlugin> Plugins = UniverseModuleLoader.PickupModules <IUniverseDataPlugin>();

            foreach (IUniverseDataPlugin plugin in Plugins)
            {
                try
                {
                    plugin.Initialize(DataConnector == null ? null : DataConnector.Copy(), source, simBase,
                                      ConnectionString);
                }
                catch (Exception ex)
                {
                    if (MainConsole.Instance != null)
                    {
                        MainConsole.Instance.Warn("[DataService]: Exception occurred starting data plugin " +
                                                  plugin.Name + ", " + ex.ToString());
                    }
                }
            }
        }
示例#6
0
        /// <summary>
        /// Writes a single modfile into memory
        /// </summary>
        /// <param name="SingleMod">A single mod file</param>
        /// <returns>returns true if successful</returns>
        private bool WriteModFileIntoMemory(SingleFile SingleModFile, string Path)
        {
            try
            {
                long Address = -1;
                if (SingleModFile.SQLiteFiles != null && SingleModFile.SQLiteFiles.Length > 0)
                {
                    foreach (var FileName in SingleModFile.SQLiteFiles)
                    {
                        List <Pointer> Pointers = SQLiteLoader.GetPointerListFromSQLiteFile(Path + SingleModFile.Directory + @"\" + FileName);
                        Address = ModLoader.TestPointers(Pointers.ToArray(), SingleModFile.ComparisonString);
                        if (Address != -1)
                        {
                            break;
                        }
                    }
                }

                if (Address == -1)
                {
                    Address = ModLoader.findAddress(Encoding.ASCII.GetBytes(SingleModFile.ComparisonString));
                }

                //Add the offset
                if (SingleModFile.AddressOffset != 0)
                {
                    Address += SingleModFile.AddressOffset;
                }

                if (Address != -1)
                {
                    ModLoader.WriteMemory(Address, File.ReadAllBytes(Path + SingleModFile.Directory + @"\" + SingleModFile.ReplacedCodeFile));
                    return(true);
                }

                return(false);
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#7
0
        public void RepairMissingBlocklistHashes()
        {
            byte[] data = new byte[150 * 1024];
            Random rng  = new Random();

            for (int k = 0; k < 2; k++)
            {
                rng.NextBytes(data);
                File.WriteAllBytes(Path.Combine(this.DATAFOLDER, $"{k}"), data);
            }

            Dictionary <string, string> options = new Dictionary <string, string>(this.TestOptions);

            using (Controller c = new Controller("file://" + this.TARGETFOLDER, options, null))
            {
                IBackupResults backupResults = c.Backup(new[] { this.DATAFOLDER });
                Assert.AreEqual(0, backupResults.Errors.Count());
                Assert.AreEqual(0, backupResults.Warnings.Count());
            }

            // Mimic a damaged database that needs to be repaired.
            const string  selectStatement     = @"SELECT BlocksetID, ""Index"", Hash FROM BlocklistHash ORDER BY Hash ASC";
            List <int>    expectedBlocksetIDs = new List <int>();
            List <int>    expectedIndexes     = new List <int>();
            List <string> expectedHashes      = new List <string>();

            using (IDbConnection connection = SQLiteLoader.LoadConnection(options["dbpath"]))
            {
                // Read the contents of the BlocklistHash table so that we can
                // compare them to the contents after the repair operation.
                using (IDbCommand command = connection.CreateCommand())
                {
                    using (IDataReader reader = command.ExecuteReader(selectStatement))
                    {
                        while (reader.Read())
                        {
                            expectedBlocksetIDs.Add(reader.GetInt32(0));
                            expectedIndexes.Add(reader.GetInt32(1));
                            expectedHashes.Add(reader.GetString(2));
                        }
                    }
                }

                using (IDbCommand command = connection.CreateCommand())
                {
                    command.ExecuteNonQuery(@"DELETE FROM BlocklistHash");
                    using (IDataReader reader = command.ExecuteReader(selectStatement))
                    {
                        Assert.IsFalse(reader.Read());
                    }
                }
            }

            using (Controller c = new Controller("file://" + this.TARGETFOLDER, options, null))
            {
                IRepairResults repairResults = c.Repair();
                Assert.AreEqual(0, repairResults.Errors.Count());
                Assert.AreEqual(0, repairResults.Warnings.Count());
            }

            List <int>    repairedBlocksetIDs = new List <int>();
            List <int>    repairedIndexes     = new List <int>();
            List <string> repairedHashes      = new List <string>();

            using (IDbConnection connection = SQLiteLoader.LoadConnection(options["dbpath"]))
            {
                using (IDbCommand command = connection.CreateCommand())
                {
                    using (IDataReader reader = command.ExecuteReader(selectStatement))
                    {
                        while (reader.Read())
                        {
                            repairedBlocksetIDs.Add(reader.GetInt32(0));
                            repairedIndexes.Add(reader.GetInt32(1));
                            repairedHashes.Add(reader.GetString(2));
                        }
                    }
                }
            }

            CollectionAssert.AreEqual(expectedBlocksetIDs, repairedBlocksetIDs);
            CollectionAssert.AreEqual(expectedIndexes, repairedIndexes);
            CollectionAssert.AreEqual(expectedHashes, repairedHashes);

            // A subsequent backup should run without errors.
            using (Controller c = new Controller("file://" + this.TARGETFOLDER, options, null))
            {
                IBackupResults backupResults = c.Backup(new[] { this.DATAFOLDER });
                Assert.AreEqual(0, backupResults.Errors.Count());
                Assert.AreEqual(0, backupResults.Warnings.Count());
            }
        }
示例#8
0
        static GKLDatabase()
        {
#if !NETSTANDARD && !NET461
            SQLiteLoader.Load();
#endif
        }
示例#9
0
        public void Initialise(IConfigSource source, IRegistryCore simBase)
        {
            //
            // Try reading the [DatabaseService] section, if it exists
            //
            IConfig dbConfig = source.Configs["DatabaseService"];

            if (dbConfig != null)
            {
                StorageProvider  = dbConfig.GetString("StorageProvider", String.Empty);
                ConnectionString = dbConfig.GetString("ConnectionString", String.Empty);
            }

            //
            // [AuroraData] section overrides [DatabaseService], if it exists
            //
            IConfig m_config = source.Configs["AuroraData"];

            if (m_config != null)
            {
                StorageProvider  = m_config.GetString("StorageProvider", StorageProvider);
                ConnectionString = m_config.GetString("ConnectionString", ConnectionString);
            }

            IGenericData DataConnector = null;

            if (StorageProvider == "MySQL" || StorageProvider == "Aurora.DataManager.MySQL.dll")
            //Allow for fallback when AuroraData isn't set
            {
                MySQLDataLoader GenericData = new MySQLDataLoader();

                DataConnector = GenericData;
            }

            /*else if (StorageProvider == "MSSQL2008")
             * {
             *  MSSQLDataLoader GenericData = new MSSQLDataLoader();
             *
             *  DataConnector = GenericData;
             * }
             * else if (StorageProvider == "MSSQL7")
             * {
             *  MSSQLDataLoader GenericData = new MSSQLDataLoader();
             *
             *  DataConnector = GenericData;
             * }*/
            else if (StorageProvider == "SQLite" || StorageProvider == "Aurora.DataManager.SQLite.dll")
            //Allow for fallback when AuroraData isn't set
            {
                SQLiteLoader GenericData = new SQLiteLoader();

                DataConnector = GenericData;
            }

            List <IAuroraDataPlugin> Plugins = AuroraModuleLoader.PickupModules <IAuroraDataPlugin>();

            foreach (IAuroraDataPlugin plugin in Plugins)
            {
                try
                {
                    plugin.Initialize(DataConnector.Copy(), source, simBase, ConnectionString);
                }
                catch (Exception ex)
                {
                    MainConsole.Instance.Warn("[DataService]: Exeception occured starting data plugin " + plugin.Name + ", " + ex.ToString());
                }
            }
        }
示例#10
0
        public void Initialize(IConfigSource config, IRegistryCore registry, List <Type> types)
        {
            IConfig m_config = config.Configs["UniverseData"];

            if (m_config != null)
            {
                StorageProvider  = m_config.GetString("StorageProvider", StorageProvider);
                ConnectionString = m_config.GetString("ConnectionString", ConnectionString);
            }

            IGenericData DataConnector = null;

            if (StorageProvider == "MySQL")
            //Allow for fallback when UniverseData isn't set
            {
                MySQLDataLoader GenericData = new MySQLDataLoader();

                DataConnector = GenericData;
            }

            /*else if (StorageProvider == "MSSQL2008")
             * {
             * MSSQLDataLoader GenericData = new MSSQLDataLoader();
             *
             * DataConnector = GenericData;
             * }
             * else if (StorageProvider == "MSSQL7")
             * {
             * MSSQLDataLoader GenericData = new MSSQLDataLoader();
             *
             * DataConnector = GenericData;
             * }*/
            else if (StorageProvider == "SQLite")
            //Allow for fallback when UniverseData isn't set
            {
                SQLiteLoader GenericData = new SQLiteLoader();

                // set default data directory in case it is needed
                var simBase = registry.RequestModuleInterface <ISimulationBase> ();
                GenericData.DefaultDataPath = simBase.DefaultDataPath;

                DataConnector = GenericData;
            }

            if (DataConnector != null)      // we have a problem if so...
            {
                foreach (Type t in types)
                {
                    List <dynamic> Plugins = UniverseModuleLoader.PickupModules(t);
                    foreach (dynamic plugin in Plugins)
                    {
                        try
                        {
                            plugin.Initialize(DataConnector.Copy(), config, registry, ConnectionString);
                        } catch (Exception ex)
                        {
                            if (MainConsole.Instance != null)
                            {
                                MainConsole.Instance.Warn("[DataService]: Exception occurred starting data plugin " +
                                                          plugin.Name + ", " + ex);
                            }
                        }
                    }
                }
            }
        }
示例#11
0
        static GKNetDatabase()
        {
#if !NETSTANDARD && !NET461 && !MONO
            SQLiteLoader.Load();
#endif
        }