public void Load(IIndexer indexer)
        {
            var configFilePath = GetIndexerConfigFilePath(indexer.Id);

            if (!File.Exists(configFilePath))
            {
                return;
            }
            try
            {
                var fileStr    = File.ReadAllText(configFilePath);
                var jsonString = JToken.Parse(fileStr);
                indexer.LoadFromSavedConfiguration(jsonString);
            }
            catch (Exception e)
            {
                logger.Error($"Failed loading configuration for {indexer.DisplayName}, trying backup\n{e}");
                var configFilePathBak = configFilePath + ".bak";
                if (File.Exists(configFilePathBak))
                {
                    try
                    {
                        var fileStrBak    = File.ReadAllText(configFilePathBak);
                        var jsonStringBak = JToken.Parse(fileStrBak);
                        indexer.LoadFromSavedConfiguration(jsonStringBak);
                        logger.Info($"Successfully loaded backup config for {indexer.DisplayName}");
                        indexer.SaveConfig();
                    }
                    catch (Exception e2)
                    {
                        logger.Error($"Failed loading backup configuration for {indexer.DisplayName}, you must reconfigure this indexer\n{e2}");
                    }
                }
                else
                {
                    logger.Error($"Failed loading backup configuration for {indexer.DisplayName} (no backup available), you must reconfigure this indexer\n{e}");
                }
            }
        }
Beispiel #2
0
        protected void LoadIndexerConfig(IIndexer idx)
        {
            var configFilePath = GetIndexerConfigFilePath(idx);

            if (File.Exists(configFilePath))
            {
                try
                {
                    var fileStr    = File.ReadAllText(configFilePath);
                    var jsonString = JToken.Parse(fileStr);
                    idx.LoadFromSavedConfiguration(jsonString);
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Failed loading configuration for {0}, trying backup", idx.DisplayName);
                    var configFilePathBak = configFilePath + ".bak";
                    if (File.Exists(configFilePathBak))
                    {
                        try
                        {
                            var fileStrBak    = File.ReadAllText(configFilePathBak);
                            var jsonStringBak = JToken.Parse(fileStrBak);
                            idx.LoadFromSavedConfiguration(jsonStringBak);
                            logger.Info("Successfully loaded backup config for {0}", idx.DisplayName);
                            idx.SaveConfig();
                        }
                        catch (Exception exbak)
                        {
                            logger.Error(exbak, "Failed loading backup configuration for {0}, you must reconfigure this indexer", idx.DisplayName);
                        }
                    }
                    else
                    {
                        logger.Error(ex, "Failed loading backup configuration for {0} (no backup available), you must reconfigure this indexer", idx.DisplayName);
                    }
                }
            }
        }