public override object GetTimeSeries(locationParam location, VariableParam variable, W3CDateTime?startDate, W3CDateTime?endDate) { BaseRestClient restServiceClient; string[] parameters; { restServiceClient = new BaseRestClient(); restServiceClient.BaseUrl = "http://www2.mvr.usace.army.mil/watercontrol/webservices/rest/webserviceWaterML.cfm?"; restServiceClient.PathFormat = "Meth={0}&site={1}&variable={2}&beginDate={3}&endDate={4}"; string varCode = variable.Code; // prep for many test string siteCode = location.SiteCode; Type vType = typeof(TimeSeriesResponseType); restServiceClient.ResponseType = vType; parameters = new string[5]; parameters[0] = "getValues"; parameters[1] = siteCode; parameters[2] = varCode; parameters[3] = startDate.Value.DateTime.ToString("yyyy-MM-dd"); parameters[4] = endDate.Value.DateTime.ToString("yyyy-MM-dd"); object res = restServiceClient.GetResponseAsObject(parameters); return(res); } }
public override VariableInfoType[] GetVariableInfoObject(VariableParam variable) { VariableParam[] variables; if (variable == null) { variables = new VariableParam[0]; } else { variables = new VariableParam[1]; variables[0] = variable; } return(GetVariableInfoObject(variables)); }
public override object GetTimeSeries( locationParam Location, WaterOneFlowImpl.v1_0.VariableParam Variable, W3CDateTime?BeginDateTime, W3CDateTime?EndDateTime) { // new method. Generate a list of query parameters and values, // tack that onto the end of the base url var queryParameters = new Dictionary <string, string>(); string siteNum; string parameterCode; string statisticCode; string agencyCode = "EPA"; W3CDateTime?startDateTime = null; W3CDateTime?endDateTime = null; if (Location.isGeometry) { throw new WaterOneFlowException("Geometry not supported "); } if (Location != null) { siteNum = Location.SiteCode; agencyCode = option2AgencyCode(Location); queryParameters.Add("organization", agencyCode); queryParameters.Add("siteid", siteNum); } else { throw new WaterOneFlowException("Missing SiteCode "); } if (Variable != null) { parameterCode = Variable.Code; queryParameters.Add("characteristicName", parameterCode); queryParameters.Add("sampleMedia", siteNum); } else { throw new WaterOneFlowException("Missing Parameter "); } if (BeginDateTime.HasValue) { //tartDateTime = BeginDateTime.Value; queryParameters.Add("startDateLo", BeginDateTime.HasValue ? BeginDateTime.Value.ToString("W"): ""); } if (EndDateTime.HasValue) { //ndDateTime = EndDateTime.Value; queryParameters.Add("startDateHi", EndDateTime.HasValue ? EndDateTime.Value.ToString("W"): ""); } if (EndDateTime.HasValue && BeginDateTime.HasValue && EndDateTime.Value < BeginDateTime.Value) { endDateTime = W3CDateTime.Now; queryParameters["startDateHi"] = W3CDateTime.Now.ToString("W"); } // http://storetnwis.epa.gov/storetqw /* he site number may be optionally prefixed by the agency code followed by a colon, which ensures the site is unique. Examples: ?site=06306300 or ?sites=USGS:06306300. There is no default if this parameter is used. For real-time streamflow sites, the site number is normally 8 characters. Site numbers range from 8 to 15 character. */ string urlFormat = "&{0}={1}"; StringBuilder url = new StringBuilder(baseUrl); foreach (var q in queryParameters) { url.AppendFormat("&{0}={1}", q.Key, q.Value); } try { Uri uri = new Uri(url.ToString()); using (WebClient web = new WebClient()) { TimeSeriesResponseType response; using (XmlReader reader = new XmlTextReader(web.OpenRead(uri))) { XmlWriter writer = null; MemoryStream memoryStream = new MemoryStream(); try { writer = XmlWriter.Create(memoryStream); // Create the XsltArgumentList. XsltArgumentList argList = new XsltArgumentList(); argList.AddParam("network", "", Location.Network); argList.AddParam("vocabulary", "", Variable.Vocabulary); argList.AddParam("location", "", Location.ToString()); argList.AddParam("variable", "", Variable.ToString()); argList.AddParam("starttime", "", BeginDateTime.HasValue? BeginDateTime.Value.ToString("W"): ""); argList.AddParam("endtime", "", EndDateTime.HasValue? EndDateTime.Value.ToString("W"): ""); xslt.Transform(reader, argList, writer); memoryStream.Position = 0; using (var reader2 = XmlReader.Create(memoryStream)) { response = (TimeSeriesResponseType)serializer.Deserialize(reader2); } } finally { memoryStream.Close(); } } //TimeSeriesResponseType response // = new Passthrough(web.OpenRead(url)); return(response); } } catch (WebException ex) { if (ex.Response is HttpWebResponse) { switch (((HttpWebResponse)ex.Response).StatusCode) { case HttpStatusCode.NotFound: log.Info("WebSite Not Found" + ex.Message); throw new WaterOneFlowSourceException("Site/Variable combination Not Found"); break; case HttpStatusCode.ServiceUnavailable: log.Info("WebSite Service Not Available " + ex.Message); throw new WaterOneFlowSourceException("Service Not Available. Please try later"); break; default: log.Info("WebSite Connection Error " + ex.Message); throw new WaterOneFlowSourceException("Error connecting to WebSite"); } } log.Info("WebSite Connection Error " + ex.Message); throw new WaterOneFlowSourceException("Error connecting to WebSite: WebException: " + url); } catch (XmlException ex) { log.Info("Error in communication with WebSite " + ex.Message); throw new WaterOneFlowSourceException("Error in communication with WebSite: XmlExpcetion "); } catch (XsltException ex) { log.Info("Error in communication with WebSite " + ex.Message); throw new WaterOneFlowSourceException("Error in communication with WebSite: XsltException "); } catch (Exception ex) { log.Info("Error in communication with WebSite " + ex.Message); throw new WaterOneFlowSourceException("Error in communication with WebSite: Unknown Exception "); } }