public string GetHistoryText() { var records = XmlFragmentHelper.ReadLog <Spoken>(HistoryFilePath); var text = string.Join(Environment.NewLine, from r in records select r.Text); return(text); }
static string GetLocalHistoryText() { var filePath = SettingsDirectory.GetDefaultSettingsFilePath("spoken.txt"); var records = XmlFragmentHelper.ReadLog <Spoken>(filePath); var text = string.Join(Environment.NewLine, from r in records select r.Text); return(text); }
public void WriteAndReadLogFile() { var tempPath = Path.GetTempPath(); var targetRootDirectory = Path.Combine(tempPath, Guid.NewGuid().ToString()); var targetPath = Path.Combine(targetRootDirectory, "Testing", Guid.NewGuid().ToString(), "TestLogFile.xml"); try { { var payloads = XmlFragmentHelper.ReadLog <DemoPayload>(targetPath); Assert.AreEqual(0, payloads.Length); } { XmlFragmentHelper.WriteLog(targetPath, new DemoPayload { Text = "First", Number = 101 }); var lines = File.ReadAllLines(targetPath); Assert.AreEqual(1, lines.Length); Assert.AreEqual("<DemoPayload Text=\"First\" Number=\"101\" />", lines[0]); } { XmlFragmentHelper.WriteLog(targetPath, new DemoPayload { Text = "Second", Number = 102 }); var lines = File.ReadAllLines(targetPath); Assert.AreEqual(2, lines.Length); Assert.AreEqual("<DemoPayload Text=\"First\" Number=\"101\" />", lines[0]); Assert.AreEqual("<DemoPayload Text=\"Second\" Number=\"102\" />", lines[1]); } { var payloads = XmlFragmentHelper.ReadLog <DemoPayload>(targetPath); Assert.AreEqual(2, payloads.Length); Assert.AreEqual("First", payloads[0].Text); Assert.AreEqual(101, payloads[0].Number); Assert.AreEqual("Second", payloads[1].Text); Assert.AreEqual(102, payloads[1].Number); } } finally { Directory.Delete(targetRootDirectory, true); } }