/// <summary> /// createSiteInfoResponse populates a SiteInfoResponseType. /// It is used the webmethod getSiteInfo. /// designed for multiple site codes /// This method will be slow if the information has never been cached. /// </summary> /// <param name="LocationParams"></param> private SiteInfoResponseType CreateSitesResponse(locationParam[] LocationParams) { /* for each site code, add a siteInfo type with a period of record * // for each site * createSitInfoType * add to response * createPeriodOfRecord * add to response * return response * */ SiteInfoResponseType response; SiteInfoType[] sites = ODSiteInfo.GetSitesByLocationParameters(LocationParams); if (sites.Length == 0) { throw new WaterOneFlowException("No Sites found"); } response = CuahsiBuilder.CreateASetOfSiteResponses(sites.Length, 1); for (int i = 0; i < sites.Length; i++) { response.site[i].siteInfo = sites[i]; String aSiteID = response.site[i].siteInfo.siteCode[0].siteID; // no period of record } return(response); }
private SiteInfoType getSiteInfoType(locationParam LocationParameter) { SiteInfoType sit; // look in memory // sit = (SiteInfoType)appCache[sitCache + siteCode]; // if (sit != null) return sit; //ok, try the database SiteInfoType[] sites = ODSiteInfo.GetSitesByLocationParameters(new locationParam[] { LocationParameter }); if (sites == null || sites.Length == 0) { return(null); } else if (sites != null && sites.Length == 1) { return(sites[0]); } else { // had better be only one String error = "More than one site with SiteCode '" + LocationParameter + "'"; log.Error(error); throw new WaterOneFlowException(error); } return(sit); }
public TimeSeriesResponseType getValues(string SiteNumber, string Variable, string StartDate, string EndDate) { // convert dates // get site info // get site ID // return value dataset TimeSeriesResponseType response; W3CDateTime? BeginDateTime; W3CDateTime? EndDateTime; int?variableId = null; int?siteID; VariableInfoType varInfoType = null; SiteInfoType siteType = null; if (!String.IsNullOrEmpty(StartDate)) { try { BeginDateTime = W3CDateTime.Parse(StartDate); } catch { throw new WaterOneFlowException("Improper BeginDate '" + StartDate + "' Must be YYYY-MM-DD"); } } else { BeginDateTime = null; } if (!String.IsNullOrEmpty(EndDate)) { try { EndDateTime = W3CDateTime.Parse(EndDate); } catch { throw new WaterOneFlowException("Improper EndDate '" + EndDate + "' Must be YYYY-MM-DD"); } } else { EndDateTime = null; } VariableParam vp; if (Variable != null) { vp = new VariableParam(Variable); VariableInfoType[] v = ODvariables.getVariable(vp, variableDs); if (v != null && v.Length > 0) { variableId = Convert.ToInt16(v[0].variableCode[0].variableID); varInfoType = v[0]; } else { throw new WaterOneFlowException("Variable parameter not found: " + Variable); } } else { throw new WaterOneFlowException("Variable parameter is required "); } locationParam sq; sq = new locationParam(SiteNumber); if (sq.isGeometry) { throw new WaterOneFlowException("Location by Geometry not accepted: " + SiteNumber); } siteInfoDataSet sitDs = ODSiteInfo.GetSiteInfoDataSet(sq); if (sitDs != null && sitDs.sites.Count > 0) { siteID = sitDs.sites[0].SiteID; ValuesDataSet valuesDs = getValuesDataset(siteID, variableId, BeginDateTime, EndDateTime, vp); response = getValues(valuesDs, vp); // above is the values, add the site, and variables response.timeSeries.variable = varInfoType; if (varInfoType != null) { if (varInfoType.units != null) { response.timeSeries.values.unitsAbbreviation = varInfoType.units.unitsAbbreviation; response.timeSeries.values.unitsCode = varInfoType.units.unitsCode; if (varInfoType.units.unitsType != null) { response.timeSeries.values.unitsType = varInfoType.units.unitsType; response.timeSeries.values.unitsTypeSpecified = true; } response.timeSeries.values.unitsAreConverted = false; } } response.timeSeries.sourceInfo = ODSiteInfo.row2SiteInfoElement(sitDs.sites[0], sitDs); } else { response = CuahsiBuilder.CreateTimeSeriesObject(); } // add query info response.queryInfo.creationTime = DateTime.UtcNow; //response.queryInfo.creationTime = DateTimeOffset.UtcNow; response.queryInfo.creationTimeSpecified = true; response.queryInfo.criteria.locationParam = SiteNumber; response.queryInfo.criteria.variableParam = Variable; response.queryInfo.criteria.timeParam = CuahsiBuilder.createQueryInfoTimeCriteria(StartDate, EndDate); NoteType sourceNote = CuahsiBuilder.createNote("OD Web Service"); response.queryInfo.note = CuahsiBuilder.addNote(response.queryInfo.note, sourceNote); return(response); }