Exemple #1
0
 public virtual void LoadDefaultAssets(string pAssetSetsXml)
 {
     _log.Info("[ASSET SERVER]: Setting up asset database");
     _loadingDefaultAssets = true;
     assetLoader.ForEachDefaultXmlAsset(pAssetSetsXml, StoreAsset);
     _loadingDefaultAssets = false;
 }
Exemple #2
0
        public virtual void LoadDefaultAssets(string pAssetSetsXml)
        {
            _log.Info("[ASSET SERVER]: Setting up asset database");
            var signpostMarkerFilename = $"{pAssetSetsXml}.loaded";

            if (File.Exists(signpostMarkerFilename))
            {
                _log.Info("[ASSET SERVER]: Asset database marked as already set up. Not reloading default assets.");
            }
            else
            {
                _loadingDefaultAssets = true;
                assetLoader.ForEachDefaultXmlAsset(pAssetSetsXml, StoreAsset);
                _loadingDefaultAssets = false;
                try
                {
                    File.CreateText(signpostMarkerFilename).Close();
                }
                catch (Exception e)
                {
                    _log.Error($"Unable to create file '{signpostMarkerFilename}' to mark default assets as having been already loaded.", e);
                }
            }
        }
Exemple #3
0
        public FSAssetConnector(IConfigSource config, string configName) : base(config)
        {
            if (!m_Initialized)
            {
                m_Initialized  = true;
                m_MainInstance = true;

                MainConsole.Instance.Commands.AddCommand("fs", false,
                                                         "show assets", "show assets", "Show asset stats",
                                                         HandleShowAssets);
                MainConsole.Instance.Commands.AddCommand("fs", false,
                                                         "show digest", "show digest <ID>", "Show asset digest",
                                                         HandleShowDigest);
                MainConsole.Instance.Commands.AddCommand("fs", false,
                                                         "delete asset", "delete asset <ID>",
                                                         "Delete asset from database",
                                                         HandleDeleteAsset);
                MainConsole.Instance.Commands.AddCommand("fs", false,
                                                         "import", "import <conn> <table> [<start> <count>]",
                                                         "Import legacy assets",
                                                         HandleImportAssets);
                MainConsole.Instance.Commands.AddCommand("fs", false,
                                                         "force import", "force import <conn> <table> [<start> <count>]",
                                                         "Import legacy assets, overwriting current content",
                                                         HandleImportAssets);
            }

            IConfig assetConfig = config.Configs[configName];

            if (assetConfig == null)
            {
                throw new Exception("No AssetService configuration");
            }

            // Get Database Connector from Asset Config (If present)
            string dllName          = assetConfig.GetString("StorageProvider", string.Empty);
            string connectionString = assetConfig.GetString("ConnectionString", string.Empty);
            string realm            = assetConfig.GetString("Realm", "fsassets");

            int SkipAccessTimeDays = assetConfig.GetInt("DaysBetweenAccessTimeUpdates", 0);

            // If not found above, fallback to Database defaults
            IConfig dbConfig = config.Configs["DatabaseService"];

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

                if (connectionString == String.Empty)
                {
                    connectionString = dbConfig.GetString("ConnectionString", String.Empty);
                }
            }

            // No databse connection found in either config
            if (dllName.Equals(String.Empty))
            {
                throw new Exception("No StorageProvider configured");
            }

            if (connectionString.Equals(String.Empty))
            {
                throw new Exception("Missing database connection string");
            }

            // Create Storage Provider
            m_DataConnector = LoadPlugin <IFSAssetDataPlugin>(dllName);

            if (m_DataConnector == null)
            {
                throw new Exception(string.Format("Could not find a storage interface in the module {0}", dllName));
            }

            // Initialize DB And perform any migrations required
            m_DataConnector.Initialise(connectionString, realm, SkipAccessTimeDays);

            // Setup Fallback Service
            string str = assetConfig.GetString("FallbackService", string.Empty);

            if (str != string.Empty)
            {
                object[] args = new object[] { config };
                m_FallbackService = LoadPlugin <IAssetService>(str, args);
                if (m_FallbackService != null)
                {
                    m_log.Info("[FSASSETS]: Fallback service loaded");
                }
                else
                {
                    m_log.Error("[FSASSETS]: Failed to load fallback service");
                }
            }

            // Setup directory structure including temp directory
            m_SpoolDirectory = assetConfig.GetString("SpoolDirectory", "/tmp");

            string spoolTmp = Path.Combine(m_SpoolDirectory, "spool");

            Directory.CreateDirectory(spoolTmp);

            m_FSBase = assetConfig.GetString("BaseDirectory", String.Empty);
            if (m_FSBase == String.Empty)
            {
                m_log.ErrorFormat("[FSASSETS]: BaseDirectory not specified");
                throw new Exception("Configuration error");
            }

            m_useOsgridFormat = assetConfig.GetBoolean("UseOsgridFormat", m_useOsgridFormat);

            if (m_MainInstance)
            {
                string loader = assetConfig.GetString("DefaultAssetLoader", string.Empty);
                if (loader != string.Empty)
                {
                    m_AssetLoader = LoadPlugin <IAssetLoader>(loader);
                    string loaderArgs = assetConfig.GetString("AssetLoaderArgs", string.Empty);
                    m_log.InfoFormat("[FSASSETS]: Loading default asset set from {0}", loaderArgs);
                    m_AssetLoader.ForEachDefaultXmlAsset(loaderArgs,
                                                         delegate(AssetBase a)
                    {
                        Store(a, false);
                    });
                }

                m_WriterThread = new Thread(Writer);
                m_WriterThread.Start();
                m_StatsThread = new Thread(Stats);
                m_StatsThread.Start();
            }

            m_log.Info("[FSASSETS]: FS asset service enabled");
        }
