コード例 #1
0
        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();
                }
            }
        }
コード例 #2
0
        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
            });
        }
コード例 #3
0
 private static void WriteChanges(XmlWriter writer, WritingSystemChangeLog log)
 {
     foreach (var logEvent in log.Events)
     {
         WriteLogEvent(writer, logEvent);
     }
 }
コード例 #4
0
        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;
                    }
                }
            }
        }
コード例 #5
0
		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"));
			}
		}
コード例 #6
0
		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);
			}
		}
コード例 #7
0
        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);
            }
        }
コード例 #8
0
		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']");
			}
		}
コード例 #9
0
 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);
         }
     }
 }
コード例 #10
0
		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);
				}
			}
		}
コード例 #11
0
		private static void WriteChanges(XmlWriter writer, WritingSystemChangeLog log)
		{
			foreach (var logEvent in log.Events)
			{
				WriteLogEvent(writer, logEvent);
			}
		}
コード例 #12
0
		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();
				}
			}
		}
コード例 #13
0
		public void Write(WritingSystemChangeLog log) {}
コード例 #14
0
 /// <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")));
 }
コード例 #15
0
 public void Write(WritingSystemChangeLog log)
 {
 }
コード例 #16
0
 public void Read(WritingSystemChangeLog log)
 {
 }
コード例 #17
0
		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;
					}
				}
			}
		}
コード例 #18
0
		public void Read(WritingSystemChangeLog log) {}
コード例 #19
0
			public WritingSystemChangeLog GetSampleWritingSystemChangeLog()
			{
				var log = new WritingSystemChangeLog();
				log.LogChange("aab", "bba");
				log.LogChange("ccc", "ddd");
				return log;
			}
コード例 #20
0
		/// <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")));
		}
コード例 #21
0
		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 });
		}