public async Task <string> GetAsync(ConfigurationsKeyEnum configElementName, bool readFromSensitiveConfig = false) { try { var fileName = (readFromSensitiveConfig) ? "config-sensitive.xml" : "config.xml"; var type = this.GetType(); var resource = type.Namespace + ".Config." + fileName; using (var stream = type.Assembly.GetManifestResourceStream(resource)) { if (stream == null) { throw new Exception("ConfigFetcher Error - Verifique el NameSpace"); } using (var reader = new StreamReader(stream)) { var xmlDocument = new XmlDocument(); xmlDocument.LoadXml(await reader.ReadToEndAsync()); if (xmlDocument.GetElementsByTagName(configElementName.ToString())[0] == null) { throw new Exception("ConfigFetcher Error - No se encuentra la configuración solicitada"); } return(xmlDocument.GetElementsByTagName(configElementName.ToString())[0].InnerText); } } } catch (Exception ex) { throw new Exception("Error al parsear el Json de configuraci¨®n al formato esperado"); } }
public async Task <string> GetAsync(ConfigurationsKeyEnum configElementName, bool readFromSensitiveConfig = false) { var fileName = (readFromSensitiveConfig) ? "config-sensitive.xml" : "config.xml"; var type = this.GetType(); var resource = type.Namespace + ".Config." + fileName; using (var stream = type.Assembly.GetManifestResourceStream(resource)) { if (stream == null) { throw new Exception("ConfigFetcher Error - Verifique el NameSpace"); } using (var reader = new StreamReader(stream)) { //var doc = XDocument.Parse(await reader.ReadToEndAsync()); //if (doc.Element("config").Element(configElementName.ToString()) == null) // throw new Exception("ConfigFetcher Error - No se encuentra la configuración solicitada"); //return doc.Element("config").Element(configElementName.ToString())?.Value; return(""); } } }