public static void WorldAlive() { Brain.MakeConscious(); }
private static void ConfigureSystem() { var xmlDoc = new XmlDocument(); try { //todo: Load defaults, then merge in settings from Config/system.xml and persistent data xmlDoc.Load(File.Exists($"{ConfigPath}{SystemFile}") ? $"{ConfigPath}{SystemFile}" : $"{DefaultConfigPath}{SystemFile}"); //Heartbeat.IsAlive var isAlive = xmlDoc.SelectNodes("/System/Heartbeat/@isalive"); if (isAlive == null || isAlive.Count == 0) { Log.Out($"{ModPrefix} Unable to load Heartbeat IsAlive, setting not found in {SystemFile}"); } else { if (!bool.TryParse(isAlive.Item(0)?.Value, out Heartbeat.IsAlive)) { Log.Out($"{ModPrefix} Unable to load Heartbeat, isalive is not a valid boolean in {SystemFile}"); } } //Heartbeat.BPM var bpm = xmlDoc.SelectNodes("/System/Heartbeat/@bpmrate"); if (bpm == null || bpm.Count <= 0) { Log.Out($"{ModPrefix} Unable to load Heartbeat BPM rate, setting not found in {SystemFile}"); } else { if (!int.TryParse(bpm.Item(0)?.Value, out Heartbeat.Bpm)) { Log.Out($"{ModPrefix} Unable to load BPM, \'rate\' is not a valid int in {SystemFile}"); } } //Synapses var synapseNodes = xmlDoc.SelectNodes("/System/Synapse"); if (synapseNodes == null || synapseNodes.Count == 0) { Log.Out($"{ModPrefix} Unable to load Synapses, settings not found in {SystemFile}"); } else { var count = 0; foreach (XmlElement node in synapseNodes) { count++; var synapse = new Synapse(); if (!node.HasAttribute("name")) { Log.Out($"{ModPrefix} Skipping Synapse element #{count}, missing \'name\' attribute in {SystemFile}"); continue; } synapse.Name = node.GetAttribute("name"); if (!node.HasAttribute("enabled")) { Log.Out($"{ModPrefix} Skipping Synapse element #{count}, missing \'enabled\' attribute in {SystemFile}"); continue; } if (!bool.TryParse(node.GetAttribute("enabled"), out synapse.IsEnabled)) { Log.Out($"{ModPrefix} Unable to load Synapse \'enabled\' in element #{count}, value is not a valid boolean in {SystemFile}"); } if (node.HasAttribute("beats") && !int.TryParse(node.GetAttribute("beats"), out synapse.Beats)) { Log.Out($"{ModPrefix} Unable to load Synapse \'beats\' in element #{count}, value not a valid int in {SystemFile}"); continue; } if (node.HasAttribute("options")) { synapse.Options = node.GetAttribute("options"); } if (node.HasAttribute("config")) { synapse.Cfg = node.GetAttribute("config"); } synapse.WireNeurons(); Brain.BondSynapse(synapse); } } } catch (Exception e) { Log.Error($"{ModPrefix} Error configuring tasks\n{e}"); } }
public static bool ConfigureSystem() { XmlDocument _xd = new XmlDocument(); try { _xd.Load(ConfigPath + systemFile); //LogCache.enabled XmlNodeList _lc = _xd.SelectNodes("/System/LogCache/@enabled"); if (_lc.Count > 0) { if (!bool.TryParse(_lc.Item(0).Value, out logCache)) { Log.Out("" + ModPrefix + " Unable to load LogCache, enabled is not a valid boolean in " + systemFile); } } else { Log.Out("" + ModPrefix + " Unable to load LogCache enabled, setting not found in " + systemFile); } //Heartbeat.IsAlive XmlNodeList _hb = _xd.SelectNodes("/System/Heartbeat/@isalive"); if (_hb.Count > 0) { if (!bool.TryParse(_hb.Item(0).Value, out Heartbeat.IsAlive)) { Log.Out("" + ModPrefix + " Unable to load Heartbeat, isalive is not a valid boolean in " + systemFile); } } else { Log.Out("" + ModPrefix + " Unable to load Heartbeat IsAlive, setting not found in " + systemFile); } //Heartbeat.BPM XmlNodeList _bpm = _xd.SelectNodes("/System/BPM/@rate"); if (_bpm.Count > 0) { if (!int.TryParse(_bpm.Item(0).Value, out Heartbeat.BPM)) { Log.Out("" + ModPrefix + " Unable to load BPM, 'rate' is not a valid int in " + systemFile); } } else { Log.Out("" + ModPrefix + " Unable to load BPM, setting not found in " + systemFile); } //Synapses XmlNodeList _synapses = _xd.SelectNodes("/System/Synapse"); if (_synapses.Count > 0) { int count = 0; foreach (XmlElement _s in _synapses) { count++; Synapse _synapse = new Synapse(); if (!_s.HasAttribute("name")) { Log.Out("" + ModPrefix + " Skipping Synapse element #" + count + ", missing 'name' attribute in " + systemFile); continue; } else { _synapse.name = _s.GetAttribute("name"); } if (!_s.HasAttribute("enabled")) { Log.Out("" + ModPrefix + " Skipping Synapse element #" + count + ", missing 'enabled' attribute in " + systemFile); continue; } else { if (!bool.TryParse(_s.GetAttribute("enabled"), out _synapse.IsEnabled)) { Log.Out("" + ModPrefix + " Unable to load Synapse 'enabled' in element #" + count + ", value is not a valid boolean in " + systemFile); } } if (!_s.HasAttribute("beats")) { Log.Out("" + ModPrefix + " Skipping Synapse element #" + count + ", missing 'beats' attribute in " + systemFile); continue; } else { if (!int.TryParse(_s.GetAttribute("beats"), out _synapse.beats)) { Log.Out("" + ModPrefix + " Unable to load Synapse 'beats' in element #" + count + ", value not a valid int in " + systemFile); } } _synapse.WireNeurons(); Brain.BondSynapse(_synapse); } } else { Log.Out("" + ModPrefix + " Unable to load Synapses, settings not found in " + systemFile); } } catch (Exception e) { Log.Error("" + ModPrefix + " Error configuring tasks\n" + e); return(false); } return(true); }
public static bool ConfigureSystem() { var xmlDoc = new XmlDocument(); try { if (File.Exists(ConfigPath + SystemFile)) { xmlDoc.Load(ConfigPath + SystemFile); } else { xmlDoc.Load(DefaultConfigPath + SystemFile); } //LogCache.enabled var logNodes = xmlDoc.SelectNodes("/System/LogCache/@enabled"); if (logNodes == null || logNodes.Count == 0) { Log.Out(ModPrefix + " Unable to load LogCache enabled, setting not found in " + SystemFile); } else { if (!bool.TryParse(logNodes.Item(0)?.Value, out LogCache)) { Log.Out(ModPrefix + " Unable to load LogCache, enabled is not a valid boolean in " + SystemFile); } } //Heartbeat.IsAlive var isAlive = xmlDoc.SelectNodes("/System/Heartbeat/@isalive"); if (isAlive == null || isAlive.Count == 0) { Log.Out(ModPrefix + " Unable to load Heartbeat IsAlive, setting not found in " + SystemFile); } else { if (!bool.TryParse(isAlive.Item(0)?.Value, out Heartbeat.IsAlive)) { Log.Out(ModPrefix + " Unable to load Heartbeat, isalive is not a valid boolean in " + SystemFile); } } //Heartbeat.BPM var bpm = xmlDoc.SelectNodes("/System/BPM/@rate"); if (bpm == null || bpm.Count <= 0) { Log.Out(ModPrefix + " Unable to load BPM, setting not found in " + SystemFile); } else { if (!int.TryParse(bpm.Item(0)?.Value, out Heartbeat.Bpm)) { Log.Out(ModPrefix + " Unable to load BPM, 'rate' is not a valid int in " + SystemFile); } } //Synapses var synapseNodes = xmlDoc.SelectNodes("/System/Synapse"); if (synapseNodes == null || synapseNodes.Count == 0) { Log.Out(ModPrefix + " Unable to load Synapses, settings not found in " + SystemFile); } else { var count = 0; foreach (XmlElement node in synapseNodes) { count++; var synapse = new Synapse(); if (!node.HasAttribute("name")) { Log.Out(ModPrefix + " Skipping Synapse element #" + count + ", missing 'name' attribute in " + SystemFile); continue; } synapse.Name = node.GetAttribute("name"); if (!node.HasAttribute("enabled")) { Log.Out(ModPrefix + " Skipping Synapse element #" + count + ", missing 'enabled' attribute in " + SystemFile); continue; } if (!bool.TryParse(node.GetAttribute("enabled"), out synapse.IsEnabled)) { Log.Out(ModPrefix + " Unable to load Synapse 'enabled' in element #" + count + ", value is not a valid boolean in " + SystemFile); } if (!node.HasAttribute("beats")) { Log.Out(ModPrefix + " Skipping Synapse element #" + count + ", missing 'beats' attribute in " + SystemFile); continue; } if (!int.TryParse(node.GetAttribute("beats"), out synapse.Beats)) { Log.Out(ModPrefix + " Unable to load Synapse 'beats' in element #" + count + ", value not a valid int in " + SystemFile); continue; } if (node.HasAttribute("options")) { synapse.Options = node.GetAttribute("options"); } synapse.WireNeurons(); Brain.BondSynapse(synapse); } } } catch (Exception e) { Log.Error(ModPrefix + " Error configuring tasks\n" + e); return(false); } return(true); }