public void Load(string fileName) { if (!File.Exists(fileName)) { return; } try { // loading database using (var reader = new StreamReader(fileName)) { string content = reader.ReadToEnd(); var rawData = YamlHelper.Deserialize(content, typeof(HolidaysList)); fHolidays = rawData[0] as HolidaysList; } // processing dates for (int i = 0; i < fHolidays.Holidays.Length; i++) { var holiday = fHolidays.Holidays[i]; string sdt = holiday.Date; DateTime dtx; if (DateTime.TryParse(sdt, out dtx)) { holiday.XDate = dtx; } else { holiday.XDate = DateTime.FromBinary(0); } } } catch (Exception ex) { Logger.WriteError("Holidays.Load()", ex); } }
public void Test_Common() { var dtx = new DateTime(2009, 01, 08); var person = new Person() { Name = "test test test", BirthDay = dtx }; string yaml = YamlHelper.Serialize(person); using (var writer = new StreamWriter("test.yaml")) { writer.WriteLine(yaml); } using (var reader = new StreamReader("test.yaml")) { string content = reader.ReadToEnd(); var obj = YamlHelper.Deserialize(content) as Dictionary <object, object>; Assert.IsNotNull(obj); Assert.AreEqual("test test test", obj["Name"]); Assert.AreEqual(dtx, obj["BirthDay"]); var obj2 = YamlHelper.Deserialize(content, typeof(Person)); Assert.IsNotNull(obj2); var p2 = obj2[0] as Person; Assert.IsNotNull(p2); Assert.AreEqual("test test test", p2.Name); Assert.AreEqual(dtx, p2.BirthDay); } }
public void Load(string fileName) { if (!File.Exists(fileName)) { return; } try { // loading database using (var reader = new StreamReader(fileName)) { string content = reader.ReadToEnd(); var rawData = YamlHelper.Deserialize(content, typeof(PathsMappingsList)); fPathsMappings = rawData[0] as PathsMappingsList; } } catch (Exception ex) { Logger.WriteError("PathReplacer.Load()", ex); } }