public void LoadConfiguration() { Log.Message("Loading configuration..."); foreach (var svc in serviceList) { string name = GetConfigPath(string.Format("Config.{0}.xml", svc.GetType().Name)); var cfgProp = GameService.GetConfigProperty(svc.GetType()); if (cfgProp == null) { continue; } Log.Message("Loading : {0}", name); Directory.CreateDirectory(Path.GetDirectoryName(name)); try { var cfg = LoadFromXml(cfgProp.PropertyType, name); cfgProp.SetValue(svc, cfg); } catch (Exception ex) { Log.Warning("Failed to load configuration:"); Log.Warning(ex.Message); } } }
public void SaveConfiguration() { Log.Message("Saving configuration..."); foreach (var svc in serviceList) { string name = GetConfigPath(string.Format("Config.{0}.xml", svc.GetType().Name)); var cfgProp = GameService.GetConfigProperty(svc.GetType()); if (cfgProp == null) { continue; } Log.Message("Saving : {0}", name); Directory.CreateDirectory(Path.GetDirectoryName(name)); try { SaveToXml(cfgProp.GetValue(svc), cfgProp.PropertyType, name); } catch (Exception ex) { Log.Error("Failed to save configuration:"); Log.Error(ex.Message); } } }