public static DataCollectionRunSettings GetInProcDataCollectionRunSettings(string runSettingsXml) { // use XmlReader to avoid loading of the plugins in client code (mainly from VS). if (!string.IsNullOrWhiteSpace(runSettingsXml)) { runSettingsXml = runSettingsXml.Trim(); using (StringReader stringReader1 = new StringReader(runSettingsXml)) { XmlReader reader = XmlReader.Create(stringReader1, ReaderSettings); // read to the fist child XmlReaderUtilities.ReadToRootNode(reader); reader.ReadToNextElement(); // Read till we reach In Proc IDC element or reach EOF while (!string.Equals(reader.Name, Constants.InProcDataCollectionRunSettingsName) && !reader.EOF) { reader.SkipToNextElement(); } // If reached EOF => IDC element not there if (reader.EOF) { return(null); } // Reached here => In Proc IDC element present. return(DataCollectionRunSettings.FromXml(reader, Constants.InProcDataCollectionRunSettingsName, Constants.InProcDataCollectorsSettingName, Constants.InProcDataCollectorSettingName)); } } return(null); }
private static T GetNodeValue <T>(string settingsXml, string nodeName, Func <XmlReader, T> nodeParser) { // use XmlReader to avoid loading of the plugins in client code (mainly from VS). if (!string.IsNullOrWhiteSpace(settingsXml)) { using (var stringReader = new StringReader(settingsXml)) { XmlReader reader = XmlReader.Create(stringReader, ReaderSettings); // read to the fist child XmlReaderUtilities.ReadToRootNode(reader); reader.ReadToNextElement(); // Read till we reach nodeName element or reach EOF while (!string.Equals(reader.Name, nodeName, StringComparison.OrdinalIgnoreCase) && !reader.EOF) { reader.SkipToNextElement(); } if (!reader.EOF) { // read nodeName element. return(nodeParser(reader)); } } } return(default(T)); }
public static DataCollectionRunSettings GetDataCollectionRunSettings(string runSettingsXml) { // use XmlReader to avoid loading of the plugins in client code (mainly from VS). if (string.IsNullOrWhiteSpace(runSettingsXml)) { return(null); } try { using (var stringReader = new StringReader(runSettingsXml)) { var reader = XmlReader.Create(stringReader, ReaderSettings); // read to the fist child XmlReaderUtilities.ReadToRootNode(reader); reader.ReadToNextElement(); // Read till we reach DC element or reach EOF while (!string.Equals(reader.Name, Constants.DataCollectionRunSettingsName) && !reader.EOF) { reader.SkipToNextElement(); } // If reached EOF => DC element not there if (reader.EOF) { return(null); } // Reached here => DC element present. return(DataCollectionRunSettings.FromXml(reader)); } } catch (XmlException ex) { throw new SettingsException( string.Format(CultureInfo.CurrentCulture, "{0} {1}", Resources.CommonResources.MalformedRunSettingsFile, ex.Message), ex); } }
private static T GetNodeValue <T>(string settingsXml, string nodeName, Func <XmlReader, T> nodeParser) { // use XmlReader to avoid loading of the plugins in client code (mainly from VS). if (!string.IsNullOrWhiteSpace(settingsXml)) { try { using (var stringReader = new StringReader(settingsXml)) { XmlReader reader = XmlReader.Create(stringReader, ReaderSettings); // read to the fist child XmlReaderUtilities.ReadToRootNode(reader); reader.ReadToNextElement(); // Read till we reach nodeName element or reach EOF while (!string.Equals(reader.Name, nodeName, StringComparison.OrdinalIgnoreCase) && !reader.EOF) { reader.SkipToNextElement(); } if (!reader.EOF) { // read nodeName element. return(nodeParser(reader)); } } } catch (XmlException ex) { throw new SettingsException( string.Format(CultureInfo.CurrentCulture, "{0} {1}", Resources.CommonResources.MalformedRunSettingsFile, ex.Message), ex); } } return(default(T)); }