示例#1
0
 public GetVariablesOD()
 {
     //
     // TODO: Add constructor logic here
     //
     Variables = ODvariables.GetVariableDataSet();
 }
示例#2
0
 public GetValuesOD()
 {
     //
     // TODO: Add constructor logic here
     //
     variableDs = ODvariables.GetVariableDataSet();
     unitsDs = ODUnits.getUnitsDataset();
     oDconnectionString = ConfigurationManager.ConnectionStrings["ODDB"];
 }
示例#3
0
 /// <summary>
 /// Add catagories for each one of the variableID's
 /// </summary>
 /// <param name="ds"></param>
 /// <returns></returns>
 public static void GetCategories(VariablesDataset ds)
 {
     if (ds != null)
     {
         CategoriesTableAdapter categoriesTableAdapter = new CategoriesTableAdapter();
         ds.Categories.Clear();
         //foreach (VariablesRow vRow in ds.Variables.Rows)
         //{
         //    categoriesTableAdapter.FillByVariableID(ds.Categories, vRow.VariableID);
         //}
     }
 }
示例#4
0
        public static void addCategoricalInformation( List<ValueSingleVariable> variables, int variableID, VariablesDataset vds)
        {
            foreach (ValueSingleVariable variable in variables)
            {
                string selectquery = String.Format("VariableID = {0} AND DataValue = {1}", variableID.ToString(),
                                                   variable.Value);
                DataRow[] rows =  vds.Categories.Select(selectquery);
                if (rows.Length >0 )
                {
                    variable.codedVocabulary = true;
                    variable.codedVocabularySpecified = true;
                    variable.codedVocabularyTerm = (string)rows[0]["CategoryDescription"];
                }

            }
        }
示例#5
0
        public static seriesCatalogType[] dataSet2SeriesCatalog(
            seriesCatalogDataSet ds,
            VariablesDataset vds)
        {
            /* logic
             *   for each sourceID that is associated with the site
             *
             *
             */

            List<seriesCatalogType> catalogs = new List<seriesCatalogType>();

            seriesCatalogType catalog = createSeriesCatalog(ds, vds);
            if (catalog != null)
            {
                catalogs.Add(catalog);
            }

            return catalogs.ToArray();
        }
示例#6
0
        public static units getUnitsElement(int unitsID, VariablesDataset ds)
        {
            DataRow[] dr = ds.Tables["units"].Select("unitsID = " + unitsID);

            if (dr.Length > 0)
            {
                VariablesDataset.UnitsRow row = (VariablesDataset.UnitsRow) dr[0];
                string uID = row.UnitsID.ToString();
                string unitType = String.IsNullOrEmpty(row.UnitsType) ? null : row.UnitsType;
                string unitAbbrev = String.IsNullOrEmpty(row.UnitsAbbreviation) ? null : row.UnitsAbbreviation;
                string unitName = String.IsNullOrEmpty(row.UnitsName) ? null : row.UnitsName;

                units u = CuahsiBuilder.CreateUnitsElement(null, uID, unitAbbrev, unitName);
                CuahsiBuilder.SetEnumFromText(u, row, "unitsType", typeof (UnitsTypeEnum));
                return u;
            }
            else
            {
                return null;
            }
        }
示例#7
0
 public GetSiteInfoOD()
 {
     variablesDs = ODvariables.GetVariableDataSet();
 }
示例#8
0
        /// <summary>
        /// Builds a VariableInfoType from a dataset row 
        /// the dataSet is stored in the NWISService variableDataSet.
        /// Find the rwo you want with the command:
        /// 
        /// and convert. 
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public static VariableInfoType rowToVariableInfoType(VariablesDataset.VariablesRow row, VariablesDataset ds)
        {
            units aUnit = null;

            aUnit = getUnitsElement(row.VariableUnitsID, ds);

            String vCode = !String.IsNullOrEmpty(row.VariableCode) ? row.VariableCode : null;

            int vid = row.VariableID;
            // appSetting['vocabulary']

            String vocab = System.Configuration.ConfigurationManager.AppSettings["vocabulary"];
            String varName = !String.IsNullOrEmpty(row.VariableName) ? row.VariableName : null;

            VariableInfoType vt = CuahsiBuilder.CreateVariableInfoType(
                vid.ToString(),
                vocab,
                vCode,
                varName,
                null, //variable description
                aUnit
                );

            // add time support
            vt.timeSupport = new VariableInfoTypeTimeSupport();
            if (row.IsRegular)
            {
                vt.timeSupport.isRegular = true;
                vt.timeSupport.isRegularSpecified = true;
                vt.timeSupport.timeInterval = Convert.ToInt32(row.TimeSupport);
                vt.timeSupport.timeIntervalSpecified = true;
                // this is different that the other "units", so populate by code
                units tUnit = getUnitsElement(row.TimeUnitsID, ds);
                if (tUnit != null)
                {
                    vt.timeSupport.unit = new UnitsType();
                    vt.timeSupport.unit.UnitID = int.Parse(tUnit.unitsCode);
                    vt.timeSupport.unit.UnitIDSpecified = true;
                    vt.timeSupport.unit.UnitDescription = tUnit.Value;
                    vt.timeSupport.unit.UnitAbbreviation = tUnit.unitsAbbreviation;
                    if (tUnit.unitsTypeSpecified)
                    {
                        // if it's specified in the units, then it's a valid enum
                        vt.timeSupport.unit.UnitType = tUnit.unitsType;
                        vt.timeSupport.unit.UnitTypeSpecified = true;

                    }
                }
            }
            else
            {
                vt.timeSupport.isRegular = false;
                vt.timeSupport.isRegularSpecified = true;
            }
            CuahsiBuilder.SetEnumFromText(vt, row, "valueType", typeof (valueTypeEnum));
            CuahsiBuilder.SetEnumFromText(vt, row, "sampleMedium", typeof (SampleMediumEnum));
            CuahsiBuilder.SetEnumFromText(vt, row, "dataType", typeof (dataTypeEnum));
            CuahsiBuilder.SetEnumFromText(vt, row, "generalCategory", typeof (generalCategoryEnum));
            // if (!String.IsNullOrEmpty(row.NoDataValue)) {
            vt.NoDataValue = row.NoDataValue.ToString();
            // }
            return vt;
        }
