Ejemplo n.º 1
0
        private void ReadConfigFiles()
        {
            XmlLoader loader = new XmlLoader(this.logger);

            this.meetbotConfig = loader.ParseDefaultConfigFile(this.pluginDir);
            this.meetbotConfig.Validate();

            IList <CommandDefinition> defs = loader.ParseDefaultFile();

            if (string.IsNullOrEmpty(this.meetbotConfig.CommandConfigPath) == false)
            {
                using (FileStream reader = new FileStream(this.meetbotConfig.CommandConfigPath, FileMode.Open, FileAccess.Read))
                {
                    IList <CommandDefinition> userDefs = loader.ParseCommandFile(reader, false);
                    foreach (CommandDefinition userDef in userDefs)
                    {
                        defs.Add(userDef);
                    }
                }
            }

            this.cmdDefs = new CommandDefinitionCollection(defs);

            this.cmdDefs.InitStage1_ValidateDefinitions();
            this.cmdDefs.InitStage2_FilterOutOverrides();
            this.cmdDefs.InitStage3_BuildDictionaries();
        }
Ejemplo n.º 2
0
        public MeetBotConfig ParseConfigFile(Stream stream, string meetbotRoot)
        {
            XDocument doc = XDocument.Load(stream);

            XElement root = doc.Root;

            MeetBotConfig config = new MeetBotConfig(meetbotRoot);

            config.FromXml(root, this.logger);
            return(config);
        }
Ejemplo n.º 3
0
        // ---------------- Functions ----------------

        public static void FromXml(this MeetBotConfig config, XElement configElement, GenericLogger logger = null)
        {
            if (XmlElementName.Equals(configElement.Name.LocalName) == false)
            {
                throw new ArgumentException(
                          $"Invalid XML element name.  Expected: {XmlElementName}, Got: {configElement.Name.LocalName}"
                          );
            }

            foreach (XElement childElement in configElement.Elements())
            {
                if (commandConfigElementName.Equals(childElement.Name.LocalName))
                {
                    config.CommandConfigPath = childElement.Value.Trim();
                }
                else if (enableBackupsElementName.Equals(childElement.Name.LocalName))
                {
                    config.EnableBackups = bool.Parse(childElement.Value.Trim());
                }
                // Parse Generators:
                else if (generatorsElementName.Equals(childElement.Name.LocalName))
                {
                    foreach (XElement generatorElement in childElement.Elements())
                    {
                        if (GeneratorConfigExtensions.XmlElementName.Equals(generatorElement.Name.LocalName))
                        {
                            GeneratorConfig generatorConfig = new GeneratorConfig(config.MeetBotRoot);
                            generatorConfig.FromXml(generatorElement, logger);
                            config.Generators.Add(generatorConfig);
                        }
                        else
                        {
                            logger?.WarningWriteLine(
                                $"Unknown XML element '{generatorElement.Name.LocalName} under '{childElement.Name.LocalName}'"
                                );
                        }
                    }
                }
                else
                {
                    logger?.WarningWriteLine(
                        $"Unknown XML element '{childElement.Name.LocalName} under '{configElement.Name.LocalName}'"
                        );
                }
            }
        }