/// <summary> /// Returns the Policy for the given nessus report file (*.nessus). /// </summary> /// <param name="path">Path to the nessus report file to parse.</param> /// <returns>Policy; null if an error occurred.</returns> public static Policy Parse(string path) { Policy policy = null; XmlSerializer serializer = new XmlSerializer(typeof(NessusClientData_v2)); TextReader reader = null; try { reader = new StreamReader(File.OpenRead(path)); NessusClientData_v2 data = (NessusClientData_v2)serializer.Deserialize(reader); policy = data.Policy; } catch (Exception e) { Console.WriteLine("Error: Could not parse (NESSUS?) file {0}: {1} {2}", path, e.GetType(), e.Message); } finally { if (reader != null) { reader.Close(); } } return(policy); }
/// <summary> /// Saves the NessusClientData_v2 object (a NESSUS report file) to a file at the given /// path. /// </summary> /// <param name="path">Path to save the report to.</param> /// <returns>bool; whether or not we are successful at the save.</returns> public static bool Save(NessusClientData_v2 data, string path) { XmlSerializer serializer = new XmlSerializer(typeof(NessusClientData_v2)); TextWriter writer = null; bool ok = false; try { writer = new StreamWriter(path); serializer.Serialize(writer, data); ok = true; } catch (Exception e) { Console.WriteLine("Error: Could not write NESSUS/XML file {0}: {1} {2}", path, e.GetType(), e.Message); } finally { if (writer != null) { writer.Close(); } } return(ok); }