示例#1
0
        public DefaultSettingsProvider(IBUTRLogger <DefaultSettingsProvider> logger)
        {
            _logger = logger;

            var globalSettingsContainers = (GenericServiceProvider.GetService <IEnumerable <IGlobalSettingsContainer> >() ??
                                            Enumerable.Empty <IGlobalSettingsContainer>()).ToList();
            var perSaveSettingsContainers = (GenericServiceProvider.GetService <IEnumerable <IPerSaveSettingsContainer> >() ??
                                             Enumerable.Empty <IPerSaveSettingsContainer>()).ToList();
            var perCampaignSettingsContainers = (GenericServiceProvider.GetService <IEnumerable <IPerCampaignSettingsContainer> >() ??
                                                 Enumerable.Empty <IPerCampaignSettingsContainer>()).ToList();

            foreach (var globalSettingsContainer in globalSettingsContainers)
            {
                logger.LogInformation("Found Global container {type}.", globalSettingsContainer.GetType());
            }
            foreach (var perSaveSettingsContainer in perSaveSettingsContainers)
            {
                logger.LogInformation("Found PerSave container {type}.", perSaveSettingsContainer.GetType());
            }
            foreach (var perCampaignSettingsContainer in perCampaignSettingsContainers)
            {
                logger.LogInformation("Found Campaign container {type}.", perCampaignSettingsContainer.GetType());
            }

            _settingsContainers = Enumerable.Empty <ISettingsContainer>()
                                  .Concat(globalSettingsContainers)
                                  .Concat(perSaveSettingsContainers)
                                  .ToList();
        }
示例#2
0
        public MCMGlobalSettingsContainer(IBUTRLogger <MCMGlobalSettingsContainer> logger)
        {
            var settings = new List <GlobalSettings>();
            var allTypes = AppDomain.CurrentDomain
                           .GetAssemblies()
                           .Where(a => !a.IsDynamic)
                           .SelectMany(a => a.GetTypes())
                           .Where(t => t.IsClass && !t.IsAbstract)
                           .Where(t => t.GetConstructor(Type.EmptyTypes) is not null)
                           .ToList();

            var mbOptionScreenSettings = allTypes
                                         .Where(t => typeof(GlobalSettings).IsAssignableFrom(t))
                                         .Where(t => !typeof(EmptyGlobalSettings).IsAssignableFrom(t))
                                         .Where(t => !typeof(IWrapper).IsAssignableFrom(t))
                                         .Select(t => Activator.CreateInstance(t) as GlobalSettings)
                                         .Where(t => t is not null)
                                         .Cast <GlobalSettings>();

            settings.AddRange(mbOptionScreenSettings);

            foreach (var setting in settings)
            {
                logger.LogTrace("Registering settings {type}.", setting.GetType());
                RegisterSettings(setting);
            }
        }
 public Json2SettingsFormat(IBUTRLogger <Json2SettingsFormat> logger) : base(logger)
 {
     JsonSerializerSettings = new JsonSerializerSettings
     {
         Formatting = Formatting.Indented,
         Converters = { new DropdownJson2Converter(logger, this) }
     };
 }
示例#4
0
        public static void LogTrace(this IBUTRLogger logger, Exception exception, string message, params object[] args)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            logger.LogMessage(LogLevel.Trace, message, args);
        }
        public MCMGlobalSettingsContainer(IBUTRLogger <MCMGlobalSettingsContainer> logger)
        {
            IEnumerable <GlobalSettings> GetGlobalSettings()
            {
                foreach (var assembly in AccessTools2.AllAssemblies().Where(a => !a.IsDynamic))
                {
                    IEnumerable <GlobalSettings> settings;
                    try
                    {
                        settings = AccessTools2.GetTypesFromAssemblyIfValid(assembly)
                                   .Where(t => t.IsClass && !t.IsAbstract)
                                   .Where(t => t.GetConstructor(Type.EmptyTypes) is not null)
                                   .Where(t => typeof(GlobalSettings).IsAssignableFrom(t))
                                   .Where(t => !typeof(EmptyGlobalSettings).IsAssignableFrom(t))
                                   .Where(t => !typeof(IWrapper).IsAssignableFrom(t))
                                   .Select(t => Activator.CreateInstance(t) as GlobalSettings)
                                   .OfType <GlobalSettings>()
                                   .ToList();
                    }
                    catch (TypeLoadException ex)
                    {
                        settings = Array.Empty <GlobalSettings>();
                        logger.LogError(ex, "Error while handling assembly {Assembly}!", assembly);
                    }

                    foreach (var setting in settings)
                    {
                        yield return(setting);
                    }
                }
            }

            foreach (var setting in GetGlobalSettings())
            {
                logger.LogTrace("Registering settings {type}.", setting.GetType());
                RegisterSettings(setting);
            }
        }
 public DropdownJsonConverter(IBUTRLogger logger, BaseJsonSettingsFormat settingsFormat)
 {
     _logger         = logger;
     _settingsFormat = settingsFormat;
 }
 public XmlSettingsFormat(IBUTRLogger <XmlSettingsFormat> logger) : base(logger)
 {
 }
示例#8
0
 public JsonSettingsFormat(IBUTRLogger <JsonSettingsFormat> logger) : base(logger)
 {
 }
 public MCMPerCampaignSettingsContainer(IBUTRLogger <MCMPerCampaignSettingsContainer> logger)
 {
     _logger    = logger;
     RootFolder = Path.Combine(base.RootFolder, "PerCampaign");
 }
 public MCMPerSaveSettingsContainer(IBUTRLogger <MCMPerSaveSettingsContainer> logger)
 {
     _logger = logger;
 }