예제 #1
0
            /// <summary>
            /// Returns a VariablesDataSet, as defined by VariablesDataSet.xsd
            ///
            /// In SDSC code, this variable is loaded once, and is stored in an
            /// Application, or AppServer variable, and queries are run against the stored dataset.
            /// Other methods in this class are used to query the dataset.
            /// </summary>
            /// <param name="networkID"></param>
            /// <returns></returns>
            public static VariablesDataset GetVariableDataSet(int networkID)
            {
                VariablesDataset ds = new VariablesDataset();

                UnitsTableAdapter      unitTableAdapter       = new UnitsTableAdapter();
                VariablesTableAdapter  varsTableAdapter       = new VariablesTableAdapter();
                CategoriesTableAdapter categoriesTableAdapter = new CategoriesTableAdapter();

                unitTableAdapter.Connection.ConnectionString       = Config.ODDB();
                varsTableAdapter.Connection.ConnectionString       = Config.ODDB();
                categoriesTableAdapter.Connection.ConnectionString = Config.ODDB();

                try
                {
                    unitTableAdapter.Fill(ds.Units);
                    varsTableAdapter.Fill(ds.Variables);
                    categoriesTableAdapter.Fill(ds.Categories);
                }
                catch (Exception e)
                {
                    log.Fatal("Cannot retrieve units or variables from database" + e.Message);
                    //+ unitTableAdapter.Connection.DataSource
                    throw new WaterOneFlowServerException("Cannot retrieve units or variables from database", e);
                }

                return(ds);
            }
예제 #2
0
        static void PrintTable(VariablesTableAdapter dtAdapter, OD_1_1_1DataSet.VariablesDataTable dt)
        {
            dtAdapter.Fill(dt);

            // Print out the column names.
            for (int curCol = 0; curCol < dt.Columns.Count; curCol++)
            {
                Console.Write(dt.Columns[curCol].ColumnName + "\t");
            }
            Console.WriteLine("\n----------------------------------");

            // Print the DataTable.
            for (int curRow = 0; curRow < dt.Rows.Count; curRow++)
            {
                for (int curCol = 0; curCol < dt.Columns.Count; curCol++)
                {
                    Console.Write(dt.Rows[curRow][curCol].ToString() + "\t");
                }
                Console.WriteLine();
            }
        }
예제 #3
0
        public VariablesResponseType GetVariables(VariableParam[] variables)
        {
            UsgsDbDailyValues.VariablesDataTable vDs = new UsgsDbDailyValues.VariablesDataTable();

            UsgsDbDailyValuesTableAdapters.VariablesTableAdapter TableAdapter = new VariablesTableAdapter();

            List <VariableInfoType> vList = new List <VariableInfoType>();

            // if nothing. get it all
            if (variables == null || variables.Length == 0)
            {
                try
                {
                    TableAdapter.Fill(vDs);
                } catch
                {
                    log.Error("Cannot connect to USGS Database");
                    throw new WaterOneFlowServerException("Server Error: Cannot Connect to Database");
                }

                if (vDs.Rows.Count > 0)
                {
                    foreach (UsgsDbDailyValues.VariablesRow vRow
                             in vDs)
                    {
                        VariableInfoType vit = RowToVariable(vRow);

                        if (vit != null)
                        {
                            vList.Add(vit);
                        }
                    }
                }
            }
            else
            {
                foreach (VariableParam v in variables)
                {
                    UsgsDbDailyValues.VariablesRow[] vRows;
                    try
                    {
                        TableAdapter.FillByVariableCode(vDs, v.Code);

                        string where = VariableOptions2WhereClause(v); /* Use Caution, where clause not SQL inject safe. */
                        vRows        = (UsgsDbDailyValues.VariablesRow[])
                                       vDs.Select(where);
                    }
                    catch
                    {
                        log.Error("Cannot connect to USGS Database");
                        throw new WaterOneFlowServerException("Server Error: Cannot Connect to Database");
                    }
                    if (vRows.Length > 0)
                    {
                        foreach (UsgsDbDailyValues.VariablesRow vRow
                                 in vRows)
                        {
                            VariableInfoType vit = RowToVariable(vRow);

                            if (vit != null)
                            {
                                vList.Add(vit);
                            }
                        }
                    }
                }
            }

            //if (vDs.Rows.Count > 0)
            //{
            //    foreach (UsgsDbDailyValues.VariablesRow vRow
            //        in vDs)
            //    {


            //            VariableInfoType v = RowToVariable(vRow);

            //        if (v != null) vList.Add(v);

            //    }
            //}
            VariablesResponseType vRes = new VariablesResponseType();

            if (vList != null && vList.Count > 0)
            {
                // build response

                vRes.variables = vList.ToArray();
            }
            else
            {
                log.Info("User Error: No Variables Returned");
                throw new WaterOneFlowException("No Variables Returned. Submit with no values to get full list.");
            }
            return(vRes);
        }
예제 #4
0
            /// <summary>
            /// Returns a VariablesDataSet, as defined by VariablesDataSet.xsd
            /// 
            /// In SDSC code, this variable is loaded once, and is stored in an 
            /// Application, or AppServer variable, and queries are run against the stored dataset.
            /// Other methods in this class are used to query the dataset.
            /// </summary>
            /// <param name="networkID"></param>
            /// <returns></returns>
            public static VariablesDataset GetVariableDataSet(int networkID)
            {
                VariablesDataset ds = new VariablesDataset();

                UnitsTableAdapter unitTableAdapter = new UnitsTableAdapter();
                VariablesTableAdapter varsTableAdapter = new VariablesTableAdapter();
                CategoriesTableAdapter categoriesTableAdapter = new CategoriesTableAdapter();

                unitTableAdapter.Connection.ConnectionString = Config.ODDB();
                varsTableAdapter.Connection.ConnectionString = Config.ODDB();
                categoriesTableAdapter.Connection.ConnectionString = Config.ODDB();

                try
                {
                    unitTableAdapter.Fill(ds.Units);
                    varsTableAdapter.Fill(ds.Variables);
                    categoriesTableAdapter.Fill(ds.Categories);
                }
                catch (Exception e)
                {
                    log.Fatal("Cannot retrieve units or variables from database" + e.Message);
                        //+ unitTableAdapter.Connection.DataSource
                    throw new WaterOneFlowServerException("Cannot retrieve units or variables from database", e);
                }

                return ds;
            }