Пример #1
0
        public PspTimeValTuple GetPSPMeasVal(PspMeasurement pspMeasurement, int fromTime)
        {
            TableRowsApiResultModel fetchedData = GetLabelData(pspMeasurement, fromTime, fromTime);
            List <List <object> >   rows        = fetchedData.TableRows;
            List <string>           colNames    = fetchedData.TableColNames;
            int timeInd = colNames.IndexOf(pspMeasurement.PspTimeCol);
            int valInd  = colNames.IndexOf(pspMeasurement.PspValCol);

            if (timeInd == -1 || valInd == -1)
            {
                // desired result was not found
                return(null);
            }
            if (rows.Count == 0)
            {
                // desired result was not found
                return(null);
            }
            // todo check val types also
            int             timeInt = Convert.ToInt32((decimal)rows.ElementAt(0).ElementAt(timeInd));
            decimal?        val     = (decimal)rows.ElementAt(0).ElementAt(valInd);
            PspTimeValTuple result  = new PspTimeValTuple {
                TimeInt = timeInt, Val = val
            };

            return(result);
        }
Пример #2
0
        public TableRowsApiResultModel GetDbTableRows(string sqlStr)
        {
            // initiate the result
            TableRowsApiResultModel rows = new TableRowsApiResultModel();

            // create and open the connection
            OracleConnection conn = new OracleConnection(ConnStr); // C#

            conn.Open();
            try
            {
                // create the command for querying
                OracleCommand cmd = new OracleCommand
                {
                    Connection  = conn,
                    CommandText = sqlStr,
                    CommandType = CommandType.Text
                };

                // execute command and read into an oracle data reader object
                OracleDataReader dr = cmd.ExecuteReader();

                // populate the column names
                for (int i = 0; i < dr.FieldCount; i++)
                {
                    string colName = dr.GetName(i);
                    rows.TableColNames.Add(colName);
                    string colType = dr.GetFieldType(i).Name;
                    rows.TableColTypes.Add(colType);
                }

                // populate the rows of the query table
                while (dr.Read())
                {
                    object[] objs = new object[dr.FieldCount];
                    dr.GetValues(objs);
                    rows.TableRows.Add(new List <object>(objs));
                    //Console.WriteLine(dr.GetInt32(dr.GetOrdinal("ID")));
                    //Console.WriteLine(dr.GetString(dr.GetOrdinal("LINE_NAME")));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            //close the connection
            conn.Close();

            // free the resources
            conn.Dispose();

            // return the result
            return(rows);
        }
Пример #3
0
        public List <PspTimeValTuple> GetPSPMeasVals(PspMeasurement pspMeasurement, int fromTime, int toTime)
        {
            TableRowsApiResultModel fetchedData = GetLabelData(pspMeasurement, fromTime, toTime);
            List <List <object> >   rows        = fetchedData.TableRows;
            List <string>           colNames    = fetchedData.TableColNames;
            int timeInd = colNames.IndexOf(pspMeasurement.PspTimeCol);
            int valInd  = colNames.IndexOf(pspMeasurement.PspValCol);
            List <PspTimeValTuple> results = new List <PspTimeValTuple>();

            if (timeInd == -1 || valInd == -1)
            {
                // desired result was not found
                return(results);
            }
            for (int rowIter = 0; rowIter < rows.Count; rowIter++)
            {
                // todo check val types also and try to accommodate other types also
                int     timeInt = 0;
                decimal?val;
                try
                {
                    timeInt = Convert.ToInt32((decimal)rows.ElementAt(rowIter).ElementAt(timeInd));
                }
                catch (Exception e)
                {
                    // didnot find valid timestamp, so we will not record the value
                    continue;
                }
                try
                {
                    val = (decimal)rows.ElementAt(rowIter).ElementAt(valInd);
                }
                catch (Exception e)
                {
                    val = null;
                }
                results.Add(new PspTimeValTuple {
                    TimeInt = timeInt, Val = val
                });
            }
            return(results);
        }