Exemple #4
0
 public void LoadDefaultAssets(string pAssetSetsLocation)
 {
     assetLoader.ForEachDefaultXmlAsset(pAssetSetsLocation, StoreAsset);
 }
        public FSAssetConnector(IConfigSource config, string configName)
            : base(config)
        {
            m_FsckProgram = string.Empty;

            MainConsole.Instance.Commands.AddCommand("fs", false,
                    "show assets", "show assets", "Show asset stats",
                    HandleShowAssets);
            MainConsole.Instance.Commands.AddCommand("fs", false,
                    "show digest", "show digest <ID>", "Show asset digest",
                    HandleShowDigest);
            MainConsole.Instance.Commands.AddCommand("fs", false,
                    "delete asset", "delete asset <ID>",
                    "Delete asset from database",
                    HandleDeleteAsset);
            MainConsole.Instance.Commands.AddCommand("fs", false,
                    "import", "import <conn> <table> [<start> <count>]",
                    "Import legacy assets",
                    HandleImportAssets);
            MainConsole.Instance.Commands.AddCommand("fs", false,
                    "force import", "force import <conn> <table> [<start> <count>]",
                    "Import legacy assets, overwriting current content",
                    HandleImportAssets);

            IConfig assetConfig = config.Configs[configName];
            if (assetConfig == null)
            {
                throw new Exception("No AssetService configuration");
            }

            m_ConnectionString = assetConfig.GetString("ConnectionString", string.Empty);
            if (m_ConnectionString == string.Empty)
            {
                throw new Exception("Missing database connection string");
            }

            m_Realm = assetConfig.GetString("Realm", "fsassets");

            m_DataConnector = new FSAssetConnectorData(m_ConnectionString, m_Realm);
            string str = assetConfig.GetString("FallbackService", string.Empty);
            if (str != string.Empty)
            {
                object[] args = new object[] { config };
                m_FallbackService = LoadPlugin<IAssetService>(str, args);
                if (m_FallbackService != null)
                {
                    m_log.Info("[FALLBACK]: Fallback service loaded");
                }
                else
                {
                    m_log.Error("[FALLBACK]: Failed to load fallback service");
                }
            }

            m_SpoolDirectory = assetConfig.GetString("SpoolDirectory", "/tmp");

            string spoolTmp = Path.Combine(m_SpoolDirectory, "spool");

            Directory.CreateDirectory(spoolTmp);

            m_FSBase = assetConfig.GetString("BaseDirectory", String.Empty);
            if (m_FSBase == String.Empty)
            {
                m_log.ErrorFormat("[ASSET]: BaseDirectory not specified");
                throw new Exception("Configuration error");
            }

            string loader = assetConfig.GetString("DefaultAssetLoader", string.Empty);
            if (loader != string.Empty)
            {
                m_AssetLoader = LoadPlugin<IAssetLoader>(loader);
                string loaderArgs = assetConfig.GetString("AssetLoaderArgs", string.Empty);
                m_log.InfoFormat("[ASSET]: Loading default asset set from {0}", loaderArgs);
                m_AssetLoader.ForEachDefaultXmlAsset(loaderArgs,
                        delegate(AssetBase a)
                        {
                            Store(a, false);
                        });
            }
            m_log.Info("[ASSET]: FS asset service enabled");

            m_WriterThread = new Thread(Writer);
            m_WriterThread.Start();
            m_StatsThread = new Thread(Stats);
            m_StatsThread.Start();
        }