public IHttpActionResult Post([FromBody] List <dataTypeList.dataType> input) { IDbConnection db = HdbController.Connect(this.Request.Headers); var sdiProcessor = new HdbApi.DataAccessLayer.SiteDataTypeRepository(); List <string> sdi = new List <string>(); List <string> sid = new List <string>(); List <string> did = new List <string>(); foreach (dataTypeList.dataType dType in input) { //if (dType.sdi > 0) //{ sdi.Add(dType.sdi); } //if (dType.sid > 0) //{ sid.Add(dType.sid); } //if (dType.did > 0) //{ did.Add(dType.did); } sdi.Add(dType.sdi); sid.Add(dType.sid); did.Add(dType.did); } var result = sdiProcessor.GetSiteDataTypes(db, sdi.ToArray(), sid.ToArray(), did.ToArray()); try { db.Close(); db.Dispose(); } catch { } return(Ok(result)); }
public IHttpActionResult Post([FromBody] List <Models.PointModel.ObservedPoint> input) { IDbConnection db = HdbController.Connect(this.Request.Headers); var hdbProcessor = new HdbApi.App_Code.HdbCommands(); foreach (Models.PointModel.ObservedPoint point in input) { if (point.loading_application_id < 1) { point.loading_application_id = -99; } if (point.computation_id < 1) { point.computation_id = -99; } if (point.data_flags == null) { point.data_flags = ""; } var result = hdbProcessor.modify_r_base_raw(db, point.site_datatype_id, point.interval, point.start_date_time, point.value, point.overwrite_flag, point.validation, point.do_update_y_or_n, point.loading_application_id, point.computation_id, point.data_flags); } try { db.Close(); db.Dispose(); } catch { } return(Ok(input)); }
public IHttpActionResult Get() { IDbConnection db = HdbController.Connect(this.Request.Headers); var sprocProcessor = new HdbApi.DataAccessLayer.SprocRepository(); return(Ok(sprocProcessor.GetData(db))); }
public IHttpActionResult Get([FromUri] string[] id = null) { IDbConnection db = HdbController.Connect(this.Request.Headers); var siteProcessor = new HdbApi.DataAccessLayer.SiteRepository(); var result = siteProcessor.GetSites(db, id); try { db.Close(); db.Dispose(); } catch { } return(Ok(result)); }
public IHttpActionResult Get([FromUri] IdType idtype = new IdType(), [FromUri] int[] id = null, [FromUri] string modelrunname = null) { IDbConnection db = HdbController.Connect(this.Request.Headers); var modelRunProcessor = new HdbApi.DataAccessLayer.ModelRunRepository(); var result = modelRunProcessor.GetModelRun(db, idtype.ToString(), id, modelrunname); try { db.Close(); db.Dispose(); } catch { } return(Ok(result)); }
public IHttpActionResult Get([FromUri] string sdi, [FromUri] DateTime t1, [FromUri] DateTime t2, [FromUri] IntervalType interval = new IntervalType(), [FromUri] bool rbase = false, [FromUri] TableType table = new TableType(), [FromUri] int mrid = 0, [FromUri] string instantMinutes = "60") { IDbConnection db = HdbController.Connect(this.Request.Headers); var seriesProcessor = new HdbApi.DataAccessLayer.SeriesRepository(); var result = seriesProcessor.GetSeries(db, sdi, interval.ToString(), t1, t2, table.ToString(), mrid, rbase, instantMinutes); try { db.Close(); db.Dispose(); } catch { } return(Ok(result)); }
public IHttpActionResult Delete([FromBody] List <Models.PointModel.ModeledPoint> input) { IDbConnection db = HdbController.Connect(this.Request.Headers); var hdbProcessor = new HdbApi.App_Code.HdbCommands(); foreach (Models.PointModel.ModeledPoint point in input) { var result = hdbProcessor.delete_from_hdb(db, point.site_datatype_id, point.start_date_time, point.interval, point.model_run_id); } try { db.Close(); db.Dispose(); } catch { } return(Ok(input)); }
public IHttpActionResult Get([FromUri] string svr, [FromUri] string sqlStatement) { var cgiProcessor = new HdbApi.DataAccessLayer.CgiRepository(); // Connect to HDB bool hostFound = false; List <string[]> hostList = cgiProcessor.get_host_list(); foreach (string[] hostInfo in hostList) { if (svr == hostInfo[0].ToString()) { hostFound = true; this.Request.Headers.Add("api_hdb", hostInfo[0]); this.Request.Headers.Add("api_user", hostInfo[4]); this.Request.Headers.Add("api_pass", hostInfo[5]); } } if (!hostFound) { throw new Exception("HDB Database not recognized."); } IDbConnection db = HdbController.Connect(this.Request.Headers); var sprocProcessor = new HdbApi.DataAccessLayer.SprocRepository(); var result = sprocProcessor.RunSqlSelect(db, sqlStatement); try { db.Close(); db.Dispose(); } catch { } return(Ok(result)); }
public HttpResponseMessage Get([FromUri] string svr, [FromUri] string sdi, [FromUri] string t1, [FromUri] string t2, [FromUri] string tstp = "DY", [FromUri] TableType table = new TableType(), [FromUri] string mrid = "0", [FromUri] string format = "1") { var cgiProcessor = new HdbApi.DataAccessLayer.CgiRepository(); IDbConnection db; if (svr.ToLower() == "pnhyd" || svr.ToLower() == "gphyd") { db = null; } else //HDB { // Connect to HDB bool hostFound = false; List <string[]> hostList = cgiProcessor.get_host_list(); foreach (string[] hostInfo in hostList) { if (svr == hostInfo[0].ToString()) { hostFound = true; this.Request.Headers.Add("api_hdb", hostInfo[0]); this.Request.Headers.Add("api_user", hostInfo[4]); this.Request.Headers.Add("api_pass", hostInfo[5]); } } if (!hostFound) { throw new Exception("HDB Database not recognized."); } db = HdbController.Connect(this.Request.Headers); } // Build CGI query URL // ?svr=lchdb2&sdi=25401&tstp=IN&t1=2018-05-07T05:00&t2=2018-05-07T08:00&table=R&mrid=&format=2 var tstpString = ""; switch (tstp.ToString().ToLower()) { case "instant": case "in": tstpString = "IN"; break; case "hour": case "hr": tstpString = "HR"; break; case "month": case "mn": tstpString = "MN"; break; case "year": case "yr": tstpString = "YR"; break; case "wy": tstpString = "WY"; break; default: tstpString = "DY"; break; } tstp = tstpString; int t1Int, t2Int; DateTime t1Input, t2Input; if (DateTime.TryParse(t1, out t1Input) && DateTime.TryParse(t2, out t2Input)) { // Snap date-times to the time-step-specific date format switch (tstp.ToString().ToLower()) { case "in": case "hr": t1Input = t1Input; t2Input = t2Input; break; case "dy": t1Input = new DateTime(t1Input.Year, t1Input.Month, t1Input.Day, 0, 0, 0); t2Input = new DateTime(t2Input.Year, t2Input.Month, t2Input.Day, 0, 0, 0); break; case "mn": t1Input = new DateTime(t1Input.Year, t1Input.Month, 1, 0, 0, 0); t2Input = new DateTime(t2Input.Year, t2Input.Month, 1, 0, 0, 0); break; case "yr": case "wy": t1Input = new DateTime(t1Input.Year, 1, 1, 0, 0, 0); t2Input = new DateTime(t2Input.Year, 1, 1, 0, 0, 0); break; default: throw new Exception("Error: Invalid Query Time-Step."); } } // Special case for T1 and T2 - If integers, query last X-timestep's worth of data and snap dates else if (int.TryParse(t1, out t1Int) && int.TryParse(t2, out t2Int)) { switch (tstp.ToString().ToLower()) { case "in": case "hr": t1Input = DateTime.Now.AddHours(t1Int); t1Input = new DateTime(t1Input.Year, t1Input.Month, t1Input.Day, t1Input.Hour, 0, 0); t2Input = DateTime.Now.AddHours(t2Int); t2Input = new DateTime(t2Input.Year, t2Input.Month, t2Input.Day, t2Input.Hour, 0, 0); break; case "dy": t1Input = DateTime.Now.AddDays(t1Int); t1Input = new DateTime(t1Input.Year, t1Input.Month, t1Input.Day, 0, 0, 0); t2Input = DateTime.Now.AddDays(t2Int); t2Input = new DateTime(t2Input.Year, t2Input.Month, t2Input.Day, 0, 0, 0); break; case "mn": t1Input = DateTime.Now.AddMonths(t1Int); t1Input = new DateTime(t1Input.Year, t1Input.Month, 1, 0, 0, 0); t2Input = DateTime.Now.AddMonths(t2Int); t2Input = new DateTime(t2Input.Year, t2Input.Month, 1, 0, 0, 0); break; case "yr": case "wy": t1Input = DateTime.Now.AddYears(t1Int); t1Input = new DateTime(t1Input.Year, 1, 1, 0, 0, 0); t2Input = DateTime.Now.AddYears(t2Int); t2Input = new DateTime(t2Input.Year, 1, 1, 0, 0, 0); break; default: throw new Exception("Error: Invalid Query Time-Step."); } } else { throw new Exception("Error: Invalid Query Dates."); } var urlString = "?svr=" + svr + "&sdi=" + sdi + "&tstp=" + tstpString + "&t1=" + t1Input.ToString("yyyy-MM-ddTHH\\:mm") + "&t2=" + t2Input.ToString("yyyy-MM-ddTHH\\:mm") + "&table=" + table.ToString() + "&mrid=" + mrid + "&format=" + format; List <string> result = cgiProcessor.get_cgi_data(db, urlString); var output = String.Join <string>(String.Empty, result); var response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new StringContent(output, System.Text.Encoding.UTF8, "text/html"); try { db.Close(); db.Dispose(); } catch { } return(response); }