public static string Save() { YamlMapping Map = new YamlMapping(); YamlSerializer Serializer = new YamlSerializer(); ForeachSetting((F, A) => { // HAX Map.Add(F.Name, YamlNode.FromYaml(Serializer.Serialize(F.GetValue(null)))[0]); }); return Map.ToYaml(); }
private bool Save(FATabStripItem tab) { var tb = (tab.Controls[0] as RegexTesterTab); YamlNode pnode = new YamlMapping( "regex", new YamlScalar(tb.RegexText.Text), "text", new YamlScalar(tb.TesterText.Text) ); if (tab.Tag == null) { if (sfdMain.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return(false); } tab.Title = Path.GetFileName(sfdMain.FileName); tab.Tag = sfdMain.FileName; if (!RecentFiles.Contains(sfdMain.FileName)) { RecentFiles.Add(sfdMain.FileName); } } try { File.WriteAllText(tab.Tag as string, pnode.ToYaml()); tb.RegexText.IsChanged = false; tb.TesterText.IsChanged = false; } catch (Exception ex) { if (MessageBox.Show(ex.Message, "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry) { return(Save(tab)); } else { return(false); } } tb.Invalidate(); return(true); }
public void MergeKey() { var map = new YamlMapping("existing", "value"); var mergeKey = new YamlScalar("!!merge", "<<"); map.Add(mergeKey, new YamlMapping("existing", "new value")); map.OnLoaded(); Assert.AreEqual(1, map.Count); Assert.IsTrue(map.ContainsKey("existing")); Assert.AreEqual((YamlNode)"value", map["existing"]); map.Add(mergeKey, new YamlMapping("not existing", "new value")); map.OnLoaded(); Assert.AreEqual(2, map.Count); Assert.IsTrue(map.ContainsKey("existing")); Assert.AreEqual((YamlNode)"value", map["existing"]); Assert.IsTrue(map.ContainsKey("not existing")); Assert.AreEqual((YamlNode)"new value", map["not existing"]); map.Add(mergeKey, new YamlMapping("key1", "value1", 2, 2, 3.0, 3.0)); map.OnLoaded(); Assert.AreEqual(5, map.Count); Assert.IsTrue(map.ContainsKey("existing")); Assert.AreEqual((YamlNode)"value", map["existing"]); Assert.IsTrue(map.ContainsKey("not existing")); Assert.AreEqual((YamlNode)"new value", map["not existing"]); Assert.IsTrue(map.ContainsKey(2)); Assert.AreEqual((YamlNode)2, map[2]); Assert.IsTrue(map.ContainsKey(3.0)); Assert.AreEqual((YamlNode)3.0, map[3.0]); map = new YamlMapping( "existing", "value", mergeKey, new YamlMapping("not existing", "new value")); map.OnLoaded(); Assert.AreEqual(2, map.Count); Assert.IsTrue(map.ContainsKey("existing")); Assert.AreEqual((YamlNode)"value", map["existing"]); Assert.IsTrue(map.ContainsKey("not existing")); Assert.AreEqual((YamlNode)"new value", map["not existing"]); map = (YamlMapping)YamlNode.FromYaml( "key1: value1\r\n" + "key2: value2\r\n" + "<<: \r\n" + " key2: value2 modified\r\n" + " key3: value3\r\n" + " <<: \r\n" + " key4: value4\r\n" + " <<: value5\r\n" + "key6: <<\r\n")[0]; Assert.AreEqual( "%YAML 1.2\r\n" + "---\r\n" + "<<: value5\r\n" + "key6: <<\r\n" + "key3: value3\r\n" + "key2: value2\r\n" + "key4: value4\r\n" + "key1: value1\r\n" + "...\r\n", map.ToYaml() ); Assert.IsTrue(map.ContainsKey(mergeKey)); Assert.AreEqual(mergeKey, map["key6"]); map.Remove(mergeKey); map.Add(mergeKey, map); // recursive map.OnLoaded(); Assert.AreEqual( // nothing has been changed "%YAML 1.2\r\n" + "---\r\n" + "key6: <<\r\n" + "key3: value3\r\n" + "key2: value2\r\n" + "key4: value4\r\n" + "key1: value1\r\n" + "...\r\n", map.ToYaml() ); }
public void Example2_27_YAML1_2() { var invoice = new YamlMapping( "invoice", 34843, "date", new DateTime(2001, 01, 23), "bill-to", new YamlMapping( "given", "Chris", "family", "Dumars", "address", new YamlMapping( "lines", "458 Walkman Dr.\nSuite #292\n", "city", "Royal Oak", "state", "MI", "postal", 48046 ) ), "product", new YamlSequence( new YamlMapping( "sku", "BL394D", "quantity", 4, "description", "Basketball", "price", 450.00 ), new YamlMapping( "sku", "BL4438H", "quantity", 1, "description", "Super Hoop", "price", 2392.00 ) ), "tax", 251.42, "total", 4443.52, "comments", "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338." ); invoice["ship-to"] = invoice["bill-to"]; invoice.Tag = "tag:clarkevans.com,2002:invoice"; var yaml = invoice.ToYaml(); Assert.AreEqual( MultiLineText( @"%YAML 1.2", @"---", @"!<tag:clarkevans.com,2002:invoice>", @"ship-to: &A ", @" address: ", @" city: Royal Oak", @" postal: 48046", @" lines: ""458 Walkman Dr.\n\", @" Suite #292\n""", @" state: MI", @" given: Chris", @" family: Dumars", @"product: ", @" - quantity: 4", @" sku: BL394D", @" price: !!float 450", @" description: Basketball", @" - quantity: 1", @" sku: BL4438H", @" price: !!float 2392", @" description: Super Hoop", @"date: 2001-01-23", @"tax: 251.42", @"bill-to: *A", @"comments: Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.", @"total: 4443.52", @"invoice: 34843", @"..." ), yaml); Assert.AreEqual(27, invoice["invoice"].Raw); Assert.AreEqual(10, invoice["invoice"].Column); Assert.AreEqual(22, invoice["date"].Raw); Assert.AreEqual(7, invoice["date"].Column); Assert.AreEqual(4, invoice["bill-to"].Raw); Assert.AreEqual(10, invoice["bill-to"].Column); Assert.AreEqual(11, ((YamlMapping)invoice["bill-to"])["given"].Raw); Assert.AreEqual(10, ((YamlMapping)invoice["bill-to"])["given"].Column); Assert.AreEqual(4, invoice["ship-to"].Raw); Assert.AreEqual(10, invoice["ship-to"].Column); }
public void MergeKey() { var map = new YamlMapping("existing", "value"); var mergeKey = new YamlScalar("!!merge", "<<"); map.Add(mergeKey, new YamlMapping("existing", "new value")); map.OnLoaded(); Assert.AreEqual(1, map.Count); Assert.IsTrue(map.ContainsKey("existing")); Assert.AreEqual((YamlNode) "value", map["existing"]); map.Add(mergeKey, new YamlMapping("not existing", "new value")); map.OnLoaded(); Assert.AreEqual(2, map.Count); Assert.IsTrue(map.ContainsKey("existing")); Assert.AreEqual((YamlNode) "value", map["existing"]); Assert.IsTrue(map.ContainsKey("not existing")); Assert.AreEqual((YamlNode) "new value", map["not existing"]); map.Add(mergeKey, new YamlMapping("key1", "value1", 2, 2, 3.0, 3.0)); map.OnLoaded(); Assert.AreEqual(5, map.Count); Assert.IsTrue(map.ContainsKey("existing")); Assert.AreEqual((YamlNode) "value", map["existing"]); Assert.IsTrue(map.ContainsKey("not existing")); Assert.AreEqual((YamlNode) "new value", map["not existing"]); Assert.IsTrue(map.ContainsKey(2)); Assert.AreEqual((YamlNode) 2, map[2]); Assert.IsTrue(map.ContainsKey(3.0)); Assert.AreEqual((YamlNode) 3.0, map[3.0]); map = new YamlMapping( "existing", "value", mergeKey, new YamlMapping("not existing", "new value")); map.OnLoaded(); Assert.AreEqual(2, map.Count); Assert.IsTrue(map.ContainsKey("existing")); Assert.AreEqual((YamlNode) "value", map["existing"]); Assert.IsTrue(map.ContainsKey("not existing")); Assert.AreEqual((YamlNode) "new value", map["not existing"]); map = (YamlMapping) YamlNode.FromYaml( "key1: value1\r\n" + "key2: value2\r\n" + "<<: \r\n" + " key2: value2 modified\r\n" + " key3: value3\r\n" + " <<: \r\n" + " key4: value4\r\n" + " <<: value5\r\n" + "key6: <<\r\n")[0]; var mapBack = map.ToYaml(); Assert.AreEqual(@"%YAML 1.2 --- <<: value5 key1: value1 key2: value2 key3: value3 key4: value4 key6: << ... ", mapBack); Assert.IsTrue(map.ContainsKey(mergeKey)); Assert.AreEqual(mergeKey, map["key6"]); map.Remove(mergeKey); map.Add(mergeKey, map); // recursive map.OnLoaded(); // nothing has been changed mapBack = map.ToYaml(); Assert.AreEqual(@"%YAML 1.2 --- key1: value1 key2: value2 key3: value3 key4: value4 key6: << ... ", mapBack); }
public void Example2_27_YAML1_2() { var invoice = new YamlMapping( "invoice", 34843, "date", new DateTime(2001, 01, 23), "bill-to", new YamlMapping( "given", "Chris", "family", "Dumars", "address", new YamlMapping( "lines", "458 Walkman Dr.\nSuite #292\n", "city", "Royal Oak", "state", "MI", "postal", 48046 ) ), "product", new YamlSequence( new YamlMapping( "sku", "BL394D", "quantity", 4, "description", "Basketball", "price", 450.00 ), new YamlMapping( "sku", "BL4438H", "quantity", 1, "description", "Super Hoop", "price", 2392.00 ) ), "tax", 251.42, "total", 4443.52, "comments", "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338." ); invoice["ship-to"] = invoice["bill-to"]; invoice.Tag = "tag:clarkevans.com,2002:invoice"; var yaml = invoice.ToYaml(); Assert.AreEqual( MultiLineText( @"%YAML 1.2 --- !<tag:clarkevans.com,2002:invoice> bill-to: &A address: city: Royal Oak lines: ""458 Walkman Dr.\n\ Suite #292\n"" postal: 48046 state: MI family: Dumars given: Chris comments: Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338. date: 2001-01-23 invoice: 34843 product: - description: Basketball price: !!float 450 quantity: 4 sku: BL394D - description: Super Hoop price: !!float 2392 quantity: 1 sku: BL4438H ship-to: *A tax: 251.42 total: 4443.52 ..."), yaml); // Doesn't really make sense to test Row //Assert.AreEqual(27, invoice["invoice"].Row); Assert.AreEqual(10, invoice["invoice"].Column); //Assert.AreEqual(22, invoice["date"].Row); Assert.AreEqual(7, invoice["date"].Column); //Assert.AreEqual(4, invoice["bill-to"].Row); Assert.AreEqual(10, invoice["bill-to"].Column); //Assert.AreEqual(11, ( (YamlMapping)invoice["bill-to"] )["given"].Row); Assert.AreEqual(10, ( (YamlMapping)invoice["bill-to"] )["given"].Column); //Assert.AreEqual(4, invoice["ship-to"].Row); Assert.AreEqual(10, invoice["ship-to"].Column); }