コード例 #1
0
        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));
        }
コード例 #2
0
ファイル: ApiCrudTests.cs プロジェクト: usbr/HdbApi
        public void SeriesMtableInsertEndPoint()
        {
            var hdbProcessor = new HdbApi.App_Code.HdbCommands();
            var result       = hdbProcessor.modify_m_table_raw(conx, testMRID, Convert.ToInt16(testSDI), testT, testVal, testInterval, testBool);

            var seriesProcessor = new DataAccessLayer.SeriesRepository();
            var verification    = seriesProcessor.GetSeries(conx, testSDI, testInterval, testT, testT, "M", testMRID);

            Assert.AreEqual(testVal.ToString(), verification.data[0].value);
            hdbProcessor.delete_from_hdb(conx, Convert.ToInt16(testSDI), testT, testInterval, testMRID);
        }
コード例 #3
0
ファイル: ApiCrudTests.cs プロジェクト: usbr/HdbApi
        public void SeriesRtableDeleteEndPoint()
        {
            var hdbProcessor = new HdbApi.App_Code.HdbCommands();
            var result       = hdbProcessor.modify_r_base_raw(conx, Convert.ToInt16(testSDI), testInterval, testT, testVal, testBool, testFlag, testBool);//, testLoadingApplicationId);

            hdbProcessor.delete_from_hdb(conx, Convert.ToInt16(testSDI), testT, testInterval);

            var seriesProcessor = new DataAccessLayer.SeriesRepository();
            var verification    = seriesProcessor.GetSeries(conx, testSDI, testInterval, testT, testT);

            Assert.AreEqual(null, verification.data[0].value);
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        //private System.Data.IDbConnection db = HdbApi.App_Code.DbConnect.Connect();

        public List <string> get_cgi_data(IDbConnection hDB, string srchStr)
        {
            var hdbProcessor      = new HdbApi.App_Code.HdbCommands();
            var hydrometProcessor = new HdbApi.App_Code.HydrometCommands();

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Build date ranges for series lookup
            // Define HDB table time-step.
            Match  outTstep    = Regex.Match(srchStr, @"&tstp=([A-Za-z]+)&");
            string sourceTstep = "";

            switch (outTstep.Groups[1].Value.ToString().ToLower())
            {
            case "in":
                sourceTstep = "INSTANT";
                break;

            case "hr":
                sourceTstep = "HOUR";
                break;

            case "dy":
                sourceTstep = "DAY";
                break;

            case "mn":
                sourceTstep = "MONTH";
                break;

            case "yr":
                sourceTstep = "YEAR";
                break;

            case "wy":
                sourceTstep = "WY";
                break;

            default:
                throw new Exception("Error: Invalid Query Time-Step.");
            }

            DateTime t1      = new DateTime();
            DateTime t2      = new DateTime();
            DateTime t1Input = new DateTime();
            DateTime t2Input = new DateTime();

            // support for iso8601/parse-able date formats
            Match t1Iso = Regex.Match(srchStr, @"&t1=(.+?)&");
            Match t2Iso = Regex.Match(srchStr, @"&t2=(.+?)&");

            if (DateTime.TryParse(t1Iso.Groups[1].Value, out t1) && DateTime.TryParse(t2Iso.Groups[1].Value, out t2))
            {
                t1Input = t1;
                t2Input = t2;
                if (outTstep.Groups[1].Value.ToString().ToLower() == "in" || outTstep.Groups[1].Value.ToString().ToLower() == "hr")
                {
                    t2 = t2.AddDays(1);//hack to grab all t2 data
                }
            }
            else
            {
                throw new Exception("Error: Invalid Query Dates.");
            }

            // Snap dates
            switch (outTstep.Groups[1].Value.ToString().ToLower())
            {
            case "in":
            case "hr":
                t1Input = new DateTime(t1Input.Year, t1Input.Month, t1Input.Day, t1Input.Hour, 0, 0);
                t2Input = new DateTime(t2Input.Year, t2Input.Month, t2Input.Day, t2Input.Hour, 0, 0);
                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.");
            }

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Get SDIs and query information for HDB lookup
            // [OPTIONAL INPUT] Define HDB table source. Default to the R-tables if not defined in input search string
            string sourceTable    = "";
            string mridString     = "0";
            int    mridInt        = 0;
            Match  outSourceTable = Regex.Match(srchStr, @"&table=([A-Za-z])");

            if (!outSourceTable.Success)
            {
                sourceTable = "R";
                mridString  = null;
            }
            else
            {
                sourceTable = outSourceTable.Groups[1].Value.ToString();
                if (sourceTable == "M")
                {
                    mridString = Regex.Match(srchStr, @"&mrid=([\s\S]*?)&").Groups[1].Value.ToString();
                    //mridInt = Convert.ToInt32(mridString);
                }
            }
            // Get SDIs and check for duplicates
            var           sdiString = Regex.Match(srchStr, @"sdi=([\s\S]*?)&").Groups[1].Value.ToString();
            List <string> sdiList   = new List <string>();

            sdiList.AddRange(sdiString.Split(','));
            sdiList = sdiList.Distinct().ToList();
            List <string> invalidSdiList = new List <string>();

            if (hDB != null)
            {
                invalidSdiList = sdiList.Where(w => w.Any(c => !Char.IsDigit(c))).ToList();
            }
            sdiString = "";
            if (invalidSdiList.Count() > 0 && sourceTable == "M") //no sdi passed in so get a list of sdis
            {
                sdiString = hdbProcessor.get_sdis_from_mrid(hDB, mridString, sourceTstep).ToString();
            }
            else if (invalidSdiList.Count() > 0) //querying r tables with no sdi? nope!
            {
                Console.WriteLine("Error: Invalid SDI in query.");
                return(new List <string> {
                });
            }
            else //build list of sdis
            {
                foreach (var item in sdiList)
                {
                    sdiString = sdiString + item + ",";
                }
            }
            sdiString = sdiString.Remove(sdiString.Count() - 1);

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////
            DataTable dataTable;
            DataTable infoTable;

            if (hDB != null)
            {
                // Get HDB data
                // Main data query. Uses Stored HDB Procedure "GET_HDB_CGI_DATA" & "GET_HDB_CGI_INFO"
                if (sourceTstep == "INSTANT")
                {
                    dataTable = hdbProcessor.get_hdb_cgi_instant_data(hDB, sdiString, t1, t2, sourceTable);
                }
                else
                {
                    //dataTable = hdbProcessor.get_hdb_cgi_data(hDB, sdiString, sourceTstep, t1, t2, sourceTable, mridInt);
                    dataTable = hdbProcessor.get_hdb_cgi_data_sql(hDB, sdiString, sourceTstep, t1, t2, sourceTable, mridString);
                }
                // SDI info query
                infoTable = hdbProcessor.get_hdb_cgi_info_sql(hDB, sdiString);
            }
            else
            {
                DataTable[] dtOut = hydrometProcessor.get_hdyromet_data("pn", sourceTstep, sdiString, t1, t2);
                dataTable = dtOut[0];
                infoTable = dtOut[1];
            }
            dataTable = dataTable.Select("HDB_DATETIME >= #" + t1Input + "# AND HDB_DATETIME <= #" + t2Input + "#").CopyToDataTable();

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Generate output
            DataTable table     = new DataTable();
            var       outFile   = new List <string>();
            string    outFormat = Regex.Match(srchStr, @"&format=([A-Za-z0-9]+)").Groups[1].Value.ToString();

            if (outFormat == "json")
            {
                var jsonOut = buildOutputJson(infoTable, dataTable, t1, t2, sourceTstep, sourceTable, mridString);
                outFile.Add(JsonConvert.SerializeObject(jsonOut));
            }
            else
            {
                outFile = buildOutputText(infoTable, dataTable, srchStr, outFormat);
            }
            return(outFile);
        }