public void Write(WritingSystemChangeLog log) { if (log == null) { throw new ArgumentNullException("log"); } if (!File.Exists(FilePath)) { string logDirectory = Path.GetDirectoryName(FilePath); Directory.CreateDirectory(logDirectory); } using (var streamWriter = new StreamWriter(FilePath)) { using (var writer = XmlWriter.Create(streamWriter, CanonicalXmlSettings.CreateXmlWriterSettings())) { writer.WriteStartDocument(); writer.WriteStartElement("WritingSystemChangeLog"); writer.WriteAttributeString("Version", log.Version); writer.WriteStartElement("Changes"); WriteChanges(writer, log); writer.WriteEndElement(); // Changes writer.WriteEndElement(); // WritingSystemChangeLog writer.Close(); } } }
private static void ReadDeleteElement(XmlReader reader, WritingSystemChangeLog log) { AssertOnElement(reader, "Delete"); string producer = reader.GetAttribute("Producer") ?? string.Empty; string producerVersion = reader.GetAttribute("ProducerVersion") ?? string.Empty; string dateTimeString = reader.GetAttribute("TimeStamp") ?? string.Empty; var dateTime = DateTime.Parse(dateTimeString); string id = ""; while (reader.Read() && !(reader.NodeType == XmlNodeType.EndElement && reader.Name == "Delete")) { if (reader.IsStartElement()) { switch (reader.Name) { case "Id": reader.Read(); // get to the text node id = reader.Value; break; } } } log.AddEvent(new WritingSystemLogDeleteEvent(id) { DateTime = dateTime, Producer = producer, ProducerVersion = producerVersion }); }
private static void WriteChanges(XmlWriter writer, WritingSystemChangeLog log) { foreach (var logEvent in log.Events) { WriteLogEvent(writer, logEvent); } }
private static void ReadChangesElement(XmlReader reader, WritingSystemChangeLog log) { AssertOnElement(reader, "Changes"); while (reader.Read() && !(reader.NodeType == XmlNodeType.EndElement && reader.Name == "Changes")) { if (reader.IsStartElement()) { switch (reader.Name) { case "Change": ReadChangeElement(reader, log); break; case "Merge": ReadMergeElement(reader, log); break; case "Add": ReadAddElement(reader, log); break; case "Delete": ReadDeleteElement(reader, log); break; } } } }
public void Read_SampleLogFile_PopulatesChanges() { using (var e = new TestEnvironment()) { var log = new WritingSystemChangeLog(new WritingSystemChangeLogDataMapper(e.GetSampleLogFilePath())); Assert.That(log.HasChangeFor("aaa")); Assert.That(log.GetChangeFor("aaa"), Is.EqualTo("ddd")); } }
private static void ReadLog(XmlReader reader, WritingSystemChangeLog log) { Debug.Assert(reader != null); if (reader.MoveToContent() != XmlNodeType.Element || reader.Name != "WritingSystemChangeLog") { throw new ApplicationException("Unable to load writing system definition: Missing <WritingSystemChangeLog> tag."); } log.Version = reader.GetAttribute("Version") ?? string.Empty; if (FindStartElement(reader, "Changes")) { ReadChangesElement(reader, log); } }
public void Write_NewEmptyFile_WritesModelToLogFile() { using (var e = new TestEnvironment()) { string tempFilePath = Path.Combine(e._tempFolder.Path, "testchangelog.xml"); var log = new WritingSystemChangeLog(new WritingSystemChangeLogDataMapper(tempFilePath)); log.LogChange("aab", "bba"); log.LogAdd("aab"); log.LogDelete("aab"); log.LogConflate("aab","bba"); AssertThatXmlIn.File(tempFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Change/From[text()='aab']"); AssertThatXmlIn.File(tempFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Change/To[text()='bba']"); AssertThatXmlIn.File(tempFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Add/Id[text()='aab']"); AssertThatXmlIn.File(tempFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Delete/Id[text()='aab']"); AssertThatXmlIn.File(tempFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Merge/From[text()='aab']"); AssertThatXmlIn.File(tempFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Merge/To[text()='bba']"); } }
public void Read(WritingSystemChangeLog log) { if (File.Exists(FilePath)) { try { using (StreamReader streamReader = File.OpenText(FilePath)) { using (XmlReader reader = XmlReader.Create(streamReader, _xmlReadSettings)) { ReadLog(reader, log); } } }catch (FormatException e) //This exception is thrown when the time format is locale specific. This was the case for a very short time when the log was introduced. (WS-34444) { File.Delete(FilePath); } } }
public void Read(WritingSystemChangeLog log) { if (File.Exists(FilePath)) { try { using (StreamReader streamReader = File.OpenText(FilePath)) { using (XmlReader reader = XmlReader.Create(streamReader, _xmlReadSettings)) { ReadLog(reader, log); } } }catch(FormatException e) //This exception is thrown when the time format is locale specific. This was the case for a very short time when the log was introduced. (WS-34444) { File.Delete(FilePath); } } }
public void Write(WritingSystemChangeLog log) {}
/// <summary> /// use a special path for the repository /// </summary> /// <param name="basePath"></param> /// <param name="compatibilityMode"></param> protected internal LdmlInFolderWritingSystemRepository(string basePath, WritingSystemCompatibility compatibilityMode) : base(compatibilityMode) { PathToWritingSystems = basePath; _changeLog = new WritingSystemChangeLog(new WritingSystemChangeLogDataMapper(Path.Combine(PathToWritingSystems, "idchangelog.xml"))); }
public void Write(WritingSystemChangeLog log) { }
public void Read(WritingSystemChangeLog log) { }
public void Read(WritingSystemChangeLog log) {}
public WritingSystemChangeLog GetSampleWritingSystemChangeLog() { var log = new WritingSystemChangeLog(); log.LogChange("aab", "bba"); log.LogChange("ccc", "ddd"); return log; }