public ConfigObj readConfig() { ConfigObj config = new ConfigObj(); try { StringBuilder output = new StringBuilder(); String xmlString = getTextFromFile(getConfPath(Constants.CONF_PATH)); if (xmlString != null) { config = parseConfig(xmlString); } } catch (Exception e) { throw e; } return config; }
public void writeConfig(ConfigObj config, String configPath) { StringBuilder sb = null; try { sb = new StringBuilder(); sb.Append("<?xml version='1.0' encoding='UTF-8' standalone='yes'?>\n"); sb.Append(" <openaudit>\n"); sb.Append(" <config strId='"+config.strId+"' remoteServer='"+config.remoteServer+"' remoteTarget='"+config.remoteTarget+"' version='"+config.version+"' uploadUrl='"+config.uploadUrl+"' downloadUrl='"+config.downloadUrl+"' >\n"); sb.Append(" </config>\n"); sb.Append(" </openaudit>\n"); if (File.Exists(configPath)) File.Delete(configPath); using (StreamWriter outfile = new StreamWriter(configPath)) { outfile.Write(sb.ToString()); outfile.Close(); } } catch (Exception e) { throw e; } finally { if (sb != null) sb = null; } }
public ConfigObj parseConfig(String configXml) { ConfigObj config = new ConfigObj(); try { using (XmlReader reader = XmlReader.Create(new StringReader(configXml))) { reader.ReadToFollowing("config"); config.strId = reader.GetAttribute("strId"); config.remoteServer = reader.GetAttribute("remoteServer"); config.remoteTarget = reader.GetAttribute("remoteTarget"); config.downloadUrl = reader.GetAttribute("downloadUrl"); config.uploadUrl = reader.GetAttribute("uploadUrl"); config.version = reader.GetAttribute("version"); } } catch (Exception e) { throw e; } return config; }