示例#9
0
        public static VariableInfoType[] GetVariablesByID(int[] variableIDs, VariablesDataset ds)
        {
            List<VariableInfoType> vars = new List<VariableInfoType>();

            if (variableIDs.Length == 0)
            {
                foreach (VariablesDataset.VariablesRow row in ds.Variables.Rows)
                {
                    VariableInfoType result = rowToVariableInfoType(row,
                                                                    ds
                        );
                    vars.Add(result);
                }
                return vars.ToArray();
            }
            else
            {
                StringBuilder sBuilder = new StringBuilder("(");
                int i = 0;
                foreach (int s in variableIDs)
                {
                    if (i > 0) sBuilder.Append(",");
                    sBuilder.Append("'");
                    sBuilder.Append(s.ToString());
                    sBuilder.Append("'");
                    i++;
                }
                sBuilder.Append(")");

                //DataRow dr = ds.Tables["variables"].Select("variableCode = " + vCode);
                DataRow[] dr = ds.Tables["variables"].Select("variableID IN " + sBuilder.ToString());

                if (dr.Length > 0)
                {
                    foreach (DataRow row in dr)
                    {
                        VariableInfoType result = rowToVariableInfoType((
                                                                        VariablesDataset.VariablesRow) row,
                                                                        ds
                            );
                        vars.Add(result);
                    }
                    return vars.ToArray();
                }
                else
                {
                    return null;
                }
            }
        }
示例#10
0
        public static VariableInfoType[] getVariables(VariableParam[] vParams, VariablesDataset ds)
        {
            List<VariableInfoType> vit = new List<VariableInfoType>();

            // if there are no variableParameters, return all varaibles
            if (vParams == null || vParams.Length == 0)
            {
                foreach (VariablesDataset.VariablesRow row in ds.Variables.Rows)
                {
                    VariableInfoType result = rowToVariableInfoType(row,
                                                                    ds
                        );
                    vit.Add(result);
                }
                return vit.ToArray();
            }
            else
            {
                foreach (VariableParam vParam in vParams)
                {
                    VariableInfoType[] vars = getVariable(vParam, ds);
                    if (vars != null) vit.AddRange(vars);
                }
                return vit.ToArray();
            }
        }
示例#11
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();
            unitTableAdapter.Connection.ConnectionString = Config.ODDB();
            varsTableAdapter.Connection.ConnectionString = Config.ODDB();

            try
            {
                unitTableAdapter.Fill(ds.Units);
                varsTableAdapter.Fill(ds.Variables);
            }
            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);
            }

            GetCategories(ds);
            return ds;
        }
示例#12
0
        /// <summary>
        /// Returns the variable associated with a variableID
        /// 
        /// Note: this will only return one value... and only one value.
        /// </summary>
        /// <param name="variableID"></param>
        /// <param name="ds"></param>
        /// <returns></returns>
        public static VariableInfoType GetVariableByID(Nullable<int> variableID, VariablesDataset ds)
        {
            VariableInfoType[] vit;
            if (variableID.HasValue)
            {
                vit = GetVariablesByID(new int[] {variableID.Value}, ds);
            }
            else
            {
                vit = GetVariablesByID(new int[] {}, ds);
            }

            if (vit == null)
            {
                return null;
            }
            else
            {
                // there should only be one, and only one value with a variable ID.
                if (vit.Length == 1)
                {
                    return vit[0];
                }
                else
                {
                    return vit[0];
                    // TODO throw error
                }
            }
        }
