Exemple #1
0
        public BaseModuleSettings GetSettingsFor(BaseModule baseModule)
        {
            var typeObj = baseModule.GetSettingsType();

            if (typeObj == null)
            {
                return(null);
            }

            BaseModuleSettings typeInstance;

            try {
                var type = (TypeInfo)typeObj;
                typeInstance = (BaseModuleSettings)Activator.CreateInstance(type, baseModule);
                typeInstance.ApplyModule(baseModule);
            } catch (Exception e) {
                Logger.Error($"Unable to load settings for module {baseModule.GetName()} [id={baseModule.GetLogIdentifer()}], can not create instance of settings class '{typeObj}", e);
                return(null);
            }

            var result = SettingsManager.LoadFromDisk(ref typeInstance);

            if (result.HasNoErrors())
            {
                typeInstance.GenerateDefault();
                return(typeInstance);
            }

            Logger.Error(
                $"Unable to load settings for module {baseModule.GetName()} [id={baseModule.GetLogIdentifer()}]",
                result.Error == null ? new Exception(result.ErrorMessage) : result.Error);

            return(null);
        }
Exemple #2
0
        private SettingsIoResult?SaveSettingsForInternal(BaseModule baseModule, BaseModuleSettings settings, bool overrideDef = false)
        {
            if (baseModule == null)
            {
                Logger.Error("Trying to save settings for module that are null");
                return(null);
            }

            if (overrideDef)
            {
                baseModule.SettingsInstance = settings;
            }

            var result = SettingsManager.UpdateOrCreate(baseModule.SettingsInstance);

            if (result.HasNoErrors())
            {
                return(result);
            }

            Logger.Error(
                $"Unable to save settings for module {baseModule.GetName()} [id={baseModule.GetLogIdentifer()}]",
                result.Error == null ? new Exception(result.ErrorMessage) : result.Error);

            return(result);
        }