static public bool SetupConfigSystem(string configFilePath) { ModManager.ApplicationExit += ModManagerApplicationExit; LoggingManager.SendMessage("ConfigManager - Setting up config system..."); if (!File.Exists(configFilePath)) { LoggingManager.SendMessage("ConfingManager - No plugins.config found, creating one from scratch"); } s_sConfigFilePath = configFilePath; FileStream config = null; try { config = File.Open(configFilePath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read); s_pluginsConfig = XmlConfigReader.Read(config); } catch (Exception e) { LoggingManager.SendMessage("ConfigManager - Failed to set up config system from file: " + configFilePath); LoggingManager.HandleException(e); return(false); } finally { if (config != null) { config.Close(); } } LoggingManager.SendMessage("ConfigManager - Config system set up successfully!"); return(true); }
public void Read_NoDevice() { var xmlConfigReader = new XmlConfigReader("_TestData\\config_no_device.xml"); var settings = xmlConfigReader.Read(); Assert.Empty(settings); }
public void Read_DeviceWithoutMapping() { var xmlConfigReader = new XmlConfigReader("_TestData\\config_device_without_mapping.xml"); var settings = xmlConfigReader.Read(); Assert.Single(settings); Assert.Equal("Dings", settings.First().Name); Assert.Empty(settings.First().Mapping); }
public void Read_OneDevice() { var xmlConfigReader = new XmlConfigReader("_TestData\\config_one_device.xml"); var settings = xmlConfigReader.Read(); Assert.Single(settings); Assert.Equal("Dings", settings.First().Name); Assert.Equal(2, settings.First().Mapping.Count); Assert.Contains(new KeyValuePair <int, int>(1, 111), settings.First().Mapping); Assert.Contains(new KeyValuePair <int, int>(2, 222), settings.First().Mapping); }
public void Read_OneDevice() { var xmlConfigReader = new XmlConfigReader("_TestData\\config_one_device.xml"); var settings = xmlConfigReader.Read(); var device = settings.FirstOrDefault(); Assert.Single(settings); Assert.Equal("Sam", device.Name); Assert.Equal(4, device.Pins.Count()); Assert.Contains(new Pin(1, 6, "Relay + LED", PinLogic.Negative), device.Pins); Assert.Contains(new Pin(2, 8, "Relay + LED", PinLogic.Positive), device.Pins); Assert.Contains(new Pin(3, 10, "Relay + LED", PinLogic.Positive), device.Pins); Assert.Contains(new Pin(4, 12, "Relay + LED", PinLogic.Positive), device.Pins); }
public IEnumerable <IController> Create() { string currentAssemblyFilePath = new Uri(typeof(XmlConfigReader).Assembly.CodeBase).LocalPath; string currentAssemblyDirectoryPath = Path.GetDirectoryName(currentAssemblyFilePath); string schemaFilePath = currentAssemblyDirectoryPath + "\\config.xsd"; string configFilePath = currentAssemblyDirectoryPath + "\\config.xml"; var validator = new XmlSchemaValidator(schemaFilePath, configFilePath); bool isValid = validator.Validate(); if (!isValid) { throw new ConfigurationErrorsException("Serial controller configuration is not valid."); } else { var xmlConfigReader = new XmlConfigReader(configFilePath); var devices = xmlConfigReader.Read(); return(devices.Select(x => new SerialController(x)).ToList()); } }
public IEnumerable <IController> Create() { string directoryPath = getCurrentDirectoryPath(); string schemaFilePath = directoryPath + "\\config.xsd"; string configFilePath = directoryPath + "\\config.xml"; var xmlSchemaValidator = new XmlSchemaValidator(schemaFilePath, configFilePath); bool isValid = xmlSchemaValidator.Validate(out string message); if (!isValid) { throw new ConfigurationErrorsException("Arduino controller configuration is not valid."); } var xmlConfigReader = new XmlConfigReader(configFilePath); var config = xmlConfigReader.Read(); return(config.Select(x => { var majoro = findConnection(x.Name); return new ArduinoController(majoro, x); })); }