public void Test_02() { // vcard[1].geo.latitude string test = nodes.GetNameByPosition("vcard", 1).Nodes["geo"].Nodes["latitude"].Value; string testGeo = new Geo(test).ToString(); string resultGeo = new Geo("37.77").ToString(); Assert.That(testGeo, Is.EqualTo(resultGeo), "Should extract latitude value from paired value" ); }
public void Test_01() { // vcard[0].geo.latitude string test = nodes.GetNameByPosition("vcard", 0).Nodes["geo"].Nodes["latitude"].Value; string testGeo = new Geo(test).ToString(); string resultGeo = new Geo("37.77").ToString(); Assert.That(testGeo, Is.EqualTo(resultGeo), "Should find latitude value from single element" ); }
public void Test_04() { // vcard[3].geo.latitude var vcard = nodes.GetNameByPosition("vcard", 3); Assert.That(vcard, Is.Not.Null); var geo = vcard.Nodes["geo"]; Assert.That(geo, Is.Not.Null); var latitude = geo.Nodes["latitude"]; Assert.That(latitude, Is.Not.Null); string test = latitude.Value; string testGeo = new Geo(test).ToString(); string resultGeo = new Geo("23.7").ToString(); Assert.That(testGeo, Is.EqualTo(resultGeo), "Should find latitude value from single element"); }
/// <summary> /// Breaks geo string such as 37.77;-122.41 into longitude and latitude child nodes /// </summary> /// <param name="node">Node containing 'geo' data</param> public static void GeoOptimization(UfDataNode node) { // If geo has child nodes check they are valid and reset values if (node.Nodes.Count > 0) { string latitude = ""; if (node.Nodes["latitude"] != null) latitude = node.Nodes["latitude"].Value; string longitude = ""; if (node.Nodes["longitude"] != null) longitude = node.Nodes["longitude"].Value; try { Geo geo = new Geo(latitude + ';' + longitude); if (node.Nodes["latitude"] != null) node.Nodes["latitude"].Value = geo.Latitude.ToString(); if (node.Nodes["longitude"] != null) node.Nodes["longitude"].Value = geo.Longitude.ToString(); } catch (Exception ex) { // On error reset by removing child nodes if (node.Nodes["longitude"] != null) node.Nodes.Remove(node.Nodes["longitude"]); if (node.Nodes["latitude"] != null) node.Nodes.Remove(node.Nodes["latitude"]); } } // If geo has no child nodes parse parent text if (node.Nodes.Count == 0 && node.Value != "") { // If there are no child nodes if (node.Value.IndexOf(';') > 0) { UfDataNode lonNode = new UfDataNode(); UfDataNode latNode = new UfDataNode(); try { Geo geo = new Geo(node.Value); node.Nodes.Add(new UfDataNode("latitude", geo.Latitude.ToString())); node.Nodes.Add(new UfDataNode("longitude", geo.Longitude.ToString())); } catch (Exception ex) { // On error reset by removing child nodes node.Nodes.Clear(); } } } // Remove parent value if its a true geo and not a compound name use like "location" if (node.Name == "geo") node.Value = ""; }