private static void NCDCSitesXMLReader(List <SiteInfoNCDC> sites, XmlReader xmlReader) { xmlReader.ReadToDescendant("site"); while (xmlReader.IsStartElement()) { XmlReader siteReader = xmlReader.ReadSubtree(); SiteInfoNCDC site = new SiteInfoNCDC(); siteReader.ReadStartElement(); while (siteReader.IsStartElement()) { switch (siteReader.Name) { case "datasetid": site.DatasetID = siteReader.ReadString(); break; case "stationid": site.StationID = siteReader.ReadString(); break; case "name": site.SiteName = siteReader.ReadString(); break; case "lat": site.SetLatitude(siteReader.ReadString()); break; case "lon": site.SetLongitude(siteReader.ReadString()); break; case "lowdate": site.SetBeginDate(siteReader.ReadString()); break; case "highdate": site.SetEndDate(siteReader.ReadString()); break; case "elev": site.SetElevation(siteReader.ReadString()); break; default: log.Error("New Node name in site " + siteReader.Name); siteReader.ReadString(); break; } siteReader.ReadEndElement(); //siteReader.ReadStartElement(); } sites.Add(site); xmlReader.ReadEndElement(); } }
public void SetEndDateTest() { SiteInfoNCDC target = new SiteInfoNCDC(); string DateYYYYmm = null; // TODO: Initialize to an appropriate value target.SetEndDate(DateYYYYmm); Assert.Ignore("A method that does not return a value cannot be verified."); }
public void SetLongitudeTest() { SiteInfoNCDC target = new SiteInfoNCDC(); string LonString = null; // TODO: Initialize to an appropriate value target.SetLongitude(LonString); Assert.Ignore("A method that does not return a value cannot be verified."); }
public void SetElevationTest() { SiteInfoNCDC target = new SiteInfoNCDC(); string elevation = null; // TODO: Initialize to an appropriate value target.SetElevation(elevation); Assert.Ignore("A method that does not return a value cannot be verified."); }
public void StationIDTest() { SiteInfoNCDC target = new SiteInfoNCDC(); string val = null; // TODO: Assign to an appropriate value for the property target.StationID = val; Assert.AreEqual(val, target.StationID, "NCDC.RestService.SiteInfoNCDC.StationID was not set correctly."); Assert.Ignore("Verify the correctness of this test method."); }
public void LongitudeTest() { SiteInfoNCDC target = new SiteInfoNCDC(); double val = -50.0; // TODO: Assign to an appropriate value for the property target.Longitude = val; Assert.AreEqual(val, target.Longitude, "NCDC.RestService.SiteInfoNCDC.Longitude was not set correctly."); Assert.Ignore("Verify the correctness of this test method."); }
public void EndDateTest() { SiteInfoNCDC target = new SiteInfoNCDC(); DateTime val = new DateTime(); // TODO: Assign to an appropriate value for the property target.EndDate = val; Assert.AreEqual(val, target.EndDate, "NCDC.RestService.SiteInfoNCDC.EndDate was not set correctly."); Assert.Ignore("Verify the correctness of this test method."); }
public void ElevationTest() { SiteInfoNCDC target = new SiteInfoNCDC(); float val = 0; // TODO: Assign to an appropriate value for the property target.Elevation = val; Assert.AreEqual(val, target.Elevation, "NCDC.RestService.SiteInfoNCDC.Elevation was not set correctly."); Assert.Ignore("Verify the correctness of this test method."); }
public void DateTimeFromYearMonthTest() { SiteInfoNCDC target = new SiteInfoNCDC(); ASOSRestTest.NCDC_RestService_SiteInfoNCDCAccessor accessor = new ASOSRestTest.NCDC_RestService_SiteInfoNCDCAccessor(target); string YYYYmm = null; // TODO: Initialize to an appropriate value DateTime expected = new DateTime(); DateTime actual; actual = accessor.DateTimeFromYearMonth(YYYYmm); Assert.AreEqual(expected, actual, "NCDC.RestService.SiteInfoNCDC.DateTimeFromYearMonth did not return the expected v" + "alue."); Assert.Ignore("Verify the correctness of this test method."); }
public void AddToDBTest() { string connectionString = "Data Source=localhost;Initial Catalog=ASOS;Integrated Security=True;"; // TODO: Initialize to an appropriate value string tableName = "siteInfo$"; SitesToDb target = new SitesToDb(connectionString); SiteInfoNCDC site = new SiteInfoNCDC(); site.StationID = "09999999"; site.SiteName = "TEst"; site.SetLongitude("179"); site.SetLatitude("80"); site.SetBeginDate("200601"); site.SetEndDate("200801"); site.Elevation = 0; site.DatasetID = "-1"; target.AddToDB(site, ExportType.ALL, tableName); SqlConnection con = new SqlConnection(); con.ConnectionString = connectionString; con.Open(); SqlCommand comm = con.CreateCommand(); comm.CommandText = "Select count(SiteID) from " + tableName + " where SiteID ='" + site.StationID + "'"; int numROws = (int)comm.ExecuteScalar(); Assert.LessOrEqual(numROws, 1, "Retrned more than one row"); // Assert.Inconclusive("A method that does not return a value cannot be verified."); }
/// <summary> /// Adds a single to the database. /// If site does not exist, all information will be added. /// If site exists, all information updated as described by ExportType. /// </summary> /// <param name="site">List of sites</param> /// <param name="exportType">ExportType to apply to record UPDATES. <see cref="ExportType"/></param> /// <remarks><list type="bullet"> /// <item>ExportType.All - Update </item> /// <item>ExportType.LatLon - Update only cooridate columns</item> /// <item>ExportType.BeginEnd - Update only time range</item> /// </list> /// </remarks> public void AddToDB(SiteInfoNCDC site, ExportType exportType, string tableName) { string sqlDuplicateCheck = "select count(siteID) from " + tableName + " where siteID =@SiteID and DatasetId=@datasetid"; string sqlInsert = "Insert into " + tableName + "(datasetID,siteID,SiteName,latitude,longitude,elevation,beginDate,endDate, state, country, dateAdded, DateUpdated)" + " Values(@datasetID,@siteID,@SiteName,@latitude,@longitude,@elevation,@beginDate,@endDate,@state,@country,getdate(),getdate())"; string sqlUpdate = "Update " + tableName + " set SiteName= @siteName, " + " siteId=@siteID, " + " latitude=@latitude, " + " longitude=@longitude, " + " beginDate=@beginDate, " + " endDate=@endDate, " + " state= @state, " + " country = @country, " + " DateUpdated = getdate() " + " where siteID = @siteId " + "AND DatasetId=@datasetid"; switch (exportType) { case ExportType.LatLong: sqlUpdate = "Update " + tableName + " set " + " latitude=@latitude, " + " longitude=@longitude, " + " DateUpdated = getdate() " + " where siteID = @siteId " + "AND DatasetId=@datasetid"; break; case ExportType.BeginEnd: sqlUpdate = "Update " + tableName + " set " + " beginDate=@beginDate, " + " endDate=@endDate, " + " DateUpdated = getdate() " + " where siteID = @siteId " + "AND DatasetId=@datasetid"; break; case ExportType.ALL: default: sqlUpdate = "Update " + tableName + " set SiteName= @siteName, " + " siteId=@siteID, " + " latitude=@latitude, " + " longitude=@longitude, " + " beginDate=@beginDate, " + " endDate=@endDate, " + " state= @state, " + " country = @country, " + " DateUpdated = getdate() " + " where siteID = @siteId " + "AND DatasetId=@datasetid"; break; } if (DatabaseConnection == null) { throw new Exception("Configure object with DatabaseConnection prior to export"); } DatabaseConnection.Open(); SqlCommand command = DatabaseConnection.CreateCommand(); command.CommandText = sqlDuplicateCheck; command.Parameters.AddWithValue("@siteid", site.StationID); command.Parameters.AddWithValue("@datasetID", ValueOrDBNull(site.DatasetID)); command.Parameters.AddWithValue("@SiteName", ValueOrDBNull(site.SiteName)); command.Parameters.AddWithValue("@latitude", ValueOrDBNull(site.Latitude)); command.Parameters.AddWithValue("@longitude", ValueOrDBNull(site.Longitude)); command.Parameters.AddWithValue("@beginDate", ValueOrDBNull(site.BeginDate)); command.Parameters.AddWithValue("@endDate", ValueOrDBNull(site.EndDate)); command.Parameters.AddWithValue("@elevation", ValueOrDBNull(site.Elevation)); command.Parameters.AddWithValue("@state", ValueOrDBNull(site.State)); command.Parameters.AddWithValue("@country", ValueOrDBNull(site.Country)); int result = (int)command.ExecuteScalar(); if (result < 1) { command.CommandText = sqlInsert; command.ExecuteNonQuery(); DatabaseConnection.Close(); return; } else { command.CommandText = sqlUpdate; command.ExecuteNonQuery(); DatabaseConnection.Close(); return; } }
private static void WaterMLSitesXMLReader(List <SiteInfoNCDC> sites, XmlReader xmlReader, string DefaultDatasetID) { xmlReader.ReadToDescendant("site", Utility.WaterMlNs); while (xmlReader.IsStartElement()) { xmlReader.ReadToDescendant("siteInfo", Utility.WaterMlNs); XmlReader siteReader = xmlReader.ReadSubtree(); SiteInfoNCDC site = new SiteInfoNCDC(); site.DatasetID = DefaultDatasetID; /* * <ns2:siteInfo> * <ns2:siteCode siteID="99999925226" network="NCDC" defaultId="true">SMITH RIVER</ns2:siteCode> * <ns2:geoLocation> * <ns2:geogLocation xsi:type="ns2:LatLonPointType" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> * <ns2:latitude>0.0599</ns2:latitude> * <ns2:longitude>-0.12643333</ns2:longitude> * </ns2:geogLocation> * </ns2:geoLocation> * </ns2:siteInfo> */ siteReader.ReadStartElement(); while (siteReader.IsStartElement()) { switch (siteReader.LocalName) { case "siteCode": /* * <ns2:siteCode * siteID="99999925226" * network="NCDC" * defaultId="true">SMITH RIVER</ns2:siteCode> */ if (siteReader.HasAttributes) { // siteReader.MoveToFirstAttribute(); while (siteReader.MoveToNextAttribute()) { switch (siteReader.LocalName) { case "siteID": site.StationID = siteReader.ReadContentAsString(); break; case "network": break; default: break; } ; } } siteReader.MoveToElement(); site.SiteName = siteReader.ReadElementContentAsString(); break; case "geoLocation": /* <ns2:geoLocation> * <ns2:geogLocation xsi:type="ns2:LatLonPointType" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> * <ns2:latitude>0.0599</ns2:latitude> * <ns2:longitude>-0.12643333</ns2:longitude> * </ns2:geogLocation> */ try { siteReader.ReadToDescendant("latitude", Utility.WaterMlNs); if (siteReader.NodeType != XmlNodeType.None) { double lat = 0.0; string lString = siteReader.ReadElementContentAsString("latitude", Utility.WaterMlNs); if (double.TryParse( lString, out lat)) { site.Latitude = lat; } } //siteReader.ReadEndElement(); // not needed after read content if (siteReader.LocalName != "longitude") { siteReader.ReadToFollowing("longitude", Utility.WaterMlNs); } if (siteReader.NodeType != XmlNodeType.None) { double lon = 0.0; string lString = siteReader.ReadElementContentAsString("longitude", Utility.WaterMlNs); if (double.TryParse( lString, out lon)) { site.Longitude = lon; } } //siteReader.ReadEndElement(); //long // not needed after read content siteReader.ReadEndElement(); //geoglocation siteReader.ReadEndElement(); // geolocation break; } catch { ReadState state = siteReader.ReadState; if (siteReader.NodeType == null) { siteReader.Skip(); } else { siteReader.ReadEndElement(); } break; } default: log.Error("New Node name in site " + siteReader.Name); siteReader.ReadEndElement(); break; } //siteReader.ReadEndElement(); //siteReader.ReadStartElement(); } sites.Add(site); xmlReader.ReadEndElement(); // siteInfo xmlReader.ReadEndElement(); //site } }