示例#13
0
        public static VariableInfoType[] getVariable(VariableParam vParam, VariablesDataset ds)
        {
            List<VariableInfoType> vars = new List<VariableInfoType>();
            if (vParam != null)
            {
                /* need to use a data view, so the we can set a filter that does not effect the whole dataset
                  DataView has a ToTable method that is uses to create a new DS, and fill
                 * a new VariablesDataset. Typed Datasets are useful ;)
                 */

                DataView view = new DataView();
                view.Table = ds.Tables["Variables"];

                if (vParam.IsId)
                {
                    view.RowFilter = "VariableID = " + vParam.Code + " ";
                }
                else
                {
                    view.RowFilter = "VariableCode = '" + vParam.Code + "' ";
                    // list of possible options. Allowing any will break the query (aka QualityControlLevelID, etc)
                    String[] options = {"samplemedium", "datatype", "valuetype"};

                    foreach (string opt in options)
                    {
                        if (vParam.options.ContainsKey(opt))
                        {
                            if (!String.IsNullOrEmpty(vParam.options[opt]))
                            {
                                String rowFilter = view.RowFilter + " AND "
                                                   + opt + "='" + vParam.options[opt] + "'";
                                view.RowFilter = rowFilter;
                            }
                        }
                    }
                }

                DataTable v = view.ToTable();
                if (v.Rows.Count > 0)
                {
                    VariablesDataset vtemp = new VariablesDataset();

                    vtemp.Variables.Merge(v);

                    foreach (VariablesDataset.VariablesRow row in vtemp.Variables.Rows)
                    {
                        VariableInfoType result = rowToVariableInfoType(row,
                                                                        ds
                            );
                        vars.Add(result);
                    }

                    return vars.ToArray();
                }
                else
                {
                    return null;
                }
            }
            else
            {
                return null;
            }
        }
示例#14
0
        public static seriesCatalogTypeSeries row2SeriesCatalogElement(
            seriesCatalogDataSet.SeriesCatalogRow row,
            seriesCatalogDataSet ds, VariablesDataset vds)
        {
            int variableID = row.VariableID;
            VariableInfoType variable = ODvariables.GetVariableByID(variableID, vds);
            Nullable<W3CDateTime> beginDateTime = null;
            if (!row.IsBeginDateTimeNull()) beginDateTime = new W3CDateTime(row.BeginDateTime);

            Nullable<W3CDateTime> endDateTime = null;
            if (!row.IsEndDateTimeNull()) endDateTime = new W3CDateTime(row.EndDateTime);

            Nullable<int> valueCount = null;
            if (!row.IsValueCountNull()) valueCount = row.ValueCount;

            int? QualityControlLevelid = null;
            if (!row.IsQualityControlLevelIDNull()) QualityControlLevelid = row.QualityControlLevelID;

            int? MethodID = null;
            if (!row.IsMethodIDNull()) MethodID = row.MethodID;

            int? SourceID = null;
            if (!row.IsSourceIDNull()) SourceID = row.SourceID;

            Nullable<Boolean> valueCountIsEstimated = false;

            seriesCatalogTypeSeries record = CuahsiBuilder.CreateSeriesRecord(
                variable,
                variable.sampleMedium.ToString(),
                beginDateTime,
                endDateTime,
                valueCount,
                valueCountIsEstimated,
                null,
                null,
                null,
                false, // real time
                null, // string if real time
                null,
                QualityControlLevelid,
                row.MethodDescription, MethodID,
                row.Organization, row.SourceDescription,
                SourceID,
                row.Citation);

            return record;
        }
示例#15
0
        private static seriesCatalogType createSeriesCatalog(
            seriesCatalogDataSet ds,
            VariablesDataset vds)
        {
            if (ds.SeriesCatalog.Count > 0)
            {
                Boolean useOD;

                String siteServiceURL;
                String siteServiceName;
                try
                {
                    useOD = Boolean.Parse(ConfigurationManager.AppSettings["UseODForValues"]);

                    if (!useOD)
                    {
                        siteServiceURL = ConfigurationManager.AppSettings["externalGetValuesService"];
                        siteServiceName = ConfigurationManager.AppSettings["externalGetValuesName"];
                    }
                    else
                    {
                        siteServiceURL = "http://localhost/";
                        siteServiceName = "OD Web Services";
                    }
                }
                catch
                {
                    useOD = true; // should be caught earlier

                    siteServiceURL = "http://locahost/";
                    siteServiceName = "Fix UseODForValues, externalGetValuesService, externalGetValuesName";

                }
                seriesCatalogType catalog = CuahsiBuilder.CreateSeriesCatalog(
                    ds.SeriesCatalog.Count,
                    siteServiceName, // menu name (aka OD name
                    siteServiceURL// web service location
                 );
                List<seriesCatalogTypeSeries> seriesRecords = new List<seriesCatalogTypeSeries>();
                foreach (seriesCatalogDataSet.SeriesCatalogRow row in ds.SeriesCatalog.Rows)
                {
                    seriesCatalogTypeSeries aRecord = row2SeriesCatalogElement(
                        row, ds, vds);

                    seriesRecords.Add(aRecord);

                }
                catalog.series = seriesRecords.ToArray();
                return catalog;
            }
            else
            {
                seriesCatalogType catalog = CuahsiBuilder.CreateSeriesCatalog(0,
                                                                null, // menu name (aka OD name
                                                                String.Empty // web service location
                    );
                return catalog;
            }
        }